@personaai/react 0.14.0 → 0.16.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 +301 -184
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +46 -6
- package/dist/index.d.ts +46 -6
- package/dist/index.js +286 -170
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1666,7 +1666,8 @@ function useMemory(autoFetch = true) {
|
|
|
1666
1666
|
const { fetchWithAuth } = usePersonaContext();
|
|
1667
1667
|
const [memory, setMemory] = useState3({
|
|
1668
1668
|
userFiles: [],
|
|
1669
|
-
agentMemories: []
|
|
1669
|
+
agentMemories: [],
|
|
1670
|
+
agentWorkspaces: []
|
|
1670
1671
|
});
|
|
1671
1672
|
const [isLoading, setIsLoading] = useState3(false);
|
|
1672
1673
|
const [error, setError] = useState3(null);
|
|
@@ -1684,7 +1685,7 @@ function useMemory(autoFetch = true) {
|
|
|
1684
1685
|
} catch (err) {
|
|
1685
1686
|
const errorObj = err instanceof Error ? err : new Error(String(err));
|
|
1686
1687
|
setError(errorObj);
|
|
1687
|
-
return { userFiles: [], agentMemories: [] };
|
|
1688
|
+
return { userFiles: [], agentMemories: [], agentWorkspaces: [] };
|
|
1688
1689
|
} finally {
|
|
1689
1690
|
setIsLoading(false);
|
|
1690
1691
|
}
|
|
@@ -1889,8 +1890,122 @@ function useThreads(autoFetch = true) {
|
|
|
1889
1890
|
};
|
|
1890
1891
|
}
|
|
1891
1892
|
|
|
1893
|
+
// src/hooks/useWorkspaceFiles.ts
|
|
1894
|
+
import { useCallback as useCallback5, useEffect as useEffect5, useState as useState5 } from "react";
|
|
1895
|
+
function toWorkspaceFile(file) {
|
|
1896
|
+
return {
|
|
1897
|
+
content: file.content,
|
|
1898
|
+
size: file.content.length,
|
|
1899
|
+
createdAt: file.createdAt ?? null,
|
|
1900
|
+
modifiedAt: file.updatedAt ?? null
|
|
1901
|
+
};
|
|
1902
|
+
}
|
|
1903
|
+
function useWorkspaceFiles(agentId, autoFetch = true) {
|
|
1904
|
+
const { fetchWithAuth } = usePersonaContext();
|
|
1905
|
+
const [files, setFiles] = useState5({});
|
|
1906
|
+
const [isLoading, setIsLoading] = useState5(false);
|
|
1907
|
+
const [isSaving, setIsSaving] = useState5(false);
|
|
1908
|
+
const [error, setError] = useState5(null);
|
|
1909
|
+
const fetchFiles = useCallback5(async () => {
|
|
1910
|
+
if (!agentId) return {};
|
|
1911
|
+
setIsLoading(true);
|
|
1912
|
+
setError(null);
|
|
1913
|
+
try {
|
|
1914
|
+
const res = await fetchWithAuth("/memory");
|
|
1915
|
+
if (!res.ok) throw new Error(`Failed to list workspace files: ${res.statusText}`);
|
|
1916
|
+
const data = await res.json();
|
|
1917
|
+
const body = data?.data ?? data;
|
|
1918
|
+
const group = (body?.agentWorkspaces ?? []).find(
|
|
1919
|
+
(g) => g.agentId === agentId
|
|
1920
|
+
);
|
|
1921
|
+
const normalized = {};
|
|
1922
|
+
for (const file of group?.files ?? []) {
|
|
1923
|
+
normalized[file.path] = toWorkspaceFile(file);
|
|
1924
|
+
}
|
|
1925
|
+
setFiles(normalized);
|
|
1926
|
+
return normalized;
|
|
1927
|
+
} catch (err) {
|
|
1928
|
+
const errorObj = err instanceof Error ? err : new Error(String(err));
|
|
1929
|
+
setError(errorObj);
|
|
1930
|
+
return {};
|
|
1931
|
+
} finally {
|
|
1932
|
+
setIsLoading(false);
|
|
1933
|
+
}
|
|
1934
|
+
}, [fetchWithAuth, agentId]);
|
|
1935
|
+
const getFile = useCallback5(
|
|
1936
|
+
async (path) => {
|
|
1937
|
+
if (!agentId) throw new Error("useWorkspaceFiles: no agentId set");
|
|
1938
|
+
const query = new URLSearchParams({ path, scope: "workspace", agentId });
|
|
1939
|
+
const res = await fetchWithAuth(`/memory/file?${query.toString()}`);
|
|
1940
|
+
if (!res.ok) throw new Error(`Failed to read workspace file: ${res.statusText}`);
|
|
1941
|
+
const data = await res.json();
|
|
1942
|
+
const raw = data?.data ?? data;
|
|
1943
|
+
return toWorkspaceFile(raw);
|
|
1944
|
+
},
|
|
1945
|
+
[fetchWithAuth, agentId]
|
|
1946
|
+
);
|
|
1947
|
+
const writeFile = useCallback5(
|
|
1948
|
+
async (path, content) => {
|
|
1949
|
+
if (!agentId) throw new Error("useWorkspaceFiles: no agentId set");
|
|
1950
|
+
setIsSaving(true);
|
|
1951
|
+
setError(null);
|
|
1952
|
+
try {
|
|
1953
|
+
const res = await fetchWithAuth("/memory/file", {
|
|
1954
|
+
method: "PUT",
|
|
1955
|
+
headers: { "Content-Type": "application/json" },
|
|
1956
|
+
body: JSON.stringify({ path, content, scope: "workspace", agentId })
|
|
1957
|
+
});
|
|
1958
|
+
if (!res.ok) throw new Error(`Failed to write workspace file: ${res.statusText}`);
|
|
1959
|
+
const data = await res.json();
|
|
1960
|
+
const raw = data?.data ?? data;
|
|
1961
|
+
const file = toWorkspaceFile(raw);
|
|
1962
|
+
setFiles((prev) => ({ ...prev, [path]: file }));
|
|
1963
|
+
return file;
|
|
1964
|
+
} catch (err) {
|
|
1965
|
+
const errorObj = err instanceof Error ? err : new Error(String(err));
|
|
1966
|
+
setError(errorObj);
|
|
1967
|
+
throw errorObj;
|
|
1968
|
+
} finally {
|
|
1969
|
+
setIsSaving(false);
|
|
1970
|
+
}
|
|
1971
|
+
},
|
|
1972
|
+
[fetchWithAuth, agentId]
|
|
1973
|
+
);
|
|
1974
|
+
const deleteFile = useCallback5(
|
|
1975
|
+
async (path) => {
|
|
1976
|
+
if (!agentId) throw new Error("useWorkspaceFiles: no agentId set");
|
|
1977
|
+
const query = new URLSearchParams({ path, scope: "workspace", agentId });
|
|
1978
|
+
const res = await fetchWithAuth(`/memory/file?${query.toString()}`, { method: "DELETE" });
|
|
1979
|
+
if (!res.ok) throw new Error(`Failed to delete workspace file: ${res.statusText}`);
|
|
1980
|
+
setFiles((prev) => {
|
|
1981
|
+
const next = { ...prev };
|
|
1982
|
+
delete next[path];
|
|
1983
|
+
return next;
|
|
1984
|
+
});
|
|
1985
|
+
},
|
|
1986
|
+
[fetchWithAuth, agentId]
|
|
1987
|
+
);
|
|
1988
|
+
useEffect5(() => {
|
|
1989
|
+
if (autoFetch && agentId) {
|
|
1990
|
+
void fetchFiles();
|
|
1991
|
+
} else if (!agentId) {
|
|
1992
|
+
setFiles({});
|
|
1993
|
+
}
|
|
1994
|
+
}, [autoFetch, agentId, fetchFiles]);
|
|
1995
|
+
return {
|
|
1996
|
+
files,
|
|
1997
|
+
isLoading,
|
|
1998
|
+
isSaving,
|
|
1999
|
+
error,
|
|
2000
|
+
refetch: fetchFiles,
|
|
2001
|
+
getFile,
|
|
2002
|
+
writeFile,
|
|
2003
|
+
deleteFile
|
|
2004
|
+
};
|
|
2005
|
+
}
|
|
2006
|
+
|
|
1892
2007
|
// src/hooks/useVoice.ts
|
|
1893
|
-
import { useCallback as
|
|
2008
|
+
import { useCallback as useCallback6, useEffect as useEffect6, useMemo as useMemo4, useRef as useRef3, useState as useState6 } from "react";
|
|
1894
2009
|
|
|
1895
2010
|
// src/hooks/voiceWorklets.ts
|
|
1896
2011
|
var RECORDER_WORKLET_SOURCE = `
|
|
@@ -1998,17 +2113,17 @@ function useVoice(options = {}) {
|
|
|
1998
2113
|
const threadId = options.threadId;
|
|
1999
2114
|
const contextOverride = options.contextOverride;
|
|
2000
2115
|
const context = options.context;
|
|
2001
|
-
const [state, setState] =
|
|
2002
|
-
const [isMuted, setIsMuted] =
|
|
2003
|
-
const [transcript, setTranscript] =
|
|
2116
|
+
const [state, setState] = useState6("idle");
|
|
2117
|
+
const [isMuted, setIsMuted] = useState6(false);
|
|
2118
|
+
const [transcript, setTranscript] = useState6(
|
|
2004
2119
|
[]
|
|
2005
2120
|
);
|
|
2006
|
-
const [partial, setPartial] =
|
|
2121
|
+
const [partial, setPartial] = useState6(
|
|
2007
2122
|
null
|
|
2008
2123
|
);
|
|
2009
|
-
const [toolCalls, setToolCalls] =
|
|
2010
|
-
const [error, setError] =
|
|
2011
|
-
const [endReason, setEndReason] =
|
|
2124
|
+
const [toolCalls, setToolCalls] = useState6([]);
|
|
2125
|
+
const [error, setError] = useState6(null);
|
|
2126
|
+
const [endReason, setEndReason] = useState6(
|
|
2012
2127
|
null
|
|
2013
2128
|
);
|
|
2014
2129
|
const wsRef = useRef3(null);
|
|
@@ -2022,13 +2137,13 @@ function useVoice(options = {}) {
|
|
|
2022
2137
|
const lastFinalTurnRef = useRef3(
|
|
2023
2138
|
null
|
|
2024
2139
|
);
|
|
2025
|
-
|
|
2140
|
+
useEffect6(() => {
|
|
2026
2141
|
mountedRef.current = true;
|
|
2027
2142
|
return () => {
|
|
2028
2143
|
mountedRef.current = false;
|
|
2029
2144
|
};
|
|
2030
2145
|
}, []);
|
|
2031
|
-
const teardownAudio =
|
|
2146
|
+
const teardownAudio = useCallback6(() => {
|
|
2032
2147
|
try {
|
|
2033
2148
|
streamRef.current?.getTracks().forEach((track) => track.stop());
|
|
2034
2149
|
} catch {
|
|
@@ -2055,7 +2170,7 @@ function useVoice(options = {}) {
|
|
|
2055
2170
|
}
|
|
2056
2171
|
outputCtxRef.current = null;
|
|
2057
2172
|
}, []);
|
|
2058
|
-
const stop =
|
|
2173
|
+
const stop = useCallback6(() => {
|
|
2059
2174
|
voiceLogger.debug("stop() called");
|
|
2060
2175
|
try {
|
|
2061
2176
|
wsRef.current?.close(1e3, "client_stop");
|
|
@@ -2065,8 +2180,8 @@ function useVoice(options = {}) {
|
|
|
2065
2180
|
teardownAudio();
|
|
2066
2181
|
if (mountedRef.current) setState("idle");
|
|
2067
2182
|
}, [teardownAudio, voiceLogger]);
|
|
2068
|
-
|
|
2069
|
-
const startCapture =
|
|
2183
|
+
useEffect6(() => stop, [stop]);
|
|
2184
|
+
const startCapture = useCallback6(async (inputSampleRate) => {
|
|
2070
2185
|
const stream = await navigator.mediaDevices.getUserMedia({
|
|
2071
2186
|
audio: {
|
|
2072
2187
|
echoCancellation: true,
|
|
@@ -2092,7 +2207,7 @@ function useVoice(options = {}) {
|
|
|
2092
2207
|
recorderNodeRef.current = recorderNode;
|
|
2093
2208
|
source.connect(recorderNode);
|
|
2094
2209
|
}, []);
|
|
2095
|
-
const setupPlayback =
|
|
2210
|
+
const setupPlayback = useCallback6(async (outputSampleRate) => {
|
|
2096
2211
|
const outputCtx = new AudioContext({ sampleRate: outputSampleRate });
|
|
2097
2212
|
outputCtxRef.current = outputCtx;
|
|
2098
2213
|
await outputCtx.audioWorklet.addModule(playerWorkletUrl());
|
|
@@ -2100,7 +2215,7 @@ function useVoice(options = {}) {
|
|
|
2100
2215
|
playerNode.connect(outputCtx.destination);
|
|
2101
2216
|
playerNodeRef.current = playerNode;
|
|
2102
2217
|
}, []);
|
|
2103
|
-
const upsertToolCall =
|
|
2218
|
+
const upsertToolCall = useCallback6(
|
|
2104
2219
|
(id, patch) => {
|
|
2105
2220
|
setToolCalls((prev) => {
|
|
2106
2221
|
const idx = prev.findIndex((t) => t.id === id);
|
|
@@ -2112,7 +2227,7 @@ function useVoice(options = {}) {
|
|
|
2112
2227
|
},
|
|
2113
2228
|
[]
|
|
2114
2229
|
);
|
|
2115
|
-
const handleTranscript =
|
|
2230
|
+
const handleTranscript = useCallback6((value) => {
|
|
2116
2231
|
const { speaker, text, isFinal, turnSeq } = value;
|
|
2117
2232
|
if (!isFinal) {
|
|
2118
2233
|
setPartial({ id: "partial", speaker, text });
|
|
@@ -2135,7 +2250,7 @@ function useVoice(options = {}) {
|
|
|
2135
2250
|
});
|
|
2136
2251
|
lastFinalTurnRef.current = { speaker, turnSeq };
|
|
2137
2252
|
}, []);
|
|
2138
|
-
const handleCustomEvent =
|
|
2253
|
+
const handleCustomEvent = useCallback6(
|
|
2139
2254
|
(name, value) => {
|
|
2140
2255
|
switch (name) {
|
|
2141
2256
|
case "voice_session_ready":
|
|
@@ -2193,7 +2308,7 @@ function useVoice(options = {}) {
|
|
|
2193
2308
|
},
|
|
2194
2309
|
[handleTranscript, setupPlayback, startCapture, teardownAudio, voiceLogger]
|
|
2195
2310
|
);
|
|
2196
|
-
const handleMessage =
|
|
2311
|
+
const handleMessage = useCallback6(
|
|
2197
2312
|
(event) => {
|
|
2198
2313
|
if (typeof event.data !== "string") {
|
|
2199
2314
|
const buf = event.data;
|
|
@@ -2251,7 +2366,7 @@ function useVoice(options = {}) {
|
|
|
2251
2366
|
},
|
|
2252
2367
|
[handleCustomEvent, upsertToolCall, voiceLogger]
|
|
2253
2368
|
);
|
|
2254
|
-
const start =
|
|
2369
|
+
const start = useCallback6(async () => {
|
|
2255
2370
|
if (!agentId) {
|
|
2256
2371
|
const err = new Error(
|
|
2257
2372
|
"useVoice: no agentId provided and no defaultAgentId set on PersonaProvider"
|
|
@@ -2318,17 +2433,17 @@ function useVoice(options = {}) {
|
|
|
2318
2433
|
teardownAudio();
|
|
2319
2434
|
}
|
|
2320
2435
|
}, [agentId, threadId, contextOverride, context, fetchWithAuth, handleMessage, teardownAudio, voiceLogger]);
|
|
2321
|
-
const mute =
|
|
2436
|
+
const mute = useCallback6((muted) => {
|
|
2322
2437
|
setIsMuted(muted);
|
|
2323
2438
|
streamRef.current?.getAudioTracks().forEach((track) => {
|
|
2324
2439
|
track.enabled = !muted;
|
|
2325
2440
|
});
|
|
2326
2441
|
}, []);
|
|
2327
|
-
const sendText =
|
|
2442
|
+
const sendText = useCallback6((text) => {
|
|
2328
2443
|
if (!text?.trim() || wsRef.current?.readyState !== WebSocket.OPEN) return;
|
|
2329
2444
|
wsRef.current.send(JSON.stringify({ type: "voice.text", text }));
|
|
2330
2445
|
}, []);
|
|
2331
|
-
const updateContext =
|
|
2446
|
+
const updateContext = useCallback6((newContext) => {
|
|
2332
2447
|
if (wsRef.current?.readyState !== WebSocket.OPEN) return;
|
|
2333
2448
|
wsRef.current.send(JSON.stringify({ type: "voice.context", context: newContext }));
|
|
2334
2449
|
}, []);
|
|
@@ -2349,14 +2464,14 @@ function useVoice(options = {}) {
|
|
|
2349
2464
|
}
|
|
2350
2465
|
|
|
2351
2466
|
// src/hooks/useFiles.ts
|
|
2352
|
-
import { useCallback as
|
|
2467
|
+
import { useCallback as useCallback7, useEffect as useEffect7, useState as useState7 } from "react";
|
|
2353
2468
|
function useFiles(autoFetch = true) {
|
|
2354
2469
|
const { fetchWithAuth } = usePersonaContext();
|
|
2355
|
-
const [files, setFiles] =
|
|
2356
|
-
const [isLoading, setIsLoading] =
|
|
2357
|
-
const [isUploading, setIsUploading] =
|
|
2358
|
-
const [error, setError] =
|
|
2359
|
-
const fetchFiles =
|
|
2470
|
+
const [files, setFiles] = useState7([]);
|
|
2471
|
+
const [isLoading, setIsLoading] = useState7(false);
|
|
2472
|
+
const [isUploading, setIsUploading] = useState7(false);
|
|
2473
|
+
const [error, setError] = useState7(null);
|
|
2474
|
+
const fetchFiles = useCallback7(async () => {
|
|
2360
2475
|
setIsLoading(true);
|
|
2361
2476
|
setError(null);
|
|
2362
2477
|
try {
|
|
@@ -2374,7 +2489,7 @@ function useFiles(autoFetch = true) {
|
|
|
2374
2489
|
setIsLoading(false);
|
|
2375
2490
|
}
|
|
2376
2491
|
}, [fetchWithAuth]);
|
|
2377
|
-
const uploadFile =
|
|
2492
|
+
const uploadFile = useCallback7(
|
|
2378
2493
|
async (fileOrFormData) => {
|
|
2379
2494
|
setIsUploading(true);
|
|
2380
2495
|
setError(null);
|
|
@@ -2407,7 +2522,7 @@ function useFiles(autoFetch = true) {
|
|
|
2407
2522
|
},
|
|
2408
2523
|
[fetchWithAuth, fetchFiles]
|
|
2409
2524
|
);
|
|
2410
|
-
const deleteFile =
|
|
2525
|
+
const deleteFile = useCallback7(
|
|
2411
2526
|
async (fileId) => {
|
|
2412
2527
|
const res = await fetchWithAuth(`/files/${fileId}`, { method: "DELETE" });
|
|
2413
2528
|
if (!res.ok) throw new Error(`Failed to delete file: ${res.statusText}`);
|
|
@@ -2415,7 +2530,7 @@ function useFiles(autoFetch = true) {
|
|
|
2415
2530
|
},
|
|
2416
2531
|
[fetchWithAuth]
|
|
2417
2532
|
);
|
|
2418
|
-
const bulkDeleteFiles =
|
|
2533
|
+
const bulkDeleteFiles = useCallback7(
|
|
2419
2534
|
async (fileIds) => {
|
|
2420
2535
|
const res = await fetchWithAuth("/files/bulk-delete", {
|
|
2421
2536
|
method: "POST",
|
|
@@ -2430,10 +2545,10 @@ function useFiles(autoFetch = true) {
|
|
|
2430
2545
|
},
|
|
2431
2546
|
[fetchWithAuth]
|
|
2432
2547
|
);
|
|
2433
|
-
const getDownloadUrl =
|
|
2548
|
+
const getDownloadUrl = useCallback7((fileId) => {
|
|
2434
2549
|
return `/files/${fileId}`;
|
|
2435
2550
|
}, []);
|
|
2436
|
-
|
|
2551
|
+
useEffect7(() => {
|
|
2437
2552
|
if (autoFetch) {
|
|
2438
2553
|
void fetchFiles();
|
|
2439
2554
|
}
|
|
@@ -2452,21 +2567,21 @@ function useFiles(autoFetch = true) {
|
|
|
2452
2567
|
}
|
|
2453
2568
|
|
|
2454
2569
|
// src/hooks/useAgents.ts
|
|
2455
|
-
import { useCallback as
|
|
2570
|
+
import { useCallback as useCallback8, useEffect as useEffect8, useState as useState8 } from "react";
|
|
2456
2571
|
function useAgents(options = true) {
|
|
2457
2572
|
const opts = typeof options === "boolean" ? { autoFetch: options } : options;
|
|
2458
2573
|
const { autoFetch = true, page, limit, search, category, scope } = opts;
|
|
2459
2574
|
const { fetchWithAuth } = usePersonaContext();
|
|
2460
|
-
const [agents, setAgents] =
|
|
2461
|
-
const [pagination, setPagination] =
|
|
2575
|
+
const [agents, setAgents] = useState8([]);
|
|
2576
|
+
const [pagination, setPagination] = useState8({
|
|
2462
2577
|
total: 0,
|
|
2463
2578
|
page: page ?? 1,
|
|
2464
2579
|
limit: limit ?? 20,
|
|
2465
2580
|
pages: 0
|
|
2466
2581
|
});
|
|
2467
|
-
const [isLoading, setIsLoading] =
|
|
2468
|
-
const [error, setError] =
|
|
2469
|
-
const fetchAgents =
|
|
2582
|
+
const [isLoading, setIsLoading] = useState8(false);
|
|
2583
|
+
const [error, setError] = useState8(null);
|
|
2584
|
+
const fetchAgents = useCallback8(async () => {
|
|
2470
2585
|
setIsLoading(true);
|
|
2471
2586
|
setError(null);
|
|
2472
2587
|
try {
|
|
@@ -2494,7 +2609,7 @@ function useAgents(options = true) {
|
|
|
2494
2609
|
setIsLoading(false);
|
|
2495
2610
|
}
|
|
2496
2611
|
}, [fetchWithAuth, page, limit, search, category, scope]);
|
|
2497
|
-
const getAgent =
|
|
2612
|
+
const getAgent = useCallback8(
|
|
2498
2613
|
async (agentId) => {
|
|
2499
2614
|
const res = await fetchWithAuth(`/agents/${agentId}`);
|
|
2500
2615
|
if (!res.ok) throw new Error(`Failed to fetch agent: ${res.statusText}`);
|
|
@@ -2502,7 +2617,7 @@ function useAgents(options = true) {
|
|
|
2502
2617
|
},
|
|
2503
2618
|
[fetchWithAuth]
|
|
2504
2619
|
);
|
|
2505
|
-
const createAgent =
|
|
2620
|
+
const createAgent = useCallback8(
|
|
2506
2621
|
async (input) => {
|
|
2507
2622
|
setError(null);
|
|
2508
2623
|
try {
|
|
@@ -2526,7 +2641,7 @@ function useAgents(options = true) {
|
|
|
2526
2641
|
},
|
|
2527
2642
|
[fetchWithAuth]
|
|
2528
2643
|
);
|
|
2529
|
-
const updateAgent =
|
|
2644
|
+
const updateAgent = useCallback8(
|
|
2530
2645
|
async (agentId, input) => {
|
|
2531
2646
|
setError(null);
|
|
2532
2647
|
try {
|
|
@@ -2550,7 +2665,7 @@ function useAgents(options = true) {
|
|
|
2550
2665
|
},
|
|
2551
2666
|
[fetchWithAuth]
|
|
2552
2667
|
);
|
|
2553
|
-
const deleteAgent =
|
|
2668
|
+
const deleteAgent = useCallback8(
|
|
2554
2669
|
async (agentId) => {
|
|
2555
2670
|
setError(null);
|
|
2556
2671
|
try {
|
|
@@ -2568,7 +2683,7 @@ function useAgents(options = true) {
|
|
|
2568
2683
|
},
|
|
2569
2684
|
[fetchWithAuth]
|
|
2570
2685
|
);
|
|
2571
|
-
const bulkDeleteAgents =
|
|
2686
|
+
const bulkDeleteAgents = useCallback8(
|
|
2572
2687
|
async (ids) => {
|
|
2573
2688
|
setError(null);
|
|
2574
2689
|
try {
|
|
@@ -2593,7 +2708,7 @@ function useAgents(options = true) {
|
|
|
2593
2708
|
},
|
|
2594
2709
|
[fetchWithAuth]
|
|
2595
2710
|
);
|
|
2596
|
-
|
|
2711
|
+
useEffect8(() => {
|
|
2597
2712
|
if (autoFetch) void fetchAgents();
|
|
2598
2713
|
}, [autoFetch, fetchAgents]);
|
|
2599
2714
|
return {
|
|
@@ -2611,13 +2726,13 @@ function useAgents(options = true) {
|
|
|
2611
2726
|
}
|
|
2612
2727
|
|
|
2613
2728
|
// src/hooks/useConnection.ts
|
|
2614
|
-
import { useCallback as
|
|
2729
|
+
import { useCallback as useCallback9, useEffect as useEffect9, useState as useState9 } from "react";
|
|
2615
2730
|
function useConnection(autoCheck = true) {
|
|
2616
2731
|
const { fetchWithAuth } = usePersonaContext();
|
|
2617
|
-
const [health, setHealth] =
|
|
2618
|
-
const [isConnected, setIsConnected] =
|
|
2619
|
-
const [isLoading, setIsLoading] =
|
|
2620
|
-
const checkHealth =
|
|
2732
|
+
const [health, setHealth] = useState9(null);
|
|
2733
|
+
const [isConnected, setIsConnected] = useState9(false);
|
|
2734
|
+
const [isLoading, setIsLoading] = useState9(false);
|
|
2735
|
+
const checkHealth = useCallback9(async () => {
|
|
2621
2736
|
setIsLoading(true);
|
|
2622
2737
|
try {
|
|
2623
2738
|
const res = await fetchWithAuth("/health");
|
|
@@ -2636,7 +2751,7 @@ function useConnection(autoCheck = true) {
|
|
|
2636
2751
|
setIsLoading(false);
|
|
2637
2752
|
}
|
|
2638
2753
|
}, [fetchWithAuth]);
|
|
2639
|
-
|
|
2754
|
+
useEffect9(() => {
|
|
2640
2755
|
if (autoCheck) {
|
|
2641
2756
|
void checkHealth();
|
|
2642
2757
|
}
|
|
@@ -2650,15 +2765,15 @@ function useConnection(autoCheck = true) {
|
|
|
2650
2765
|
}
|
|
2651
2766
|
|
|
2652
2767
|
// src/hooks/useMcpConnections.ts
|
|
2653
|
-
import { useCallback as
|
|
2768
|
+
import { useCallback as useCallback10, useEffect as useEffect10, useState as useState10 } from "react";
|
|
2654
2769
|
function useMcpConnections(options = {}) {
|
|
2655
2770
|
const { defaultAgentId, fetchWithAuth } = usePersonaContext();
|
|
2656
2771
|
const agentId = options.agentId ?? defaultAgentId;
|
|
2657
2772
|
const autoFetch = options.autoFetch ?? true;
|
|
2658
|
-
const [connections, setConnections] =
|
|
2659
|
-
const [isLoading, setIsLoading] =
|
|
2660
|
-
const [error, setError] =
|
|
2661
|
-
const fetchConnections =
|
|
2773
|
+
const [connections, setConnections] = useState10([]);
|
|
2774
|
+
const [isLoading, setIsLoading] = useState10(false);
|
|
2775
|
+
const [error, setError] = useState10(null);
|
|
2776
|
+
const fetchConnections = useCallback10(async () => {
|
|
2662
2777
|
if (!agentId) return [];
|
|
2663
2778
|
setIsLoading(true);
|
|
2664
2779
|
setError(null);
|
|
@@ -2682,8 +2797,8 @@ function useMcpConnections(options = {}) {
|
|
|
2682
2797
|
setIsLoading(false);
|
|
2683
2798
|
}
|
|
2684
2799
|
}, [agentId, fetchWithAuth, options.returnTo]);
|
|
2685
|
-
const [isDisconnecting, setIsDisconnecting] =
|
|
2686
|
-
const disconnect =
|
|
2800
|
+
const [isDisconnecting, setIsDisconnecting] = useState10(false);
|
|
2801
|
+
const disconnect = useCallback10(
|
|
2687
2802
|
async (mcpId) => {
|
|
2688
2803
|
setIsDisconnecting(true);
|
|
2689
2804
|
setError(null);
|
|
@@ -2709,7 +2824,7 @@ function useMcpConnections(options = {}) {
|
|
|
2709
2824
|
},
|
|
2710
2825
|
[fetchWithAuth, fetchConnections]
|
|
2711
2826
|
);
|
|
2712
|
-
|
|
2827
|
+
useEffect10(() => {
|
|
2713
2828
|
if (autoFetch) void fetchConnections();
|
|
2714
2829
|
}, [autoFetch, fetchConnections]);
|
|
2715
2830
|
return {
|
|
@@ -2725,11 +2840,11 @@ function useMcpConnections(options = {}) {
|
|
|
2725
2840
|
}
|
|
2726
2841
|
|
|
2727
2842
|
// src/hooks/useMcp.ts
|
|
2728
|
-
import { useCallback as
|
|
2843
|
+
import { useCallback as useCallback11 } from "react";
|
|
2729
2844
|
function useMcp(options = {}) {
|
|
2730
2845
|
const { fetchWithAuth } = usePersonaContext();
|
|
2731
2846
|
const defaultMcpId = options.mcpId;
|
|
2732
|
-
const readResource =
|
|
2847
|
+
const readResource = useCallback11(
|
|
2733
2848
|
async (uri, mcpId) => {
|
|
2734
2849
|
const id = mcpId ?? defaultMcpId;
|
|
2735
2850
|
if (!id) throw new Error("MCP server ID is required to read resource");
|
|
@@ -2743,7 +2858,7 @@ function useMcp(options = {}) {
|
|
|
2743
2858
|
},
|
|
2744
2859
|
[fetchWithAuth, defaultMcpId]
|
|
2745
2860
|
);
|
|
2746
|
-
const callTool =
|
|
2861
|
+
const callTool = useCallback11(
|
|
2747
2862
|
async (name, args, mcpId) => {
|
|
2748
2863
|
const id = mcpId ?? defaultMcpId;
|
|
2749
2864
|
if (!id) throw new Error("MCP server ID is required to call tool");
|
|
@@ -2766,20 +2881,20 @@ function useMcp(options = {}) {
|
|
|
2766
2881
|
}
|
|
2767
2882
|
|
|
2768
2883
|
// src/hooks/useSkills.ts
|
|
2769
|
-
import { useCallback as
|
|
2884
|
+
import { useCallback as useCallback12, useEffect as useEffect11, useState as useState11 } from "react";
|
|
2770
2885
|
function useSkills(options = {}) {
|
|
2771
2886
|
const { autoFetch = true, page, limit, search, scope } = options;
|
|
2772
2887
|
const { fetchWithAuth } = usePersonaContext();
|
|
2773
|
-
const [skills, setSkills] =
|
|
2774
|
-
const [pagination, setPagination] =
|
|
2888
|
+
const [skills, setSkills] = useState11([]);
|
|
2889
|
+
const [pagination, setPagination] = useState11({
|
|
2775
2890
|
total: 0,
|
|
2776
2891
|
page: page ?? 1,
|
|
2777
2892
|
limit: limit ?? 20,
|
|
2778
2893
|
pages: 0
|
|
2779
2894
|
});
|
|
2780
|
-
const [isLoading, setIsLoading] =
|
|
2781
|
-
const [error, setError] =
|
|
2782
|
-
const fetchSkills =
|
|
2895
|
+
const [isLoading, setIsLoading] = useState11(false);
|
|
2896
|
+
const [error, setError] = useState11(null);
|
|
2897
|
+
const fetchSkills = useCallback12(async () => {
|
|
2783
2898
|
setIsLoading(true);
|
|
2784
2899
|
setError(null);
|
|
2785
2900
|
try {
|
|
@@ -2806,7 +2921,7 @@ function useSkills(options = {}) {
|
|
|
2806
2921
|
setIsLoading(false);
|
|
2807
2922
|
}
|
|
2808
2923
|
}, [fetchWithAuth, page, limit, search, scope]);
|
|
2809
|
-
const getSkill =
|
|
2924
|
+
const getSkill = useCallback12(
|
|
2810
2925
|
async (skillId) => {
|
|
2811
2926
|
const res = await fetchWithAuth(`/skills/${skillId}`);
|
|
2812
2927
|
if (!res.ok) throw new Error(`Failed to fetch skill: ${res.statusText}`);
|
|
@@ -2814,7 +2929,7 @@ function useSkills(options = {}) {
|
|
|
2814
2929
|
},
|
|
2815
2930
|
[fetchWithAuth]
|
|
2816
2931
|
);
|
|
2817
|
-
const createSkill =
|
|
2932
|
+
const createSkill = useCallback12(
|
|
2818
2933
|
async (input) => {
|
|
2819
2934
|
setError(null);
|
|
2820
2935
|
try {
|
|
@@ -2838,7 +2953,7 @@ function useSkills(options = {}) {
|
|
|
2838
2953
|
},
|
|
2839
2954
|
[fetchWithAuth]
|
|
2840
2955
|
);
|
|
2841
|
-
const updateSkill =
|
|
2956
|
+
const updateSkill = useCallback12(
|
|
2842
2957
|
async (skillId, input) => {
|
|
2843
2958
|
setError(null);
|
|
2844
2959
|
try {
|
|
@@ -2862,7 +2977,7 @@ function useSkills(options = {}) {
|
|
|
2862
2977
|
},
|
|
2863
2978
|
[fetchWithAuth]
|
|
2864
2979
|
);
|
|
2865
|
-
const deleteSkill =
|
|
2980
|
+
const deleteSkill = useCallback12(
|
|
2866
2981
|
async (skillId) => {
|
|
2867
2982
|
setError(null);
|
|
2868
2983
|
try {
|
|
@@ -2880,7 +2995,7 @@ function useSkills(options = {}) {
|
|
|
2880
2995
|
},
|
|
2881
2996
|
[fetchWithAuth]
|
|
2882
2997
|
);
|
|
2883
|
-
const bulkDeleteSkills =
|
|
2998
|
+
const bulkDeleteSkills = useCallback12(
|
|
2884
2999
|
async (ids) => {
|
|
2885
3000
|
setError(null);
|
|
2886
3001
|
try {
|
|
@@ -2905,7 +3020,7 @@ function useSkills(options = {}) {
|
|
|
2905
3020
|
},
|
|
2906
3021
|
[fetchWithAuth]
|
|
2907
3022
|
);
|
|
2908
|
-
const getSkillUsage =
|
|
3023
|
+
const getSkillUsage = useCallback12(
|
|
2909
3024
|
async (skillId) => {
|
|
2910
3025
|
const res = await fetchWithAuth(`/skills/${skillId}/usage`);
|
|
2911
3026
|
if (!res.ok) throw new Error(`Failed to fetch skill usage: ${res.statusText}`);
|
|
@@ -2913,7 +3028,7 @@ function useSkills(options = {}) {
|
|
|
2913
3028
|
},
|
|
2914
3029
|
[fetchWithAuth]
|
|
2915
3030
|
);
|
|
2916
|
-
|
|
3031
|
+
useEffect11(() => {
|
|
2917
3032
|
if (autoFetch) void fetchSkills();
|
|
2918
3033
|
}, [autoFetch, fetchSkills]);
|
|
2919
3034
|
return {
|
|
@@ -2932,20 +3047,20 @@ function useSkills(options = {}) {
|
|
|
2932
3047
|
}
|
|
2933
3048
|
|
|
2934
3049
|
// src/hooks/useRcpSources.ts
|
|
2935
|
-
import { useCallback as
|
|
3050
|
+
import { useCallback as useCallback13, useEffect as useEffect12, useState as useState12 } from "react";
|
|
2936
3051
|
function useRcpSources(options = {}) {
|
|
2937
3052
|
const { autoFetch = true, page, limit, search } = options;
|
|
2938
3053
|
const { fetchWithAuth } = usePersonaContext();
|
|
2939
|
-
const [rcpSources, setRcpSources] =
|
|
2940
|
-
const [pagination, setPagination] =
|
|
3054
|
+
const [rcpSources, setRcpSources] = useState12([]);
|
|
3055
|
+
const [pagination, setPagination] = useState12({
|
|
2941
3056
|
total: 0,
|
|
2942
3057
|
page: page ?? 1,
|
|
2943
3058
|
limit: limit ?? 20,
|
|
2944
3059
|
pages: 0
|
|
2945
3060
|
});
|
|
2946
|
-
const [isLoading, setIsLoading] =
|
|
2947
|
-
const [error, setError] =
|
|
2948
|
-
const fetchRcpSources =
|
|
3061
|
+
const [isLoading, setIsLoading] = useState12(false);
|
|
3062
|
+
const [error, setError] = useState12(null);
|
|
3063
|
+
const fetchRcpSources = useCallback13(async () => {
|
|
2949
3064
|
setIsLoading(true);
|
|
2950
3065
|
setError(null);
|
|
2951
3066
|
try {
|
|
@@ -2971,7 +3086,7 @@ function useRcpSources(options = {}) {
|
|
|
2971
3086
|
setIsLoading(false);
|
|
2972
3087
|
}
|
|
2973
3088
|
}, [fetchWithAuth, page, limit, search]);
|
|
2974
|
-
const getRcpSource =
|
|
3089
|
+
const getRcpSource = useCallback13(
|
|
2975
3090
|
async (sourceId) => {
|
|
2976
3091
|
const res = await fetchWithAuth(`/rcp-sources/${sourceId}`);
|
|
2977
3092
|
if (!res.ok) throw new Error(`Failed to fetch RCP source: ${res.statusText}`);
|
|
@@ -2979,7 +3094,7 @@ function useRcpSources(options = {}) {
|
|
|
2979
3094
|
},
|
|
2980
3095
|
[fetchWithAuth]
|
|
2981
3096
|
);
|
|
2982
|
-
const createRcpSource =
|
|
3097
|
+
const createRcpSource = useCallback13(
|
|
2983
3098
|
async (input) => {
|
|
2984
3099
|
setError(null);
|
|
2985
3100
|
try {
|
|
@@ -3003,7 +3118,7 @@ function useRcpSources(options = {}) {
|
|
|
3003
3118
|
},
|
|
3004
3119
|
[fetchWithAuth]
|
|
3005
3120
|
);
|
|
3006
|
-
const updateRcpSource =
|
|
3121
|
+
const updateRcpSource = useCallback13(
|
|
3007
3122
|
async (sourceId, input) => {
|
|
3008
3123
|
setError(null);
|
|
3009
3124
|
try {
|
|
@@ -3027,7 +3142,7 @@ function useRcpSources(options = {}) {
|
|
|
3027
3142
|
},
|
|
3028
3143
|
[fetchWithAuth]
|
|
3029
3144
|
);
|
|
3030
|
-
const deleteRcpSource =
|
|
3145
|
+
const deleteRcpSource = useCallback13(
|
|
3031
3146
|
async (sourceId) => {
|
|
3032
3147
|
setError(null);
|
|
3033
3148
|
try {
|
|
@@ -3045,7 +3160,7 @@ function useRcpSources(options = {}) {
|
|
|
3045
3160
|
},
|
|
3046
3161
|
[fetchWithAuth]
|
|
3047
3162
|
);
|
|
3048
|
-
const bulkDeleteRcpSources =
|
|
3163
|
+
const bulkDeleteRcpSources = useCallback13(
|
|
3049
3164
|
async (ids) => {
|
|
3050
3165
|
setError(null);
|
|
3051
3166
|
try {
|
|
@@ -3070,7 +3185,7 @@ function useRcpSources(options = {}) {
|
|
|
3070
3185
|
},
|
|
3071
3186
|
[fetchWithAuth]
|
|
3072
3187
|
);
|
|
3073
|
-
const getRcpSourceUsage =
|
|
3188
|
+
const getRcpSourceUsage = useCallback13(
|
|
3074
3189
|
async (sourceId) => {
|
|
3075
3190
|
const res = await fetchWithAuth(`/rcp-sources/${sourceId}/usage`);
|
|
3076
3191
|
if (!res.ok) throw new Error(`Failed to fetch RCP source usage: ${res.statusText}`);
|
|
@@ -3078,7 +3193,7 @@ function useRcpSources(options = {}) {
|
|
|
3078
3193
|
},
|
|
3079
3194
|
[fetchWithAuth]
|
|
3080
3195
|
);
|
|
3081
|
-
const testRcpSourceConnection =
|
|
3196
|
+
const testRcpSourceConnection = useCallback13(
|
|
3082
3197
|
async (sourceId) => {
|
|
3083
3198
|
setError(null);
|
|
3084
3199
|
try {
|
|
@@ -3102,7 +3217,7 @@ function useRcpSources(options = {}) {
|
|
|
3102
3217
|
},
|
|
3103
3218
|
[fetchWithAuth]
|
|
3104
3219
|
);
|
|
3105
|
-
|
|
3220
|
+
useEffect12(() => {
|
|
3106
3221
|
if (autoFetch) void fetchRcpSources();
|
|
3107
3222
|
}, [autoFetch, fetchRcpSources]);
|
|
3108
3223
|
return {
|
|
@@ -3122,21 +3237,21 @@ function useRcpSources(options = {}) {
|
|
|
3122
3237
|
}
|
|
3123
3238
|
|
|
3124
3239
|
// src/hooks/useKnowledgeBases.ts
|
|
3125
|
-
import { useCallback as
|
|
3240
|
+
import { useCallback as useCallback14, useEffect as useEffect13, useState as useState13 } from "react";
|
|
3126
3241
|
function useKnowledgeBases(options = {}) {
|
|
3127
3242
|
const { autoFetch = true, page, limit, search, scope } = options;
|
|
3128
3243
|
const { fetchWithAuth } = usePersonaContext();
|
|
3129
|
-
const [knowledgeBases, setKnowledgeBases] =
|
|
3130
|
-
const [pagination, setPagination] =
|
|
3244
|
+
const [knowledgeBases, setKnowledgeBases] = useState13([]);
|
|
3245
|
+
const [pagination, setPagination] = useState13({
|
|
3131
3246
|
total: 0,
|
|
3132
3247
|
page: page ?? 1,
|
|
3133
3248
|
limit: limit ?? 20,
|
|
3134
3249
|
pages: 0
|
|
3135
3250
|
});
|
|
3136
|
-
const [isLoading, setIsLoading] =
|
|
3137
|
-
const [isUploading, setIsUploading] =
|
|
3138
|
-
const [error, setError] =
|
|
3139
|
-
const fetchKnowledgeBases =
|
|
3251
|
+
const [isLoading, setIsLoading] = useState13(false);
|
|
3252
|
+
const [isUploading, setIsUploading] = useState13(false);
|
|
3253
|
+
const [error, setError] = useState13(null);
|
|
3254
|
+
const fetchKnowledgeBases = useCallback14(async () => {
|
|
3140
3255
|
setIsLoading(true);
|
|
3141
3256
|
setError(null);
|
|
3142
3257
|
try {
|
|
@@ -3163,7 +3278,7 @@ function useKnowledgeBases(options = {}) {
|
|
|
3163
3278
|
setIsLoading(false);
|
|
3164
3279
|
}
|
|
3165
3280
|
}, [fetchWithAuth, page, limit, search, scope]);
|
|
3166
|
-
const getKnowledgeBase =
|
|
3281
|
+
const getKnowledgeBase = useCallback14(
|
|
3167
3282
|
async (kbId) => {
|
|
3168
3283
|
const res = await fetchWithAuth(`/knowledge/${kbId}`);
|
|
3169
3284
|
if (!res.ok) throw new Error(`Failed to fetch knowledge base: ${res.statusText}`);
|
|
@@ -3171,7 +3286,7 @@ function useKnowledgeBases(options = {}) {
|
|
|
3171
3286
|
},
|
|
3172
3287
|
[fetchWithAuth]
|
|
3173
3288
|
);
|
|
3174
|
-
const createKnowledgeBase =
|
|
3289
|
+
const createKnowledgeBase = useCallback14(
|
|
3175
3290
|
async (input) => {
|
|
3176
3291
|
setError(null);
|
|
3177
3292
|
try {
|
|
@@ -3195,7 +3310,7 @@ function useKnowledgeBases(options = {}) {
|
|
|
3195
3310
|
},
|
|
3196
3311
|
[fetchWithAuth]
|
|
3197
3312
|
);
|
|
3198
|
-
const updateKnowledgeBase =
|
|
3313
|
+
const updateKnowledgeBase = useCallback14(
|
|
3199
3314
|
async (kbId, input) => {
|
|
3200
3315
|
setError(null);
|
|
3201
3316
|
try {
|
|
@@ -3219,7 +3334,7 @@ function useKnowledgeBases(options = {}) {
|
|
|
3219
3334
|
},
|
|
3220
3335
|
[fetchWithAuth]
|
|
3221
3336
|
);
|
|
3222
|
-
const deleteKnowledgeBase =
|
|
3337
|
+
const deleteKnowledgeBase = useCallback14(
|
|
3223
3338
|
async (kbId) => {
|
|
3224
3339
|
setError(null);
|
|
3225
3340
|
try {
|
|
@@ -3237,7 +3352,7 @@ function useKnowledgeBases(options = {}) {
|
|
|
3237
3352
|
},
|
|
3238
3353
|
[fetchWithAuth]
|
|
3239
3354
|
);
|
|
3240
|
-
const bulkDeleteKnowledgeBases =
|
|
3355
|
+
const bulkDeleteKnowledgeBases = useCallback14(
|
|
3241
3356
|
async (ids) => {
|
|
3242
3357
|
setError(null);
|
|
3243
3358
|
try {
|
|
@@ -3262,7 +3377,7 @@ function useKnowledgeBases(options = {}) {
|
|
|
3262
3377
|
},
|
|
3263
3378
|
[fetchWithAuth]
|
|
3264
3379
|
);
|
|
3265
|
-
const getKnowledgeBaseUsage =
|
|
3380
|
+
const getKnowledgeBaseUsage = useCallback14(
|
|
3266
3381
|
async (kbId) => {
|
|
3267
3382
|
const res = await fetchWithAuth(`/knowledge/${kbId}/usage`);
|
|
3268
3383
|
if (!res.ok) throw new Error(`Failed to fetch knowledge base usage: ${res.statusText}`);
|
|
@@ -3270,7 +3385,7 @@ function useKnowledgeBases(options = {}) {
|
|
|
3270
3385
|
},
|
|
3271
3386
|
[fetchWithAuth]
|
|
3272
3387
|
);
|
|
3273
|
-
const uploadDocuments =
|
|
3388
|
+
const uploadDocuments = useCallback14(
|
|
3274
3389
|
async (kbId, files) => {
|
|
3275
3390
|
setIsUploading(true);
|
|
3276
3391
|
setError(null);
|
|
@@ -3312,7 +3427,7 @@ function useKnowledgeBases(options = {}) {
|
|
|
3312
3427
|
},
|
|
3313
3428
|
[fetchWithAuth]
|
|
3314
3429
|
);
|
|
3315
|
-
const listDocuments =
|
|
3430
|
+
const listDocuments = useCallback14(
|
|
3316
3431
|
async (kbId) => {
|
|
3317
3432
|
const res = await fetchWithAuth(`/knowledge/${kbId}/documents`);
|
|
3318
3433
|
if (!res.ok) throw new Error(`Failed to list documents: ${res.statusText}`);
|
|
@@ -3320,7 +3435,7 @@ function useKnowledgeBases(options = {}) {
|
|
|
3320
3435
|
},
|
|
3321
3436
|
[fetchWithAuth]
|
|
3322
3437
|
);
|
|
3323
|
-
const deleteDocument =
|
|
3438
|
+
const deleteDocument = useCallback14(
|
|
3324
3439
|
async (kbId, sourceName) => {
|
|
3325
3440
|
setError(null);
|
|
3326
3441
|
try {
|
|
@@ -3347,7 +3462,7 @@ function useKnowledgeBases(options = {}) {
|
|
|
3347
3462
|
},
|
|
3348
3463
|
[fetchWithAuth]
|
|
3349
3464
|
);
|
|
3350
|
-
const searchKnowledgeBase =
|
|
3465
|
+
const searchKnowledgeBase = useCallback14(
|
|
3351
3466
|
async (kbId, query, opts) => {
|
|
3352
3467
|
const res = await fetchWithAuth(`/knowledge/${kbId}/search`, {
|
|
3353
3468
|
method: "POST",
|
|
@@ -3362,7 +3477,7 @@ function useKnowledgeBases(options = {}) {
|
|
|
3362
3477
|
},
|
|
3363
3478
|
[fetchWithAuth]
|
|
3364
3479
|
);
|
|
3365
|
-
|
|
3480
|
+
useEffect13(() => {
|
|
3366
3481
|
if (autoFetch) void fetchKnowledgeBases();
|
|
3367
3482
|
}, [autoFetch, fetchKnowledgeBases]);
|
|
3368
3483
|
return {
|
|
@@ -3386,20 +3501,20 @@ function useKnowledgeBases(options = {}) {
|
|
|
3386
3501
|
}
|
|
3387
3502
|
|
|
3388
3503
|
// src/hooks/useMcpAdmin.ts
|
|
3389
|
-
import { useCallback as
|
|
3504
|
+
import { useCallback as useCallback15, useEffect as useEffect14, useState as useState14 } from "react";
|
|
3390
3505
|
function useMcpAdmin(options = {}) {
|
|
3391
3506
|
const { autoFetch = true, page, limit, search } = options;
|
|
3392
3507
|
const { fetchWithAuth } = usePersonaContext();
|
|
3393
|
-
const [mcps, setMcps] =
|
|
3394
|
-
const [pagination, setPagination] =
|
|
3508
|
+
const [mcps, setMcps] = useState14([]);
|
|
3509
|
+
const [pagination, setPagination] = useState14({
|
|
3395
3510
|
total: 0,
|
|
3396
3511
|
page: page ?? 1,
|
|
3397
3512
|
limit: limit ?? 20,
|
|
3398
3513
|
pages: 0
|
|
3399
3514
|
});
|
|
3400
|
-
const [isLoading, setIsLoading] =
|
|
3401
|
-
const [error, setError] =
|
|
3402
|
-
const fetchMcps =
|
|
3515
|
+
const [isLoading, setIsLoading] = useState14(false);
|
|
3516
|
+
const [error, setError] = useState14(null);
|
|
3517
|
+
const fetchMcps = useCallback15(async () => {
|
|
3403
3518
|
setIsLoading(true);
|
|
3404
3519
|
setError(null);
|
|
3405
3520
|
try {
|
|
@@ -3425,7 +3540,7 @@ function useMcpAdmin(options = {}) {
|
|
|
3425
3540
|
setIsLoading(false);
|
|
3426
3541
|
}
|
|
3427
3542
|
}, [fetchWithAuth, page, limit, search]);
|
|
3428
|
-
const getMcp =
|
|
3543
|
+
const getMcp = useCallback15(
|
|
3429
3544
|
async (mcpId) => {
|
|
3430
3545
|
const res = await fetchWithAuth(`/mcps/${mcpId}`);
|
|
3431
3546
|
if (!res.ok) throw new Error(`Failed to fetch MCP: ${res.statusText}`);
|
|
@@ -3433,7 +3548,7 @@ function useMcpAdmin(options = {}) {
|
|
|
3433
3548
|
},
|
|
3434
3549
|
[fetchWithAuth]
|
|
3435
3550
|
);
|
|
3436
|
-
const createMcp =
|
|
3551
|
+
const createMcp = useCallback15(
|
|
3437
3552
|
async (input) => {
|
|
3438
3553
|
setError(null);
|
|
3439
3554
|
try {
|
|
@@ -3457,7 +3572,7 @@ function useMcpAdmin(options = {}) {
|
|
|
3457
3572
|
},
|
|
3458
3573
|
[fetchWithAuth]
|
|
3459
3574
|
);
|
|
3460
|
-
const updateMcp =
|
|
3575
|
+
const updateMcp = useCallback15(
|
|
3461
3576
|
async (mcpId, input) => {
|
|
3462
3577
|
setError(null);
|
|
3463
3578
|
try {
|
|
@@ -3481,7 +3596,7 @@ function useMcpAdmin(options = {}) {
|
|
|
3481
3596
|
},
|
|
3482
3597
|
[fetchWithAuth]
|
|
3483
3598
|
);
|
|
3484
|
-
const deleteMcp =
|
|
3599
|
+
const deleteMcp = useCallback15(
|
|
3485
3600
|
async (mcpId) => {
|
|
3486
3601
|
setError(null);
|
|
3487
3602
|
try {
|
|
@@ -3499,7 +3614,7 @@ function useMcpAdmin(options = {}) {
|
|
|
3499
3614
|
},
|
|
3500
3615
|
[fetchWithAuth]
|
|
3501
3616
|
);
|
|
3502
|
-
const bulkDeleteMcps =
|
|
3617
|
+
const bulkDeleteMcps = useCallback15(
|
|
3503
3618
|
async (ids) => {
|
|
3504
3619
|
setError(null);
|
|
3505
3620
|
try {
|
|
@@ -3524,7 +3639,7 @@ function useMcpAdmin(options = {}) {
|
|
|
3524
3639
|
},
|
|
3525
3640
|
[fetchWithAuth]
|
|
3526
3641
|
);
|
|
3527
|
-
const testConnection =
|
|
3642
|
+
const testConnection = useCallback15(
|
|
3528
3643
|
async (mcpId) => {
|
|
3529
3644
|
setError(null);
|
|
3530
3645
|
try {
|
|
@@ -3548,7 +3663,7 @@ function useMcpAdmin(options = {}) {
|
|
|
3548
3663
|
},
|
|
3549
3664
|
[fetchWithAuth]
|
|
3550
3665
|
);
|
|
3551
|
-
|
|
3666
|
+
useEffect14(() => {
|
|
3552
3667
|
if (autoFetch) void fetchMcps();
|
|
3553
3668
|
}, [autoFetch, fetchMcps]);
|
|
3554
3669
|
return {
|
|
@@ -3567,21 +3682,21 @@ function useMcpAdmin(options = {}) {
|
|
|
3567
3682
|
}
|
|
3568
3683
|
|
|
3569
3684
|
// src/hooks/useWorkflows.ts
|
|
3570
|
-
import { useCallback as
|
|
3685
|
+
import { useCallback as useCallback16, useEffect as useEffect15, useState as useState15 } from "react";
|
|
3571
3686
|
function useWorkflows(options) {
|
|
3572
3687
|
const opts = typeof options === "boolean" ? { autoFetch: options } : options ?? {};
|
|
3573
3688
|
const { autoFetch = true, search, scope, visibility, isEnabled, page, limit } = opts;
|
|
3574
3689
|
const { fetchWithAuth } = usePersonaContext();
|
|
3575
|
-
const [workflows, setWorkflows] =
|
|
3576
|
-
const [pagination, setPagination] =
|
|
3690
|
+
const [workflows, setWorkflows] = useState15([]);
|
|
3691
|
+
const [pagination, setPagination] = useState15({
|
|
3577
3692
|
page: page ?? 1,
|
|
3578
3693
|
limit: limit ?? 20,
|
|
3579
3694
|
total: 0,
|
|
3580
3695
|
totalPages: 0
|
|
3581
3696
|
});
|
|
3582
|
-
const [isLoading, setIsLoading] =
|
|
3583
|
-
const [error, setError] =
|
|
3584
|
-
const fetchWorkflows =
|
|
3697
|
+
const [isLoading, setIsLoading] = useState15(false);
|
|
3698
|
+
const [error, setError] = useState15(null);
|
|
3699
|
+
const fetchWorkflows = useCallback16(async () => {
|
|
3585
3700
|
setIsLoading(true);
|
|
3586
3701
|
setError(null);
|
|
3587
3702
|
try {
|
|
@@ -3627,7 +3742,7 @@ function useWorkflows(options) {
|
|
|
3627
3742
|
setIsLoading(false);
|
|
3628
3743
|
}
|
|
3629
3744
|
}, [fetchWithAuth, search, scope, visibility, isEnabled, page, limit]);
|
|
3630
|
-
const createWorkflow =
|
|
3745
|
+
const createWorkflow = useCallback16(
|
|
3631
3746
|
async (input) => {
|
|
3632
3747
|
setError(null);
|
|
3633
3748
|
try {
|
|
@@ -3651,7 +3766,7 @@ function useWorkflows(options) {
|
|
|
3651
3766
|
},
|
|
3652
3767
|
[fetchWithAuth]
|
|
3653
3768
|
);
|
|
3654
|
-
|
|
3769
|
+
useEffect15(() => {
|
|
3655
3770
|
if (autoFetch) {
|
|
3656
3771
|
void fetchWorkflows();
|
|
3657
3772
|
}
|
|
@@ -3667,17 +3782,17 @@ function useWorkflows(options) {
|
|
|
3667
3782
|
}
|
|
3668
3783
|
|
|
3669
3784
|
// src/hooks/useWorkflow.ts
|
|
3670
|
-
import { useCallback as
|
|
3785
|
+
import { useCallback as useCallback17, useEffect as useEffect16, useState as useState16 } from "react";
|
|
3671
3786
|
function useWorkflow(workflowId, options) {
|
|
3672
3787
|
const opts = typeof options === "boolean" ? { autoFetch: options } : options ?? {};
|
|
3673
3788
|
const { autoFetch = true } = opts;
|
|
3674
3789
|
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 =
|
|
3790
|
+
const [workflow, setWorkflow] = useState16(null);
|
|
3791
|
+
const [versions, setVersions] = useState16([]);
|
|
3792
|
+
const [mermaid, setMermaid] = useState16(null);
|
|
3793
|
+
const [isLoading, setIsLoading] = useState16(false);
|
|
3794
|
+
const [error, setError] = useState16(null);
|
|
3795
|
+
const fetchWorkflow = useCallback17(async () => {
|
|
3681
3796
|
if (!workflowId) return null;
|
|
3682
3797
|
setIsLoading(true);
|
|
3683
3798
|
setError(null);
|
|
@@ -3697,7 +3812,7 @@ function useWorkflow(workflowId, options) {
|
|
|
3697
3812
|
setIsLoading(false);
|
|
3698
3813
|
}
|
|
3699
3814
|
}, [fetchWithAuth, workflowId]);
|
|
3700
|
-
const fetchVersions =
|
|
3815
|
+
const fetchVersions = useCallback17(async () => {
|
|
3701
3816
|
if (!workflowId) return [];
|
|
3702
3817
|
try {
|
|
3703
3818
|
const res = await fetchWithAuth(`/workflows/${workflowId}/versions`);
|
|
@@ -3710,7 +3825,7 @@ function useWorkflow(workflowId, options) {
|
|
|
3710
3825
|
return [];
|
|
3711
3826
|
}
|
|
3712
3827
|
}, [fetchWithAuth, workflowId]);
|
|
3713
|
-
const getVersion =
|
|
3828
|
+
const getVersion = useCallback17(
|
|
3714
3829
|
async (version) => {
|
|
3715
3830
|
if (!workflowId) throw new Error("Workflow ID is required");
|
|
3716
3831
|
const res = await fetchWithAuth(`/workflows/${workflowId}/versions/${version}`);
|
|
@@ -3721,7 +3836,7 @@ function useWorkflow(workflowId, options) {
|
|
|
3721
3836
|
},
|
|
3722
3837
|
[fetchWithAuth, workflowId]
|
|
3723
3838
|
);
|
|
3724
|
-
const fetchMermaid =
|
|
3839
|
+
const fetchMermaid = useCallback17(async () => {
|
|
3725
3840
|
if (!workflowId) return "";
|
|
3726
3841
|
try {
|
|
3727
3842
|
const res = await fetchWithAuth(`/workflows/${workflowId}/mermaid`);
|
|
@@ -3734,7 +3849,7 @@ function useWorkflow(workflowId, options) {
|
|
|
3734
3849
|
return "";
|
|
3735
3850
|
}
|
|
3736
3851
|
}, [fetchWithAuth, workflowId]);
|
|
3737
|
-
const updateWorkflow =
|
|
3852
|
+
const updateWorkflow = useCallback17(
|
|
3738
3853
|
async (input) => {
|
|
3739
3854
|
if (!workflowId) throw new Error("Workflow ID is required");
|
|
3740
3855
|
setError(null);
|
|
@@ -3753,7 +3868,7 @@ function useWorkflow(workflowId, options) {
|
|
|
3753
3868
|
},
|
|
3754
3869
|
[fetchWithAuth, workflowId]
|
|
3755
3870
|
);
|
|
3756
|
-
const saveDraft =
|
|
3871
|
+
const saveDraft = useCallback17(
|
|
3757
3872
|
async (draft) => {
|
|
3758
3873
|
if (!workflowId) throw new Error("Workflow ID is required");
|
|
3759
3874
|
setError(null);
|
|
@@ -3772,7 +3887,7 @@ function useWorkflow(workflowId, options) {
|
|
|
3772
3887
|
},
|
|
3773
3888
|
[fetchWithAuth, workflowId]
|
|
3774
3889
|
);
|
|
3775
|
-
const publish =
|
|
3890
|
+
const publish = useCallback17(async () => {
|
|
3776
3891
|
if (!workflowId) throw new Error("Workflow ID is required");
|
|
3777
3892
|
setError(null);
|
|
3778
3893
|
const res = await fetchWithAuth(`/workflows/${workflowId}/publish`, {
|
|
@@ -3787,7 +3902,7 @@ function useWorkflow(workflowId, options) {
|
|
|
3787
3902
|
void fetchVersions();
|
|
3788
3903
|
return versionResult;
|
|
3789
3904
|
}, [fetchWithAuth, workflowId, fetchWorkflow, fetchVersions]);
|
|
3790
|
-
const deleteWorkflow =
|
|
3905
|
+
const deleteWorkflow = useCallback17(async () => {
|
|
3791
3906
|
if (!workflowId) throw new Error("Workflow ID is required");
|
|
3792
3907
|
setError(null);
|
|
3793
3908
|
const res = await fetchWithAuth(`/workflows/${workflowId}`, {
|
|
@@ -3798,7 +3913,7 @@ function useWorkflow(workflowId, options) {
|
|
|
3798
3913
|
}
|
|
3799
3914
|
setWorkflow(null);
|
|
3800
3915
|
}, [fetchWithAuth, workflowId]);
|
|
3801
|
-
|
|
3916
|
+
useEffect16(() => {
|
|
3802
3917
|
if (autoFetch && workflowId) {
|
|
3803
3918
|
void fetchWorkflow();
|
|
3804
3919
|
}
|
|
@@ -3821,25 +3936,25 @@ function useWorkflow(workflowId, options) {
|
|
|
3821
3936
|
}
|
|
3822
3937
|
|
|
3823
3938
|
// src/hooks/useWorkflowStream.ts
|
|
3824
|
-
import { useCallback as
|
|
3939
|
+
import { useCallback as useCallback18, useEffect as useEffect17, useRef as useRef4, useState as useState17 } from "react";
|
|
3825
3940
|
function useWorkflowStream(workflowId, options) {
|
|
3826
3941
|
const { baseUrl, getAuthToken, fetchWithAuth, logger } = usePersonaContext();
|
|
3827
|
-
const [status, setStatus] =
|
|
3828
|
-
const [runId, setRunId] =
|
|
3829
|
-
const [activeNodeId, setActiveNodeId] =
|
|
3830
|
-
const [nodeRuns, setNodeRuns] =
|
|
3942
|
+
const [status, setStatus] = useState17("idle");
|
|
3943
|
+
const [runId, setRunId] = useState17(null);
|
|
3944
|
+
const [activeNodeId, setActiveNodeId] = useState17(null);
|
|
3945
|
+
const [nodeRuns, setNodeRuns] = useState17(
|
|
3831
3946
|
{}
|
|
3832
3947
|
);
|
|
3833
|
-
const [text, setText] =
|
|
3834
|
-
const [output, setOutput] =
|
|
3835
|
-
const [error, setError] =
|
|
3836
|
-
const [events, setEvents] =
|
|
3948
|
+
const [text, setText] = useState17("");
|
|
3949
|
+
const [output, setOutput] = useState17(null);
|
|
3950
|
+
const [error, setError] = useState17(null);
|
|
3951
|
+
const [events, setEvents] = useState17([]);
|
|
3837
3952
|
const abortControllerRef = useRef4(null);
|
|
3838
3953
|
const currentRunIdRef = useRef4(null);
|
|
3839
3954
|
currentRunIdRef.current = runId;
|
|
3840
3955
|
const optionsRef = useRef4(options);
|
|
3841
3956
|
optionsRef.current = options;
|
|
3842
|
-
const cancel =
|
|
3957
|
+
const cancel = useCallback18(async () => {
|
|
3843
3958
|
if (abortControllerRef.current) {
|
|
3844
3959
|
abortControllerRef.current.abort();
|
|
3845
3960
|
abortControllerRef.current = null;
|
|
@@ -3860,7 +3975,7 @@ function useWorkflowStream(workflowId, options) {
|
|
|
3860
3975
|
setStatus("cancelled");
|
|
3861
3976
|
setActiveNodeId(null);
|
|
3862
3977
|
}, [fetchWithAuth, logger]);
|
|
3863
|
-
const reset =
|
|
3978
|
+
const reset = useCallback18(() => {
|
|
3864
3979
|
if (abortControllerRef.current) {
|
|
3865
3980
|
abortControllerRef.current.abort();
|
|
3866
3981
|
abortControllerRef.current = null;
|
|
@@ -3874,7 +3989,7 @@ function useWorkflowStream(workflowId, options) {
|
|
|
3874
3989
|
setError(null);
|
|
3875
3990
|
setEvents([]);
|
|
3876
3991
|
}, []);
|
|
3877
|
-
const processStream =
|
|
3992
|
+
const processStream = useCallback18(
|
|
3878
3993
|
async (url, method, body, targetRunId) => {
|
|
3879
3994
|
if (abortControllerRef.current) {
|
|
3880
3995
|
abortControllerRef.current.abort();
|
|
@@ -4039,7 +4154,7 @@ function useWorkflowStream(workflowId, options) {
|
|
|
4039
4154
|
},
|
|
4040
4155
|
[getAuthToken]
|
|
4041
4156
|
);
|
|
4042
|
-
const start =
|
|
4157
|
+
const start = useCallback18(
|
|
4043
4158
|
async (input, opts) => {
|
|
4044
4159
|
const targetWfId = opts?.workflowId || workflowId;
|
|
4045
4160
|
if (!targetWfId) {
|
|
@@ -4060,7 +4175,7 @@ function useWorkflowStream(workflowId, options) {
|
|
|
4060
4175
|
},
|
|
4061
4176
|
[workflowId, baseUrl, processStream]
|
|
4062
4177
|
);
|
|
4063
|
-
const resume =
|
|
4178
|
+
const resume = useCallback18(
|
|
4064
4179
|
async (targetRunId, sinceSeq) => {
|
|
4065
4180
|
if (!targetRunId) {
|
|
4066
4181
|
throw new Error("Run ID is required to resume stream");
|
|
@@ -4073,7 +4188,7 @@ function useWorkflowStream(workflowId, options) {
|
|
|
4073
4188
|
},
|
|
4074
4189
|
[baseUrl, processStream]
|
|
4075
4190
|
);
|
|
4076
|
-
|
|
4191
|
+
useEffect17(() => {
|
|
4077
4192
|
return () => {
|
|
4078
4193
|
if (abortControllerRef.current) {
|
|
4079
4194
|
abortControllerRef.current.abort();
|
|
@@ -4098,21 +4213,21 @@ function useWorkflowStream(workflowId, options) {
|
|
|
4098
4213
|
}
|
|
4099
4214
|
|
|
4100
4215
|
// src/hooks/useWorkflowRuns.ts
|
|
4101
|
-
import { useCallback as
|
|
4216
|
+
import { useCallback as useCallback19, useEffect as useEffect18, useState as useState18 } from "react";
|
|
4102
4217
|
function useWorkflowRuns(workflowId, options) {
|
|
4103
4218
|
const opts = typeof options === "boolean" ? { autoFetch: options } : options ?? {};
|
|
4104
4219
|
const { autoFetch = true, page = 1, limit = 20 } = opts;
|
|
4105
4220
|
const { fetchWithAuth } = usePersonaContext();
|
|
4106
|
-
const [runs, setRuns] =
|
|
4107
|
-
const [pagination, setPagination] =
|
|
4221
|
+
const [runs, setRuns] = useState18([]);
|
|
4222
|
+
const [pagination, setPagination] = useState18({
|
|
4108
4223
|
page,
|
|
4109
4224
|
limit,
|
|
4110
4225
|
total: 0,
|
|
4111
4226
|
totalPages: 0
|
|
4112
4227
|
});
|
|
4113
|
-
const [isLoading, setIsLoading] =
|
|
4114
|
-
const [error, setError] =
|
|
4115
|
-
const fetchRuns =
|
|
4228
|
+
const [isLoading, setIsLoading] = useState18(false);
|
|
4229
|
+
const [error, setError] = useState18(null);
|
|
4230
|
+
const fetchRuns = useCallback19(async () => {
|
|
4116
4231
|
if (!workflowId) return [];
|
|
4117
4232
|
setIsLoading(true);
|
|
4118
4233
|
setError(null);
|
|
@@ -4144,7 +4259,7 @@ function useWorkflowRuns(workflowId, options) {
|
|
|
4144
4259
|
setIsLoading(false);
|
|
4145
4260
|
}
|
|
4146
4261
|
}, [fetchWithAuth, workflowId, page, limit]);
|
|
4147
|
-
const getRun =
|
|
4262
|
+
const getRun = useCallback19(
|
|
4148
4263
|
async (runId) => {
|
|
4149
4264
|
if (!runId) throw new Error("Run ID is required");
|
|
4150
4265
|
const res = await fetchWithAuth(`/workflows/runs/${runId}`);
|
|
@@ -4155,7 +4270,7 @@ function useWorkflowRuns(workflowId, options) {
|
|
|
4155
4270
|
},
|
|
4156
4271
|
[fetchWithAuth]
|
|
4157
4272
|
);
|
|
4158
|
-
const cancelRun =
|
|
4273
|
+
const cancelRun = useCallback19(
|
|
4159
4274
|
async (runId) => {
|
|
4160
4275
|
if (!runId) throw new Error("Run ID is required");
|
|
4161
4276
|
const res = await fetchWithAuth(`/workflows/runs/${runId}/cancel`, {
|
|
@@ -4170,7 +4285,7 @@ function useWorkflowRuns(workflowId, options) {
|
|
|
4170
4285
|
},
|
|
4171
4286
|
[fetchWithAuth]
|
|
4172
4287
|
);
|
|
4173
|
-
|
|
4288
|
+
useEffect18(() => {
|
|
4174
4289
|
if (autoFetch && workflowId) {
|
|
4175
4290
|
void fetchRuns();
|
|
4176
4291
|
}
|
|
@@ -4224,6 +4339,7 @@ export {
|
|
|
4224
4339
|
useWorkflow,
|
|
4225
4340
|
useWorkflowRuns,
|
|
4226
4341
|
useWorkflowStream,
|
|
4227
|
-
useWorkflows
|
|
4342
|
+
useWorkflows,
|
|
4343
|
+
useWorkspaceFiles
|
|
4228
4344
|
};
|
|
4229
4345
|
//# sourceMappingURL=index.js.map
|