@personaai/react 0.14.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 +286 -182
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -1
- package/dist/index.d.ts +23 -1
- package/dist/index.js +271 -168
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1889,8 +1889,110 @@ function useThreads(autoFetch = true) {
|
|
|
1889
1889
|
};
|
|
1890
1890
|
}
|
|
1891
1891
|
|
|
1892
|
+
// src/hooks/useWorkspaceFiles.ts
|
|
1893
|
+
import { useCallback as useCallback5, useEffect as useEffect5, useState as useState5 } from "react";
|
|
1894
|
+
function useWorkspaceFiles(threadId, autoFetch = true) {
|
|
1895
|
+
const { fetchWithAuth } = usePersonaContext();
|
|
1896
|
+
const [files, setFiles] = useState5({});
|
|
1897
|
+
const [isLoading, setIsLoading] = useState5(false);
|
|
1898
|
+
const [isSaving, setIsSaving] = useState5(false);
|
|
1899
|
+
const [error, setError] = useState5(null);
|
|
1900
|
+
const fetchFiles = useCallback5(async () => {
|
|
1901
|
+
if (!threadId) return {};
|
|
1902
|
+
setIsLoading(true);
|
|
1903
|
+
setError(null);
|
|
1904
|
+
try {
|
|
1905
|
+
const res = await fetchWithAuth(`/threads/${threadId}/files`);
|
|
1906
|
+
if (!res.ok) throw new Error(`Failed to list workspace files: ${res.statusText}`);
|
|
1907
|
+
const data = await res.json();
|
|
1908
|
+
const normalized = normalizeWorkspaceFiles(data?.data ?? data ?? {});
|
|
1909
|
+
setFiles(normalized);
|
|
1910
|
+
return normalized;
|
|
1911
|
+
} catch (err) {
|
|
1912
|
+
const errorObj = err instanceof Error ? err : new Error(String(err));
|
|
1913
|
+
setError(errorObj);
|
|
1914
|
+
return {};
|
|
1915
|
+
} finally {
|
|
1916
|
+
setIsLoading(false);
|
|
1917
|
+
}
|
|
1918
|
+
}, [fetchWithAuth, threadId]);
|
|
1919
|
+
const getFile = useCallback5(
|
|
1920
|
+
async (path) => {
|
|
1921
|
+
if (!threadId) throw new Error("useWorkspaceFiles: no threadId set");
|
|
1922
|
+
const res = await fetchWithAuth(
|
|
1923
|
+
`/threads/${threadId}/file?path=${encodeURIComponent(path)}`
|
|
1924
|
+
);
|
|
1925
|
+
if (!res.ok) throw new Error(`Failed to read workspace file: ${res.statusText}`);
|
|
1926
|
+
const data = await res.json();
|
|
1927
|
+
const raw = data?.data ?? data;
|
|
1928
|
+
return normalizeWorkspaceFiles({ [path]: raw })[path];
|
|
1929
|
+
},
|
|
1930
|
+
[fetchWithAuth, threadId]
|
|
1931
|
+
);
|
|
1932
|
+
const writeFile = useCallback5(
|
|
1933
|
+
async (path, content) => {
|
|
1934
|
+
if (!threadId) throw new Error("useWorkspaceFiles: no threadId set");
|
|
1935
|
+
setIsSaving(true);
|
|
1936
|
+
setError(null);
|
|
1937
|
+
try {
|
|
1938
|
+
const res = await fetchWithAuth(`/threads/${threadId}/file`, {
|
|
1939
|
+
method: "PUT",
|
|
1940
|
+
headers: { "Content-Type": "application/json" },
|
|
1941
|
+
body: JSON.stringify({ path, content })
|
|
1942
|
+
});
|
|
1943
|
+
if (!res.ok) throw new Error(`Failed to write workspace file: ${res.statusText}`);
|
|
1944
|
+
const data = await res.json();
|
|
1945
|
+
const raw = data?.data ?? data;
|
|
1946
|
+
const file = normalizeWorkspaceFiles({ [path]: raw })[path];
|
|
1947
|
+
setFiles((prev) => ({ ...prev, [path]: file }));
|
|
1948
|
+
return file;
|
|
1949
|
+
} catch (err) {
|
|
1950
|
+
const errorObj = err instanceof Error ? err : new Error(String(err));
|
|
1951
|
+
setError(errorObj);
|
|
1952
|
+
throw errorObj;
|
|
1953
|
+
} finally {
|
|
1954
|
+
setIsSaving(false);
|
|
1955
|
+
}
|
|
1956
|
+
},
|
|
1957
|
+
[fetchWithAuth, threadId]
|
|
1958
|
+
);
|
|
1959
|
+
const deleteFile = useCallback5(
|
|
1960
|
+
async (path) => {
|
|
1961
|
+
if (!threadId) throw new Error("useWorkspaceFiles: no threadId set");
|
|
1962
|
+
const res = await fetchWithAuth(
|
|
1963
|
+
`/threads/${threadId}/file?path=${encodeURIComponent(path)}`,
|
|
1964
|
+
{ method: "DELETE" }
|
|
1965
|
+
);
|
|
1966
|
+
if (!res.ok) throw new Error(`Failed to delete workspace file: ${res.statusText}`);
|
|
1967
|
+
setFiles((prev) => {
|
|
1968
|
+
const next = { ...prev };
|
|
1969
|
+
delete next[path];
|
|
1970
|
+
return next;
|
|
1971
|
+
});
|
|
1972
|
+
},
|
|
1973
|
+
[fetchWithAuth, threadId]
|
|
1974
|
+
);
|
|
1975
|
+
useEffect5(() => {
|
|
1976
|
+
if (autoFetch && threadId) {
|
|
1977
|
+
void fetchFiles();
|
|
1978
|
+
} else if (!threadId) {
|
|
1979
|
+
setFiles({});
|
|
1980
|
+
}
|
|
1981
|
+
}, [autoFetch, threadId, fetchFiles]);
|
|
1982
|
+
return {
|
|
1983
|
+
files,
|
|
1984
|
+
isLoading,
|
|
1985
|
+
isSaving,
|
|
1986
|
+
error,
|
|
1987
|
+
refetch: fetchFiles,
|
|
1988
|
+
getFile,
|
|
1989
|
+
writeFile,
|
|
1990
|
+
deleteFile
|
|
1991
|
+
};
|
|
1992
|
+
}
|
|
1993
|
+
|
|
1892
1994
|
// src/hooks/useVoice.ts
|
|
1893
|
-
import { useCallback as
|
|
1995
|
+
import { useCallback as useCallback6, useEffect as useEffect6, useMemo as useMemo4, useRef as useRef3, useState as useState6 } from "react";
|
|
1894
1996
|
|
|
1895
1997
|
// src/hooks/voiceWorklets.ts
|
|
1896
1998
|
var RECORDER_WORKLET_SOURCE = `
|
|
@@ -1998,17 +2100,17 @@ function useVoice(options = {}) {
|
|
|
1998
2100
|
const threadId = options.threadId;
|
|
1999
2101
|
const contextOverride = options.contextOverride;
|
|
2000
2102
|
const context = options.context;
|
|
2001
|
-
const [state, setState] =
|
|
2002
|
-
const [isMuted, setIsMuted] =
|
|
2003
|
-
const [transcript, setTranscript] =
|
|
2103
|
+
const [state, setState] = useState6("idle");
|
|
2104
|
+
const [isMuted, setIsMuted] = useState6(false);
|
|
2105
|
+
const [transcript, setTranscript] = useState6(
|
|
2004
2106
|
[]
|
|
2005
2107
|
);
|
|
2006
|
-
const [partial, setPartial] =
|
|
2108
|
+
const [partial, setPartial] = useState6(
|
|
2007
2109
|
null
|
|
2008
2110
|
);
|
|
2009
|
-
const [toolCalls, setToolCalls] =
|
|
2010
|
-
const [error, setError] =
|
|
2011
|
-
const [endReason, setEndReason] =
|
|
2111
|
+
const [toolCalls, setToolCalls] = useState6([]);
|
|
2112
|
+
const [error, setError] = useState6(null);
|
|
2113
|
+
const [endReason, setEndReason] = useState6(
|
|
2012
2114
|
null
|
|
2013
2115
|
);
|
|
2014
2116
|
const wsRef = useRef3(null);
|
|
@@ -2022,13 +2124,13 @@ function useVoice(options = {}) {
|
|
|
2022
2124
|
const lastFinalTurnRef = useRef3(
|
|
2023
2125
|
null
|
|
2024
2126
|
);
|
|
2025
|
-
|
|
2127
|
+
useEffect6(() => {
|
|
2026
2128
|
mountedRef.current = true;
|
|
2027
2129
|
return () => {
|
|
2028
2130
|
mountedRef.current = false;
|
|
2029
2131
|
};
|
|
2030
2132
|
}, []);
|
|
2031
|
-
const teardownAudio =
|
|
2133
|
+
const teardownAudio = useCallback6(() => {
|
|
2032
2134
|
try {
|
|
2033
2135
|
streamRef.current?.getTracks().forEach((track) => track.stop());
|
|
2034
2136
|
} catch {
|
|
@@ -2055,7 +2157,7 @@ function useVoice(options = {}) {
|
|
|
2055
2157
|
}
|
|
2056
2158
|
outputCtxRef.current = null;
|
|
2057
2159
|
}, []);
|
|
2058
|
-
const stop =
|
|
2160
|
+
const stop = useCallback6(() => {
|
|
2059
2161
|
voiceLogger.debug("stop() called");
|
|
2060
2162
|
try {
|
|
2061
2163
|
wsRef.current?.close(1e3, "client_stop");
|
|
@@ -2065,8 +2167,8 @@ function useVoice(options = {}) {
|
|
|
2065
2167
|
teardownAudio();
|
|
2066
2168
|
if (mountedRef.current) setState("idle");
|
|
2067
2169
|
}, [teardownAudio, voiceLogger]);
|
|
2068
|
-
|
|
2069
|
-
const startCapture =
|
|
2170
|
+
useEffect6(() => stop, [stop]);
|
|
2171
|
+
const startCapture = useCallback6(async (inputSampleRate) => {
|
|
2070
2172
|
const stream = await navigator.mediaDevices.getUserMedia({
|
|
2071
2173
|
audio: {
|
|
2072
2174
|
echoCancellation: true,
|
|
@@ -2092,7 +2194,7 @@ function useVoice(options = {}) {
|
|
|
2092
2194
|
recorderNodeRef.current = recorderNode;
|
|
2093
2195
|
source.connect(recorderNode);
|
|
2094
2196
|
}, []);
|
|
2095
|
-
const setupPlayback =
|
|
2197
|
+
const setupPlayback = useCallback6(async (outputSampleRate) => {
|
|
2096
2198
|
const outputCtx = new AudioContext({ sampleRate: outputSampleRate });
|
|
2097
2199
|
outputCtxRef.current = outputCtx;
|
|
2098
2200
|
await outputCtx.audioWorklet.addModule(playerWorkletUrl());
|
|
@@ -2100,7 +2202,7 @@ function useVoice(options = {}) {
|
|
|
2100
2202
|
playerNode.connect(outputCtx.destination);
|
|
2101
2203
|
playerNodeRef.current = playerNode;
|
|
2102
2204
|
}, []);
|
|
2103
|
-
const upsertToolCall =
|
|
2205
|
+
const upsertToolCall = useCallback6(
|
|
2104
2206
|
(id, patch) => {
|
|
2105
2207
|
setToolCalls((prev) => {
|
|
2106
2208
|
const idx = prev.findIndex((t) => t.id === id);
|
|
@@ -2112,7 +2214,7 @@ function useVoice(options = {}) {
|
|
|
2112
2214
|
},
|
|
2113
2215
|
[]
|
|
2114
2216
|
);
|
|
2115
|
-
const handleTranscript =
|
|
2217
|
+
const handleTranscript = useCallback6((value) => {
|
|
2116
2218
|
const { speaker, text, isFinal, turnSeq } = value;
|
|
2117
2219
|
if (!isFinal) {
|
|
2118
2220
|
setPartial({ id: "partial", speaker, text });
|
|
@@ -2135,7 +2237,7 @@ function useVoice(options = {}) {
|
|
|
2135
2237
|
});
|
|
2136
2238
|
lastFinalTurnRef.current = { speaker, turnSeq };
|
|
2137
2239
|
}, []);
|
|
2138
|
-
const handleCustomEvent =
|
|
2240
|
+
const handleCustomEvent = useCallback6(
|
|
2139
2241
|
(name, value) => {
|
|
2140
2242
|
switch (name) {
|
|
2141
2243
|
case "voice_session_ready":
|
|
@@ -2193,7 +2295,7 @@ function useVoice(options = {}) {
|
|
|
2193
2295
|
},
|
|
2194
2296
|
[handleTranscript, setupPlayback, startCapture, teardownAudio, voiceLogger]
|
|
2195
2297
|
);
|
|
2196
|
-
const handleMessage =
|
|
2298
|
+
const handleMessage = useCallback6(
|
|
2197
2299
|
(event) => {
|
|
2198
2300
|
if (typeof event.data !== "string") {
|
|
2199
2301
|
const buf = event.data;
|
|
@@ -2251,7 +2353,7 @@ function useVoice(options = {}) {
|
|
|
2251
2353
|
},
|
|
2252
2354
|
[handleCustomEvent, upsertToolCall, voiceLogger]
|
|
2253
2355
|
);
|
|
2254
|
-
const start =
|
|
2356
|
+
const start = useCallback6(async () => {
|
|
2255
2357
|
if (!agentId) {
|
|
2256
2358
|
const err = new Error(
|
|
2257
2359
|
"useVoice: no agentId provided and no defaultAgentId set on PersonaProvider"
|
|
@@ -2318,17 +2420,17 @@ function useVoice(options = {}) {
|
|
|
2318
2420
|
teardownAudio();
|
|
2319
2421
|
}
|
|
2320
2422
|
}, [agentId, threadId, contextOverride, context, fetchWithAuth, handleMessage, teardownAudio, voiceLogger]);
|
|
2321
|
-
const mute =
|
|
2423
|
+
const mute = useCallback6((muted) => {
|
|
2322
2424
|
setIsMuted(muted);
|
|
2323
2425
|
streamRef.current?.getAudioTracks().forEach((track) => {
|
|
2324
2426
|
track.enabled = !muted;
|
|
2325
2427
|
});
|
|
2326
2428
|
}, []);
|
|
2327
|
-
const sendText =
|
|
2429
|
+
const sendText = useCallback6((text) => {
|
|
2328
2430
|
if (!text?.trim() || wsRef.current?.readyState !== WebSocket.OPEN) return;
|
|
2329
2431
|
wsRef.current.send(JSON.stringify({ type: "voice.text", text }));
|
|
2330
2432
|
}, []);
|
|
2331
|
-
const updateContext =
|
|
2433
|
+
const updateContext = useCallback6((newContext) => {
|
|
2332
2434
|
if (wsRef.current?.readyState !== WebSocket.OPEN) return;
|
|
2333
2435
|
wsRef.current.send(JSON.stringify({ type: "voice.context", context: newContext }));
|
|
2334
2436
|
}, []);
|
|
@@ -2349,14 +2451,14 @@ function useVoice(options = {}) {
|
|
|
2349
2451
|
}
|
|
2350
2452
|
|
|
2351
2453
|
// src/hooks/useFiles.ts
|
|
2352
|
-
import { useCallback as
|
|
2454
|
+
import { useCallback as useCallback7, useEffect as useEffect7, useState as useState7 } from "react";
|
|
2353
2455
|
function useFiles(autoFetch = true) {
|
|
2354
2456
|
const { fetchWithAuth } = usePersonaContext();
|
|
2355
|
-
const [files, setFiles] =
|
|
2356
|
-
const [isLoading, setIsLoading] =
|
|
2357
|
-
const [isUploading, setIsUploading] =
|
|
2358
|
-
const [error, setError] =
|
|
2359
|
-
const fetchFiles =
|
|
2457
|
+
const [files, setFiles] = useState7([]);
|
|
2458
|
+
const [isLoading, setIsLoading] = useState7(false);
|
|
2459
|
+
const [isUploading, setIsUploading] = useState7(false);
|
|
2460
|
+
const [error, setError] = useState7(null);
|
|
2461
|
+
const fetchFiles = useCallback7(async () => {
|
|
2360
2462
|
setIsLoading(true);
|
|
2361
2463
|
setError(null);
|
|
2362
2464
|
try {
|
|
@@ -2374,7 +2476,7 @@ function useFiles(autoFetch = true) {
|
|
|
2374
2476
|
setIsLoading(false);
|
|
2375
2477
|
}
|
|
2376
2478
|
}, [fetchWithAuth]);
|
|
2377
|
-
const uploadFile =
|
|
2479
|
+
const uploadFile = useCallback7(
|
|
2378
2480
|
async (fileOrFormData) => {
|
|
2379
2481
|
setIsUploading(true);
|
|
2380
2482
|
setError(null);
|
|
@@ -2407,7 +2509,7 @@ function useFiles(autoFetch = true) {
|
|
|
2407
2509
|
},
|
|
2408
2510
|
[fetchWithAuth, fetchFiles]
|
|
2409
2511
|
);
|
|
2410
|
-
const deleteFile =
|
|
2512
|
+
const deleteFile = useCallback7(
|
|
2411
2513
|
async (fileId) => {
|
|
2412
2514
|
const res = await fetchWithAuth(`/files/${fileId}`, { method: "DELETE" });
|
|
2413
2515
|
if (!res.ok) throw new Error(`Failed to delete file: ${res.statusText}`);
|
|
@@ -2415,7 +2517,7 @@ function useFiles(autoFetch = true) {
|
|
|
2415
2517
|
},
|
|
2416
2518
|
[fetchWithAuth]
|
|
2417
2519
|
);
|
|
2418
|
-
const bulkDeleteFiles =
|
|
2520
|
+
const bulkDeleteFiles = useCallback7(
|
|
2419
2521
|
async (fileIds) => {
|
|
2420
2522
|
const res = await fetchWithAuth("/files/bulk-delete", {
|
|
2421
2523
|
method: "POST",
|
|
@@ -2430,10 +2532,10 @@ function useFiles(autoFetch = true) {
|
|
|
2430
2532
|
},
|
|
2431
2533
|
[fetchWithAuth]
|
|
2432
2534
|
);
|
|
2433
|
-
const getDownloadUrl =
|
|
2535
|
+
const getDownloadUrl = useCallback7((fileId) => {
|
|
2434
2536
|
return `/files/${fileId}`;
|
|
2435
2537
|
}, []);
|
|
2436
|
-
|
|
2538
|
+
useEffect7(() => {
|
|
2437
2539
|
if (autoFetch) {
|
|
2438
2540
|
void fetchFiles();
|
|
2439
2541
|
}
|
|
@@ -2452,21 +2554,21 @@ function useFiles(autoFetch = true) {
|
|
|
2452
2554
|
}
|
|
2453
2555
|
|
|
2454
2556
|
// src/hooks/useAgents.ts
|
|
2455
|
-
import { useCallback as
|
|
2557
|
+
import { useCallback as useCallback8, useEffect as useEffect8, useState as useState8 } from "react";
|
|
2456
2558
|
function useAgents(options = true) {
|
|
2457
2559
|
const opts = typeof options === "boolean" ? { autoFetch: options } : options;
|
|
2458
2560
|
const { autoFetch = true, page, limit, search, category, scope } = opts;
|
|
2459
2561
|
const { fetchWithAuth } = usePersonaContext();
|
|
2460
|
-
const [agents, setAgents] =
|
|
2461
|
-
const [pagination, setPagination] =
|
|
2562
|
+
const [agents, setAgents] = useState8([]);
|
|
2563
|
+
const [pagination, setPagination] = useState8({
|
|
2462
2564
|
total: 0,
|
|
2463
2565
|
page: page ?? 1,
|
|
2464
2566
|
limit: limit ?? 20,
|
|
2465
2567
|
pages: 0
|
|
2466
2568
|
});
|
|
2467
|
-
const [isLoading, setIsLoading] =
|
|
2468
|
-
const [error, setError] =
|
|
2469
|
-
const fetchAgents =
|
|
2569
|
+
const [isLoading, setIsLoading] = useState8(false);
|
|
2570
|
+
const [error, setError] = useState8(null);
|
|
2571
|
+
const fetchAgents = useCallback8(async () => {
|
|
2470
2572
|
setIsLoading(true);
|
|
2471
2573
|
setError(null);
|
|
2472
2574
|
try {
|
|
@@ -2494,7 +2596,7 @@ function useAgents(options = true) {
|
|
|
2494
2596
|
setIsLoading(false);
|
|
2495
2597
|
}
|
|
2496
2598
|
}, [fetchWithAuth, page, limit, search, category, scope]);
|
|
2497
|
-
const getAgent =
|
|
2599
|
+
const getAgent = useCallback8(
|
|
2498
2600
|
async (agentId) => {
|
|
2499
2601
|
const res = await fetchWithAuth(`/agents/${agentId}`);
|
|
2500
2602
|
if (!res.ok) throw new Error(`Failed to fetch agent: ${res.statusText}`);
|
|
@@ -2502,7 +2604,7 @@ function useAgents(options = true) {
|
|
|
2502
2604
|
},
|
|
2503
2605
|
[fetchWithAuth]
|
|
2504
2606
|
);
|
|
2505
|
-
const createAgent =
|
|
2607
|
+
const createAgent = useCallback8(
|
|
2506
2608
|
async (input) => {
|
|
2507
2609
|
setError(null);
|
|
2508
2610
|
try {
|
|
@@ -2526,7 +2628,7 @@ function useAgents(options = true) {
|
|
|
2526
2628
|
},
|
|
2527
2629
|
[fetchWithAuth]
|
|
2528
2630
|
);
|
|
2529
|
-
const updateAgent =
|
|
2631
|
+
const updateAgent = useCallback8(
|
|
2530
2632
|
async (agentId, input) => {
|
|
2531
2633
|
setError(null);
|
|
2532
2634
|
try {
|
|
@@ -2550,7 +2652,7 @@ function useAgents(options = true) {
|
|
|
2550
2652
|
},
|
|
2551
2653
|
[fetchWithAuth]
|
|
2552
2654
|
);
|
|
2553
|
-
const deleteAgent =
|
|
2655
|
+
const deleteAgent = useCallback8(
|
|
2554
2656
|
async (agentId) => {
|
|
2555
2657
|
setError(null);
|
|
2556
2658
|
try {
|
|
@@ -2568,7 +2670,7 @@ function useAgents(options = true) {
|
|
|
2568
2670
|
},
|
|
2569
2671
|
[fetchWithAuth]
|
|
2570
2672
|
);
|
|
2571
|
-
const bulkDeleteAgents =
|
|
2673
|
+
const bulkDeleteAgents = useCallback8(
|
|
2572
2674
|
async (ids) => {
|
|
2573
2675
|
setError(null);
|
|
2574
2676
|
try {
|
|
@@ -2593,7 +2695,7 @@ function useAgents(options = true) {
|
|
|
2593
2695
|
},
|
|
2594
2696
|
[fetchWithAuth]
|
|
2595
2697
|
);
|
|
2596
|
-
|
|
2698
|
+
useEffect8(() => {
|
|
2597
2699
|
if (autoFetch) void fetchAgents();
|
|
2598
2700
|
}, [autoFetch, fetchAgents]);
|
|
2599
2701
|
return {
|
|
@@ -2611,13 +2713,13 @@ function useAgents(options = true) {
|
|
|
2611
2713
|
}
|
|
2612
2714
|
|
|
2613
2715
|
// src/hooks/useConnection.ts
|
|
2614
|
-
import { useCallback as
|
|
2716
|
+
import { useCallback as useCallback9, useEffect as useEffect9, useState as useState9 } from "react";
|
|
2615
2717
|
function useConnection(autoCheck = true) {
|
|
2616
2718
|
const { fetchWithAuth } = usePersonaContext();
|
|
2617
|
-
const [health, setHealth] =
|
|
2618
|
-
const [isConnected, setIsConnected] =
|
|
2619
|
-
const [isLoading, setIsLoading] =
|
|
2620
|
-
const checkHealth =
|
|
2719
|
+
const [health, setHealth] = useState9(null);
|
|
2720
|
+
const [isConnected, setIsConnected] = useState9(false);
|
|
2721
|
+
const [isLoading, setIsLoading] = useState9(false);
|
|
2722
|
+
const checkHealth = useCallback9(async () => {
|
|
2621
2723
|
setIsLoading(true);
|
|
2622
2724
|
try {
|
|
2623
2725
|
const res = await fetchWithAuth("/health");
|
|
@@ -2636,7 +2738,7 @@ function useConnection(autoCheck = true) {
|
|
|
2636
2738
|
setIsLoading(false);
|
|
2637
2739
|
}
|
|
2638
2740
|
}, [fetchWithAuth]);
|
|
2639
|
-
|
|
2741
|
+
useEffect9(() => {
|
|
2640
2742
|
if (autoCheck) {
|
|
2641
2743
|
void checkHealth();
|
|
2642
2744
|
}
|
|
@@ -2650,15 +2752,15 @@ function useConnection(autoCheck = true) {
|
|
|
2650
2752
|
}
|
|
2651
2753
|
|
|
2652
2754
|
// src/hooks/useMcpConnections.ts
|
|
2653
|
-
import { useCallback as
|
|
2755
|
+
import { useCallback as useCallback10, useEffect as useEffect10, useState as useState10 } from "react";
|
|
2654
2756
|
function useMcpConnections(options = {}) {
|
|
2655
2757
|
const { defaultAgentId, fetchWithAuth } = usePersonaContext();
|
|
2656
2758
|
const agentId = options.agentId ?? defaultAgentId;
|
|
2657
2759
|
const autoFetch = options.autoFetch ?? true;
|
|
2658
|
-
const [connections, setConnections] =
|
|
2659
|
-
const [isLoading, setIsLoading] =
|
|
2660
|
-
const [error, setError] =
|
|
2661
|
-
const fetchConnections =
|
|
2760
|
+
const [connections, setConnections] = useState10([]);
|
|
2761
|
+
const [isLoading, setIsLoading] = useState10(false);
|
|
2762
|
+
const [error, setError] = useState10(null);
|
|
2763
|
+
const fetchConnections = useCallback10(async () => {
|
|
2662
2764
|
if (!agentId) return [];
|
|
2663
2765
|
setIsLoading(true);
|
|
2664
2766
|
setError(null);
|
|
@@ -2682,8 +2784,8 @@ function useMcpConnections(options = {}) {
|
|
|
2682
2784
|
setIsLoading(false);
|
|
2683
2785
|
}
|
|
2684
2786
|
}, [agentId, fetchWithAuth, options.returnTo]);
|
|
2685
|
-
const [isDisconnecting, setIsDisconnecting] =
|
|
2686
|
-
const disconnect =
|
|
2787
|
+
const [isDisconnecting, setIsDisconnecting] = useState10(false);
|
|
2788
|
+
const disconnect = useCallback10(
|
|
2687
2789
|
async (mcpId) => {
|
|
2688
2790
|
setIsDisconnecting(true);
|
|
2689
2791
|
setError(null);
|
|
@@ -2709,7 +2811,7 @@ function useMcpConnections(options = {}) {
|
|
|
2709
2811
|
},
|
|
2710
2812
|
[fetchWithAuth, fetchConnections]
|
|
2711
2813
|
);
|
|
2712
|
-
|
|
2814
|
+
useEffect10(() => {
|
|
2713
2815
|
if (autoFetch) void fetchConnections();
|
|
2714
2816
|
}, [autoFetch, fetchConnections]);
|
|
2715
2817
|
return {
|
|
@@ -2725,11 +2827,11 @@ function useMcpConnections(options = {}) {
|
|
|
2725
2827
|
}
|
|
2726
2828
|
|
|
2727
2829
|
// src/hooks/useMcp.ts
|
|
2728
|
-
import { useCallback as
|
|
2830
|
+
import { useCallback as useCallback11 } from "react";
|
|
2729
2831
|
function useMcp(options = {}) {
|
|
2730
2832
|
const { fetchWithAuth } = usePersonaContext();
|
|
2731
2833
|
const defaultMcpId = options.mcpId;
|
|
2732
|
-
const readResource =
|
|
2834
|
+
const readResource = useCallback11(
|
|
2733
2835
|
async (uri, mcpId) => {
|
|
2734
2836
|
const id = mcpId ?? defaultMcpId;
|
|
2735
2837
|
if (!id) throw new Error("MCP server ID is required to read resource");
|
|
@@ -2743,7 +2845,7 @@ function useMcp(options = {}) {
|
|
|
2743
2845
|
},
|
|
2744
2846
|
[fetchWithAuth, defaultMcpId]
|
|
2745
2847
|
);
|
|
2746
|
-
const callTool =
|
|
2848
|
+
const callTool = useCallback11(
|
|
2747
2849
|
async (name, args, mcpId) => {
|
|
2748
2850
|
const id = mcpId ?? defaultMcpId;
|
|
2749
2851
|
if (!id) throw new Error("MCP server ID is required to call tool");
|
|
@@ -2766,20 +2868,20 @@ function useMcp(options = {}) {
|
|
|
2766
2868
|
}
|
|
2767
2869
|
|
|
2768
2870
|
// src/hooks/useSkills.ts
|
|
2769
|
-
import { useCallback as
|
|
2871
|
+
import { useCallback as useCallback12, useEffect as useEffect11, useState as useState11 } from "react";
|
|
2770
2872
|
function useSkills(options = {}) {
|
|
2771
2873
|
const { autoFetch = true, page, limit, search, scope } = options;
|
|
2772
2874
|
const { fetchWithAuth } = usePersonaContext();
|
|
2773
|
-
const [skills, setSkills] =
|
|
2774
|
-
const [pagination, setPagination] =
|
|
2875
|
+
const [skills, setSkills] = useState11([]);
|
|
2876
|
+
const [pagination, setPagination] = useState11({
|
|
2775
2877
|
total: 0,
|
|
2776
2878
|
page: page ?? 1,
|
|
2777
2879
|
limit: limit ?? 20,
|
|
2778
2880
|
pages: 0
|
|
2779
2881
|
});
|
|
2780
|
-
const [isLoading, setIsLoading] =
|
|
2781
|
-
const [error, setError] =
|
|
2782
|
-
const fetchSkills =
|
|
2882
|
+
const [isLoading, setIsLoading] = useState11(false);
|
|
2883
|
+
const [error, setError] = useState11(null);
|
|
2884
|
+
const fetchSkills = useCallback12(async () => {
|
|
2783
2885
|
setIsLoading(true);
|
|
2784
2886
|
setError(null);
|
|
2785
2887
|
try {
|
|
@@ -2806,7 +2908,7 @@ function useSkills(options = {}) {
|
|
|
2806
2908
|
setIsLoading(false);
|
|
2807
2909
|
}
|
|
2808
2910
|
}, [fetchWithAuth, page, limit, search, scope]);
|
|
2809
|
-
const getSkill =
|
|
2911
|
+
const getSkill = useCallback12(
|
|
2810
2912
|
async (skillId) => {
|
|
2811
2913
|
const res = await fetchWithAuth(`/skills/${skillId}`);
|
|
2812
2914
|
if (!res.ok) throw new Error(`Failed to fetch skill: ${res.statusText}`);
|
|
@@ -2814,7 +2916,7 @@ function useSkills(options = {}) {
|
|
|
2814
2916
|
},
|
|
2815
2917
|
[fetchWithAuth]
|
|
2816
2918
|
);
|
|
2817
|
-
const createSkill =
|
|
2919
|
+
const createSkill = useCallback12(
|
|
2818
2920
|
async (input) => {
|
|
2819
2921
|
setError(null);
|
|
2820
2922
|
try {
|
|
@@ -2838,7 +2940,7 @@ function useSkills(options = {}) {
|
|
|
2838
2940
|
},
|
|
2839
2941
|
[fetchWithAuth]
|
|
2840
2942
|
);
|
|
2841
|
-
const updateSkill =
|
|
2943
|
+
const updateSkill = useCallback12(
|
|
2842
2944
|
async (skillId, input) => {
|
|
2843
2945
|
setError(null);
|
|
2844
2946
|
try {
|
|
@@ -2862,7 +2964,7 @@ function useSkills(options = {}) {
|
|
|
2862
2964
|
},
|
|
2863
2965
|
[fetchWithAuth]
|
|
2864
2966
|
);
|
|
2865
|
-
const deleteSkill =
|
|
2967
|
+
const deleteSkill = useCallback12(
|
|
2866
2968
|
async (skillId) => {
|
|
2867
2969
|
setError(null);
|
|
2868
2970
|
try {
|
|
@@ -2880,7 +2982,7 @@ function useSkills(options = {}) {
|
|
|
2880
2982
|
},
|
|
2881
2983
|
[fetchWithAuth]
|
|
2882
2984
|
);
|
|
2883
|
-
const bulkDeleteSkills =
|
|
2985
|
+
const bulkDeleteSkills = useCallback12(
|
|
2884
2986
|
async (ids) => {
|
|
2885
2987
|
setError(null);
|
|
2886
2988
|
try {
|
|
@@ -2905,7 +3007,7 @@ function useSkills(options = {}) {
|
|
|
2905
3007
|
},
|
|
2906
3008
|
[fetchWithAuth]
|
|
2907
3009
|
);
|
|
2908
|
-
const getSkillUsage =
|
|
3010
|
+
const getSkillUsage = useCallback12(
|
|
2909
3011
|
async (skillId) => {
|
|
2910
3012
|
const res = await fetchWithAuth(`/skills/${skillId}/usage`);
|
|
2911
3013
|
if (!res.ok) throw new Error(`Failed to fetch skill usage: ${res.statusText}`);
|
|
@@ -2913,7 +3015,7 @@ function useSkills(options = {}) {
|
|
|
2913
3015
|
},
|
|
2914
3016
|
[fetchWithAuth]
|
|
2915
3017
|
);
|
|
2916
|
-
|
|
3018
|
+
useEffect11(() => {
|
|
2917
3019
|
if (autoFetch) void fetchSkills();
|
|
2918
3020
|
}, [autoFetch, fetchSkills]);
|
|
2919
3021
|
return {
|
|
@@ -2932,20 +3034,20 @@ function useSkills(options = {}) {
|
|
|
2932
3034
|
}
|
|
2933
3035
|
|
|
2934
3036
|
// src/hooks/useRcpSources.ts
|
|
2935
|
-
import { useCallback as
|
|
3037
|
+
import { useCallback as useCallback13, useEffect as useEffect12, useState as useState12 } from "react";
|
|
2936
3038
|
function useRcpSources(options = {}) {
|
|
2937
3039
|
const { autoFetch = true, page, limit, search } = options;
|
|
2938
3040
|
const { fetchWithAuth } = usePersonaContext();
|
|
2939
|
-
const [rcpSources, setRcpSources] =
|
|
2940
|
-
const [pagination, setPagination] =
|
|
3041
|
+
const [rcpSources, setRcpSources] = useState12([]);
|
|
3042
|
+
const [pagination, setPagination] = useState12({
|
|
2941
3043
|
total: 0,
|
|
2942
3044
|
page: page ?? 1,
|
|
2943
3045
|
limit: limit ?? 20,
|
|
2944
3046
|
pages: 0
|
|
2945
3047
|
});
|
|
2946
|
-
const [isLoading, setIsLoading] =
|
|
2947
|
-
const [error, setError] =
|
|
2948
|
-
const fetchRcpSources =
|
|
3048
|
+
const [isLoading, setIsLoading] = useState12(false);
|
|
3049
|
+
const [error, setError] = useState12(null);
|
|
3050
|
+
const fetchRcpSources = useCallback13(async () => {
|
|
2949
3051
|
setIsLoading(true);
|
|
2950
3052
|
setError(null);
|
|
2951
3053
|
try {
|
|
@@ -2971,7 +3073,7 @@ function useRcpSources(options = {}) {
|
|
|
2971
3073
|
setIsLoading(false);
|
|
2972
3074
|
}
|
|
2973
3075
|
}, [fetchWithAuth, page, limit, search]);
|
|
2974
|
-
const getRcpSource =
|
|
3076
|
+
const getRcpSource = useCallback13(
|
|
2975
3077
|
async (sourceId) => {
|
|
2976
3078
|
const res = await fetchWithAuth(`/rcp-sources/${sourceId}`);
|
|
2977
3079
|
if (!res.ok) throw new Error(`Failed to fetch RCP source: ${res.statusText}`);
|
|
@@ -2979,7 +3081,7 @@ function useRcpSources(options = {}) {
|
|
|
2979
3081
|
},
|
|
2980
3082
|
[fetchWithAuth]
|
|
2981
3083
|
);
|
|
2982
|
-
const createRcpSource =
|
|
3084
|
+
const createRcpSource = useCallback13(
|
|
2983
3085
|
async (input) => {
|
|
2984
3086
|
setError(null);
|
|
2985
3087
|
try {
|
|
@@ -3003,7 +3105,7 @@ function useRcpSources(options = {}) {
|
|
|
3003
3105
|
},
|
|
3004
3106
|
[fetchWithAuth]
|
|
3005
3107
|
);
|
|
3006
|
-
const updateRcpSource =
|
|
3108
|
+
const updateRcpSource = useCallback13(
|
|
3007
3109
|
async (sourceId, input) => {
|
|
3008
3110
|
setError(null);
|
|
3009
3111
|
try {
|
|
@@ -3027,7 +3129,7 @@ function useRcpSources(options = {}) {
|
|
|
3027
3129
|
},
|
|
3028
3130
|
[fetchWithAuth]
|
|
3029
3131
|
);
|
|
3030
|
-
const deleteRcpSource =
|
|
3132
|
+
const deleteRcpSource = useCallback13(
|
|
3031
3133
|
async (sourceId) => {
|
|
3032
3134
|
setError(null);
|
|
3033
3135
|
try {
|
|
@@ -3045,7 +3147,7 @@ function useRcpSources(options = {}) {
|
|
|
3045
3147
|
},
|
|
3046
3148
|
[fetchWithAuth]
|
|
3047
3149
|
);
|
|
3048
|
-
const bulkDeleteRcpSources =
|
|
3150
|
+
const bulkDeleteRcpSources = useCallback13(
|
|
3049
3151
|
async (ids) => {
|
|
3050
3152
|
setError(null);
|
|
3051
3153
|
try {
|
|
@@ -3070,7 +3172,7 @@ function useRcpSources(options = {}) {
|
|
|
3070
3172
|
},
|
|
3071
3173
|
[fetchWithAuth]
|
|
3072
3174
|
);
|
|
3073
|
-
const getRcpSourceUsage =
|
|
3175
|
+
const getRcpSourceUsage = useCallback13(
|
|
3074
3176
|
async (sourceId) => {
|
|
3075
3177
|
const res = await fetchWithAuth(`/rcp-sources/${sourceId}/usage`);
|
|
3076
3178
|
if (!res.ok) throw new Error(`Failed to fetch RCP source usage: ${res.statusText}`);
|
|
@@ -3078,7 +3180,7 @@ function useRcpSources(options = {}) {
|
|
|
3078
3180
|
},
|
|
3079
3181
|
[fetchWithAuth]
|
|
3080
3182
|
);
|
|
3081
|
-
const testRcpSourceConnection =
|
|
3183
|
+
const testRcpSourceConnection = useCallback13(
|
|
3082
3184
|
async (sourceId) => {
|
|
3083
3185
|
setError(null);
|
|
3084
3186
|
try {
|
|
@@ -3102,7 +3204,7 @@ function useRcpSources(options = {}) {
|
|
|
3102
3204
|
},
|
|
3103
3205
|
[fetchWithAuth]
|
|
3104
3206
|
);
|
|
3105
|
-
|
|
3207
|
+
useEffect12(() => {
|
|
3106
3208
|
if (autoFetch) void fetchRcpSources();
|
|
3107
3209
|
}, [autoFetch, fetchRcpSources]);
|
|
3108
3210
|
return {
|
|
@@ -3122,21 +3224,21 @@ function useRcpSources(options = {}) {
|
|
|
3122
3224
|
}
|
|
3123
3225
|
|
|
3124
3226
|
// src/hooks/useKnowledgeBases.ts
|
|
3125
|
-
import { useCallback as
|
|
3227
|
+
import { useCallback as useCallback14, useEffect as useEffect13, useState as useState13 } from "react";
|
|
3126
3228
|
function useKnowledgeBases(options = {}) {
|
|
3127
3229
|
const { autoFetch = true, page, limit, search, scope } = options;
|
|
3128
3230
|
const { fetchWithAuth } = usePersonaContext();
|
|
3129
|
-
const [knowledgeBases, setKnowledgeBases] =
|
|
3130
|
-
const [pagination, setPagination] =
|
|
3231
|
+
const [knowledgeBases, setKnowledgeBases] = useState13([]);
|
|
3232
|
+
const [pagination, setPagination] = useState13({
|
|
3131
3233
|
total: 0,
|
|
3132
3234
|
page: page ?? 1,
|
|
3133
3235
|
limit: limit ?? 20,
|
|
3134
3236
|
pages: 0
|
|
3135
3237
|
});
|
|
3136
|
-
const [isLoading, setIsLoading] =
|
|
3137
|
-
const [isUploading, setIsUploading] =
|
|
3138
|
-
const [error, setError] =
|
|
3139
|
-
const fetchKnowledgeBases =
|
|
3238
|
+
const [isLoading, setIsLoading] = useState13(false);
|
|
3239
|
+
const [isUploading, setIsUploading] = useState13(false);
|
|
3240
|
+
const [error, setError] = useState13(null);
|
|
3241
|
+
const fetchKnowledgeBases = useCallback14(async () => {
|
|
3140
3242
|
setIsLoading(true);
|
|
3141
3243
|
setError(null);
|
|
3142
3244
|
try {
|
|
@@ -3163,7 +3265,7 @@ function useKnowledgeBases(options = {}) {
|
|
|
3163
3265
|
setIsLoading(false);
|
|
3164
3266
|
}
|
|
3165
3267
|
}, [fetchWithAuth, page, limit, search, scope]);
|
|
3166
|
-
const getKnowledgeBase =
|
|
3268
|
+
const getKnowledgeBase = useCallback14(
|
|
3167
3269
|
async (kbId) => {
|
|
3168
3270
|
const res = await fetchWithAuth(`/knowledge/${kbId}`);
|
|
3169
3271
|
if (!res.ok) throw new Error(`Failed to fetch knowledge base: ${res.statusText}`);
|
|
@@ -3171,7 +3273,7 @@ function useKnowledgeBases(options = {}) {
|
|
|
3171
3273
|
},
|
|
3172
3274
|
[fetchWithAuth]
|
|
3173
3275
|
);
|
|
3174
|
-
const createKnowledgeBase =
|
|
3276
|
+
const createKnowledgeBase = useCallback14(
|
|
3175
3277
|
async (input) => {
|
|
3176
3278
|
setError(null);
|
|
3177
3279
|
try {
|
|
@@ -3195,7 +3297,7 @@ function useKnowledgeBases(options = {}) {
|
|
|
3195
3297
|
},
|
|
3196
3298
|
[fetchWithAuth]
|
|
3197
3299
|
);
|
|
3198
|
-
const updateKnowledgeBase =
|
|
3300
|
+
const updateKnowledgeBase = useCallback14(
|
|
3199
3301
|
async (kbId, input) => {
|
|
3200
3302
|
setError(null);
|
|
3201
3303
|
try {
|
|
@@ -3219,7 +3321,7 @@ function useKnowledgeBases(options = {}) {
|
|
|
3219
3321
|
},
|
|
3220
3322
|
[fetchWithAuth]
|
|
3221
3323
|
);
|
|
3222
|
-
const deleteKnowledgeBase =
|
|
3324
|
+
const deleteKnowledgeBase = useCallback14(
|
|
3223
3325
|
async (kbId) => {
|
|
3224
3326
|
setError(null);
|
|
3225
3327
|
try {
|
|
@@ -3237,7 +3339,7 @@ function useKnowledgeBases(options = {}) {
|
|
|
3237
3339
|
},
|
|
3238
3340
|
[fetchWithAuth]
|
|
3239
3341
|
);
|
|
3240
|
-
const bulkDeleteKnowledgeBases =
|
|
3342
|
+
const bulkDeleteKnowledgeBases = useCallback14(
|
|
3241
3343
|
async (ids) => {
|
|
3242
3344
|
setError(null);
|
|
3243
3345
|
try {
|
|
@@ -3262,7 +3364,7 @@ function useKnowledgeBases(options = {}) {
|
|
|
3262
3364
|
},
|
|
3263
3365
|
[fetchWithAuth]
|
|
3264
3366
|
);
|
|
3265
|
-
const getKnowledgeBaseUsage =
|
|
3367
|
+
const getKnowledgeBaseUsage = useCallback14(
|
|
3266
3368
|
async (kbId) => {
|
|
3267
3369
|
const res = await fetchWithAuth(`/knowledge/${kbId}/usage`);
|
|
3268
3370
|
if (!res.ok) throw new Error(`Failed to fetch knowledge base usage: ${res.statusText}`);
|
|
@@ -3270,7 +3372,7 @@ function useKnowledgeBases(options = {}) {
|
|
|
3270
3372
|
},
|
|
3271
3373
|
[fetchWithAuth]
|
|
3272
3374
|
);
|
|
3273
|
-
const uploadDocuments =
|
|
3375
|
+
const uploadDocuments = useCallback14(
|
|
3274
3376
|
async (kbId, files) => {
|
|
3275
3377
|
setIsUploading(true);
|
|
3276
3378
|
setError(null);
|
|
@@ -3312,7 +3414,7 @@ function useKnowledgeBases(options = {}) {
|
|
|
3312
3414
|
},
|
|
3313
3415
|
[fetchWithAuth]
|
|
3314
3416
|
);
|
|
3315
|
-
const listDocuments =
|
|
3417
|
+
const listDocuments = useCallback14(
|
|
3316
3418
|
async (kbId) => {
|
|
3317
3419
|
const res = await fetchWithAuth(`/knowledge/${kbId}/documents`);
|
|
3318
3420
|
if (!res.ok) throw new Error(`Failed to list documents: ${res.statusText}`);
|
|
@@ -3320,7 +3422,7 @@ function useKnowledgeBases(options = {}) {
|
|
|
3320
3422
|
},
|
|
3321
3423
|
[fetchWithAuth]
|
|
3322
3424
|
);
|
|
3323
|
-
const deleteDocument =
|
|
3425
|
+
const deleteDocument = useCallback14(
|
|
3324
3426
|
async (kbId, sourceName) => {
|
|
3325
3427
|
setError(null);
|
|
3326
3428
|
try {
|
|
@@ -3347,7 +3449,7 @@ function useKnowledgeBases(options = {}) {
|
|
|
3347
3449
|
},
|
|
3348
3450
|
[fetchWithAuth]
|
|
3349
3451
|
);
|
|
3350
|
-
const searchKnowledgeBase =
|
|
3452
|
+
const searchKnowledgeBase = useCallback14(
|
|
3351
3453
|
async (kbId, query, opts) => {
|
|
3352
3454
|
const res = await fetchWithAuth(`/knowledge/${kbId}/search`, {
|
|
3353
3455
|
method: "POST",
|
|
@@ -3362,7 +3464,7 @@ function useKnowledgeBases(options = {}) {
|
|
|
3362
3464
|
},
|
|
3363
3465
|
[fetchWithAuth]
|
|
3364
3466
|
);
|
|
3365
|
-
|
|
3467
|
+
useEffect13(() => {
|
|
3366
3468
|
if (autoFetch) void fetchKnowledgeBases();
|
|
3367
3469
|
}, [autoFetch, fetchKnowledgeBases]);
|
|
3368
3470
|
return {
|
|
@@ -3386,20 +3488,20 @@ function useKnowledgeBases(options = {}) {
|
|
|
3386
3488
|
}
|
|
3387
3489
|
|
|
3388
3490
|
// src/hooks/useMcpAdmin.ts
|
|
3389
|
-
import { useCallback as
|
|
3491
|
+
import { useCallback as useCallback15, useEffect as useEffect14, useState as useState14 } from "react";
|
|
3390
3492
|
function useMcpAdmin(options = {}) {
|
|
3391
3493
|
const { autoFetch = true, page, limit, search } = options;
|
|
3392
3494
|
const { fetchWithAuth } = usePersonaContext();
|
|
3393
|
-
const [mcps, setMcps] =
|
|
3394
|
-
const [pagination, setPagination] =
|
|
3495
|
+
const [mcps, setMcps] = useState14([]);
|
|
3496
|
+
const [pagination, setPagination] = useState14({
|
|
3395
3497
|
total: 0,
|
|
3396
3498
|
page: page ?? 1,
|
|
3397
3499
|
limit: limit ?? 20,
|
|
3398
3500
|
pages: 0
|
|
3399
3501
|
});
|
|
3400
|
-
const [isLoading, setIsLoading] =
|
|
3401
|
-
const [error, setError] =
|
|
3402
|
-
const fetchMcps =
|
|
3502
|
+
const [isLoading, setIsLoading] = useState14(false);
|
|
3503
|
+
const [error, setError] = useState14(null);
|
|
3504
|
+
const fetchMcps = useCallback15(async () => {
|
|
3403
3505
|
setIsLoading(true);
|
|
3404
3506
|
setError(null);
|
|
3405
3507
|
try {
|
|
@@ -3425,7 +3527,7 @@ function useMcpAdmin(options = {}) {
|
|
|
3425
3527
|
setIsLoading(false);
|
|
3426
3528
|
}
|
|
3427
3529
|
}, [fetchWithAuth, page, limit, search]);
|
|
3428
|
-
const getMcp =
|
|
3530
|
+
const getMcp = useCallback15(
|
|
3429
3531
|
async (mcpId) => {
|
|
3430
3532
|
const res = await fetchWithAuth(`/mcps/${mcpId}`);
|
|
3431
3533
|
if (!res.ok) throw new Error(`Failed to fetch MCP: ${res.statusText}`);
|
|
@@ -3433,7 +3535,7 @@ function useMcpAdmin(options = {}) {
|
|
|
3433
3535
|
},
|
|
3434
3536
|
[fetchWithAuth]
|
|
3435
3537
|
);
|
|
3436
|
-
const createMcp =
|
|
3538
|
+
const createMcp = useCallback15(
|
|
3437
3539
|
async (input) => {
|
|
3438
3540
|
setError(null);
|
|
3439
3541
|
try {
|
|
@@ -3457,7 +3559,7 @@ function useMcpAdmin(options = {}) {
|
|
|
3457
3559
|
},
|
|
3458
3560
|
[fetchWithAuth]
|
|
3459
3561
|
);
|
|
3460
|
-
const updateMcp =
|
|
3562
|
+
const updateMcp = useCallback15(
|
|
3461
3563
|
async (mcpId, input) => {
|
|
3462
3564
|
setError(null);
|
|
3463
3565
|
try {
|
|
@@ -3481,7 +3583,7 @@ function useMcpAdmin(options = {}) {
|
|
|
3481
3583
|
},
|
|
3482
3584
|
[fetchWithAuth]
|
|
3483
3585
|
);
|
|
3484
|
-
const deleteMcp =
|
|
3586
|
+
const deleteMcp = useCallback15(
|
|
3485
3587
|
async (mcpId) => {
|
|
3486
3588
|
setError(null);
|
|
3487
3589
|
try {
|
|
@@ -3499,7 +3601,7 @@ function useMcpAdmin(options = {}) {
|
|
|
3499
3601
|
},
|
|
3500
3602
|
[fetchWithAuth]
|
|
3501
3603
|
);
|
|
3502
|
-
const bulkDeleteMcps =
|
|
3604
|
+
const bulkDeleteMcps = useCallback15(
|
|
3503
3605
|
async (ids) => {
|
|
3504
3606
|
setError(null);
|
|
3505
3607
|
try {
|
|
@@ -3524,7 +3626,7 @@ function useMcpAdmin(options = {}) {
|
|
|
3524
3626
|
},
|
|
3525
3627
|
[fetchWithAuth]
|
|
3526
3628
|
);
|
|
3527
|
-
const testConnection =
|
|
3629
|
+
const testConnection = useCallback15(
|
|
3528
3630
|
async (mcpId) => {
|
|
3529
3631
|
setError(null);
|
|
3530
3632
|
try {
|
|
@@ -3548,7 +3650,7 @@ function useMcpAdmin(options = {}) {
|
|
|
3548
3650
|
},
|
|
3549
3651
|
[fetchWithAuth]
|
|
3550
3652
|
);
|
|
3551
|
-
|
|
3653
|
+
useEffect14(() => {
|
|
3552
3654
|
if (autoFetch) void fetchMcps();
|
|
3553
3655
|
}, [autoFetch, fetchMcps]);
|
|
3554
3656
|
return {
|
|
@@ -3567,21 +3669,21 @@ function useMcpAdmin(options = {}) {
|
|
|
3567
3669
|
}
|
|
3568
3670
|
|
|
3569
3671
|
// src/hooks/useWorkflows.ts
|
|
3570
|
-
import { useCallback as
|
|
3672
|
+
import { useCallback as useCallback16, useEffect as useEffect15, useState as useState15 } from "react";
|
|
3571
3673
|
function useWorkflows(options) {
|
|
3572
3674
|
const opts = typeof options === "boolean" ? { autoFetch: options } : options ?? {};
|
|
3573
3675
|
const { autoFetch = true, search, scope, visibility, isEnabled, page, limit } = opts;
|
|
3574
3676
|
const { fetchWithAuth } = usePersonaContext();
|
|
3575
|
-
const [workflows, setWorkflows] =
|
|
3576
|
-
const [pagination, setPagination] =
|
|
3677
|
+
const [workflows, setWorkflows] = useState15([]);
|
|
3678
|
+
const [pagination, setPagination] = useState15({
|
|
3577
3679
|
page: page ?? 1,
|
|
3578
3680
|
limit: limit ?? 20,
|
|
3579
3681
|
total: 0,
|
|
3580
3682
|
totalPages: 0
|
|
3581
3683
|
});
|
|
3582
|
-
const [isLoading, setIsLoading] =
|
|
3583
|
-
const [error, setError] =
|
|
3584
|
-
const fetchWorkflows =
|
|
3684
|
+
const [isLoading, setIsLoading] = useState15(false);
|
|
3685
|
+
const [error, setError] = useState15(null);
|
|
3686
|
+
const fetchWorkflows = useCallback16(async () => {
|
|
3585
3687
|
setIsLoading(true);
|
|
3586
3688
|
setError(null);
|
|
3587
3689
|
try {
|
|
@@ -3627,7 +3729,7 @@ function useWorkflows(options) {
|
|
|
3627
3729
|
setIsLoading(false);
|
|
3628
3730
|
}
|
|
3629
3731
|
}, [fetchWithAuth, search, scope, visibility, isEnabled, page, limit]);
|
|
3630
|
-
const createWorkflow =
|
|
3732
|
+
const createWorkflow = useCallback16(
|
|
3631
3733
|
async (input) => {
|
|
3632
3734
|
setError(null);
|
|
3633
3735
|
try {
|
|
@@ -3651,7 +3753,7 @@ function useWorkflows(options) {
|
|
|
3651
3753
|
},
|
|
3652
3754
|
[fetchWithAuth]
|
|
3653
3755
|
);
|
|
3654
|
-
|
|
3756
|
+
useEffect15(() => {
|
|
3655
3757
|
if (autoFetch) {
|
|
3656
3758
|
void fetchWorkflows();
|
|
3657
3759
|
}
|
|
@@ -3667,17 +3769,17 @@ function useWorkflows(options) {
|
|
|
3667
3769
|
}
|
|
3668
3770
|
|
|
3669
3771
|
// src/hooks/useWorkflow.ts
|
|
3670
|
-
import { useCallback as
|
|
3772
|
+
import { useCallback as useCallback17, useEffect as useEffect16, useState as useState16 } from "react";
|
|
3671
3773
|
function useWorkflow(workflowId, options) {
|
|
3672
3774
|
const opts = typeof options === "boolean" ? { autoFetch: options } : options ?? {};
|
|
3673
3775
|
const { autoFetch = true } = opts;
|
|
3674
3776
|
const { fetchWithAuth } = usePersonaContext();
|
|
3675
|
-
const [workflow, setWorkflow] =
|
|
3676
|
-
const [versions, setVersions] =
|
|
3677
|
-
const [mermaid, setMermaid] =
|
|
3678
|
-
const [isLoading, setIsLoading] =
|
|
3679
|
-
const [error, setError] =
|
|
3680
|
-
const fetchWorkflow =
|
|
3777
|
+
const [workflow, setWorkflow] = useState16(null);
|
|
3778
|
+
const [versions, setVersions] = useState16([]);
|
|
3779
|
+
const [mermaid, setMermaid] = useState16(null);
|
|
3780
|
+
const [isLoading, setIsLoading] = useState16(false);
|
|
3781
|
+
const [error, setError] = useState16(null);
|
|
3782
|
+
const fetchWorkflow = useCallback17(async () => {
|
|
3681
3783
|
if (!workflowId) return null;
|
|
3682
3784
|
setIsLoading(true);
|
|
3683
3785
|
setError(null);
|
|
@@ -3697,7 +3799,7 @@ function useWorkflow(workflowId, options) {
|
|
|
3697
3799
|
setIsLoading(false);
|
|
3698
3800
|
}
|
|
3699
3801
|
}, [fetchWithAuth, workflowId]);
|
|
3700
|
-
const fetchVersions =
|
|
3802
|
+
const fetchVersions = useCallback17(async () => {
|
|
3701
3803
|
if (!workflowId) return [];
|
|
3702
3804
|
try {
|
|
3703
3805
|
const res = await fetchWithAuth(`/workflows/${workflowId}/versions`);
|
|
@@ -3710,7 +3812,7 @@ function useWorkflow(workflowId, options) {
|
|
|
3710
3812
|
return [];
|
|
3711
3813
|
}
|
|
3712
3814
|
}, [fetchWithAuth, workflowId]);
|
|
3713
|
-
const getVersion =
|
|
3815
|
+
const getVersion = useCallback17(
|
|
3714
3816
|
async (version) => {
|
|
3715
3817
|
if (!workflowId) throw new Error("Workflow ID is required");
|
|
3716
3818
|
const res = await fetchWithAuth(`/workflows/${workflowId}/versions/${version}`);
|
|
@@ -3721,7 +3823,7 @@ function useWorkflow(workflowId, options) {
|
|
|
3721
3823
|
},
|
|
3722
3824
|
[fetchWithAuth, workflowId]
|
|
3723
3825
|
);
|
|
3724
|
-
const fetchMermaid =
|
|
3826
|
+
const fetchMermaid = useCallback17(async () => {
|
|
3725
3827
|
if (!workflowId) return "";
|
|
3726
3828
|
try {
|
|
3727
3829
|
const res = await fetchWithAuth(`/workflows/${workflowId}/mermaid`);
|
|
@@ -3734,7 +3836,7 @@ function useWorkflow(workflowId, options) {
|
|
|
3734
3836
|
return "";
|
|
3735
3837
|
}
|
|
3736
3838
|
}, [fetchWithAuth, workflowId]);
|
|
3737
|
-
const updateWorkflow =
|
|
3839
|
+
const updateWorkflow = useCallback17(
|
|
3738
3840
|
async (input) => {
|
|
3739
3841
|
if (!workflowId) throw new Error("Workflow ID is required");
|
|
3740
3842
|
setError(null);
|
|
@@ -3753,7 +3855,7 @@ function useWorkflow(workflowId, options) {
|
|
|
3753
3855
|
},
|
|
3754
3856
|
[fetchWithAuth, workflowId]
|
|
3755
3857
|
);
|
|
3756
|
-
const saveDraft =
|
|
3858
|
+
const saveDraft = useCallback17(
|
|
3757
3859
|
async (draft) => {
|
|
3758
3860
|
if (!workflowId) throw new Error("Workflow ID is required");
|
|
3759
3861
|
setError(null);
|
|
@@ -3772,7 +3874,7 @@ function useWorkflow(workflowId, options) {
|
|
|
3772
3874
|
},
|
|
3773
3875
|
[fetchWithAuth, workflowId]
|
|
3774
3876
|
);
|
|
3775
|
-
const publish =
|
|
3877
|
+
const publish = useCallback17(async () => {
|
|
3776
3878
|
if (!workflowId) throw new Error("Workflow ID is required");
|
|
3777
3879
|
setError(null);
|
|
3778
3880
|
const res = await fetchWithAuth(`/workflows/${workflowId}/publish`, {
|
|
@@ -3787,7 +3889,7 @@ function useWorkflow(workflowId, options) {
|
|
|
3787
3889
|
void fetchVersions();
|
|
3788
3890
|
return versionResult;
|
|
3789
3891
|
}, [fetchWithAuth, workflowId, fetchWorkflow, fetchVersions]);
|
|
3790
|
-
const deleteWorkflow =
|
|
3892
|
+
const deleteWorkflow = useCallback17(async () => {
|
|
3791
3893
|
if (!workflowId) throw new Error("Workflow ID is required");
|
|
3792
3894
|
setError(null);
|
|
3793
3895
|
const res = await fetchWithAuth(`/workflows/${workflowId}`, {
|
|
@@ -3798,7 +3900,7 @@ function useWorkflow(workflowId, options) {
|
|
|
3798
3900
|
}
|
|
3799
3901
|
setWorkflow(null);
|
|
3800
3902
|
}, [fetchWithAuth, workflowId]);
|
|
3801
|
-
|
|
3903
|
+
useEffect16(() => {
|
|
3802
3904
|
if (autoFetch && workflowId) {
|
|
3803
3905
|
void fetchWorkflow();
|
|
3804
3906
|
}
|
|
@@ -3821,25 +3923,25 @@ function useWorkflow(workflowId, options) {
|
|
|
3821
3923
|
}
|
|
3822
3924
|
|
|
3823
3925
|
// src/hooks/useWorkflowStream.ts
|
|
3824
|
-
import { useCallback as
|
|
3926
|
+
import { useCallback as useCallback18, useEffect as useEffect17, useRef as useRef4, useState as useState17 } from "react";
|
|
3825
3927
|
function useWorkflowStream(workflowId, options) {
|
|
3826
3928
|
const { baseUrl, getAuthToken, fetchWithAuth, logger } = usePersonaContext();
|
|
3827
|
-
const [status, setStatus] =
|
|
3828
|
-
const [runId, setRunId] =
|
|
3829
|
-
const [activeNodeId, setActiveNodeId] =
|
|
3830
|
-
const [nodeRuns, setNodeRuns] =
|
|
3929
|
+
const [status, setStatus] = useState17("idle");
|
|
3930
|
+
const [runId, setRunId] = useState17(null);
|
|
3931
|
+
const [activeNodeId, setActiveNodeId] = useState17(null);
|
|
3932
|
+
const [nodeRuns, setNodeRuns] = useState17(
|
|
3831
3933
|
{}
|
|
3832
3934
|
);
|
|
3833
|
-
const [text, setText] =
|
|
3834
|
-
const [output, setOutput] =
|
|
3835
|
-
const [error, setError] =
|
|
3836
|
-
const [events, setEvents] =
|
|
3935
|
+
const [text, setText] = useState17("");
|
|
3936
|
+
const [output, setOutput] = useState17(null);
|
|
3937
|
+
const [error, setError] = useState17(null);
|
|
3938
|
+
const [events, setEvents] = useState17([]);
|
|
3837
3939
|
const abortControllerRef = useRef4(null);
|
|
3838
3940
|
const currentRunIdRef = useRef4(null);
|
|
3839
3941
|
currentRunIdRef.current = runId;
|
|
3840
3942
|
const optionsRef = useRef4(options);
|
|
3841
3943
|
optionsRef.current = options;
|
|
3842
|
-
const cancel =
|
|
3944
|
+
const cancel = useCallback18(async () => {
|
|
3843
3945
|
if (abortControllerRef.current) {
|
|
3844
3946
|
abortControllerRef.current.abort();
|
|
3845
3947
|
abortControllerRef.current = null;
|
|
@@ -3860,7 +3962,7 @@ function useWorkflowStream(workflowId, options) {
|
|
|
3860
3962
|
setStatus("cancelled");
|
|
3861
3963
|
setActiveNodeId(null);
|
|
3862
3964
|
}, [fetchWithAuth, logger]);
|
|
3863
|
-
const reset =
|
|
3965
|
+
const reset = useCallback18(() => {
|
|
3864
3966
|
if (abortControllerRef.current) {
|
|
3865
3967
|
abortControllerRef.current.abort();
|
|
3866
3968
|
abortControllerRef.current = null;
|
|
@@ -3874,7 +3976,7 @@ function useWorkflowStream(workflowId, options) {
|
|
|
3874
3976
|
setError(null);
|
|
3875
3977
|
setEvents([]);
|
|
3876
3978
|
}, []);
|
|
3877
|
-
const processStream =
|
|
3979
|
+
const processStream = useCallback18(
|
|
3878
3980
|
async (url, method, body, targetRunId) => {
|
|
3879
3981
|
if (abortControllerRef.current) {
|
|
3880
3982
|
abortControllerRef.current.abort();
|
|
@@ -4039,7 +4141,7 @@ function useWorkflowStream(workflowId, options) {
|
|
|
4039
4141
|
},
|
|
4040
4142
|
[getAuthToken]
|
|
4041
4143
|
);
|
|
4042
|
-
const start =
|
|
4144
|
+
const start = useCallback18(
|
|
4043
4145
|
async (input, opts) => {
|
|
4044
4146
|
const targetWfId = opts?.workflowId || workflowId;
|
|
4045
4147
|
if (!targetWfId) {
|
|
@@ -4060,7 +4162,7 @@ function useWorkflowStream(workflowId, options) {
|
|
|
4060
4162
|
},
|
|
4061
4163
|
[workflowId, baseUrl, processStream]
|
|
4062
4164
|
);
|
|
4063
|
-
const resume =
|
|
4165
|
+
const resume = useCallback18(
|
|
4064
4166
|
async (targetRunId, sinceSeq) => {
|
|
4065
4167
|
if (!targetRunId) {
|
|
4066
4168
|
throw new Error("Run ID is required to resume stream");
|
|
@@ -4073,7 +4175,7 @@ function useWorkflowStream(workflowId, options) {
|
|
|
4073
4175
|
},
|
|
4074
4176
|
[baseUrl, processStream]
|
|
4075
4177
|
);
|
|
4076
|
-
|
|
4178
|
+
useEffect17(() => {
|
|
4077
4179
|
return () => {
|
|
4078
4180
|
if (abortControllerRef.current) {
|
|
4079
4181
|
abortControllerRef.current.abort();
|
|
@@ -4098,21 +4200,21 @@ function useWorkflowStream(workflowId, options) {
|
|
|
4098
4200
|
}
|
|
4099
4201
|
|
|
4100
4202
|
// src/hooks/useWorkflowRuns.ts
|
|
4101
|
-
import { useCallback as
|
|
4203
|
+
import { useCallback as useCallback19, useEffect as useEffect18, useState as useState18 } from "react";
|
|
4102
4204
|
function useWorkflowRuns(workflowId, options) {
|
|
4103
4205
|
const opts = typeof options === "boolean" ? { autoFetch: options } : options ?? {};
|
|
4104
4206
|
const { autoFetch = true, page = 1, limit = 20 } = opts;
|
|
4105
4207
|
const { fetchWithAuth } = usePersonaContext();
|
|
4106
|
-
const [runs, setRuns] =
|
|
4107
|
-
const [pagination, setPagination] =
|
|
4208
|
+
const [runs, setRuns] = useState18([]);
|
|
4209
|
+
const [pagination, setPagination] = useState18({
|
|
4108
4210
|
page,
|
|
4109
4211
|
limit,
|
|
4110
4212
|
total: 0,
|
|
4111
4213
|
totalPages: 0
|
|
4112
4214
|
});
|
|
4113
|
-
const [isLoading, setIsLoading] =
|
|
4114
|
-
const [error, setError] =
|
|
4115
|
-
const fetchRuns =
|
|
4215
|
+
const [isLoading, setIsLoading] = useState18(false);
|
|
4216
|
+
const [error, setError] = useState18(null);
|
|
4217
|
+
const fetchRuns = useCallback19(async () => {
|
|
4116
4218
|
if (!workflowId) return [];
|
|
4117
4219
|
setIsLoading(true);
|
|
4118
4220
|
setError(null);
|
|
@@ -4144,7 +4246,7 @@ function useWorkflowRuns(workflowId, options) {
|
|
|
4144
4246
|
setIsLoading(false);
|
|
4145
4247
|
}
|
|
4146
4248
|
}, [fetchWithAuth, workflowId, page, limit]);
|
|
4147
|
-
const getRun =
|
|
4249
|
+
const getRun = useCallback19(
|
|
4148
4250
|
async (runId) => {
|
|
4149
4251
|
if (!runId) throw new Error("Run ID is required");
|
|
4150
4252
|
const res = await fetchWithAuth(`/workflows/runs/${runId}`);
|
|
@@ -4155,7 +4257,7 @@ function useWorkflowRuns(workflowId, options) {
|
|
|
4155
4257
|
},
|
|
4156
4258
|
[fetchWithAuth]
|
|
4157
4259
|
);
|
|
4158
|
-
const cancelRun =
|
|
4260
|
+
const cancelRun = useCallback19(
|
|
4159
4261
|
async (runId) => {
|
|
4160
4262
|
if (!runId) throw new Error("Run ID is required");
|
|
4161
4263
|
const res = await fetchWithAuth(`/workflows/runs/${runId}/cancel`, {
|
|
@@ -4170,7 +4272,7 @@ function useWorkflowRuns(workflowId, options) {
|
|
|
4170
4272
|
},
|
|
4171
4273
|
[fetchWithAuth]
|
|
4172
4274
|
);
|
|
4173
|
-
|
|
4275
|
+
useEffect18(() => {
|
|
4174
4276
|
if (autoFetch && workflowId) {
|
|
4175
4277
|
void fetchRuns();
|
|
4176
4278
|
}
|
|
@@ -4224,6 +4326,7 @@ export {
|
|
|
4224
4326
|
useWorkflow,
|
|
4225
4327
|
useWorkflowRuns,
|
|
4226
4328
|
useWorkflowStream,
|
|
4227
|
-
useWorkflows
|
|
4329
|
+
useWorkflows,
|
|
4330
|
+
useWorkspaceFiles
|
|
4228
4331
|
};
|
|
4229
4332
|
//# sourceMappingURL=index.js.map
|