@personaai/react 0.15.0 → 0.17.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 +40 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -15
- package/dist/index.d.ts +34 -15
- package/dist/index.js +40 -27
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1721,7 +1721,8 @@ function useMemory(autoFetch = true) {
|
|
|
1721
1721
|
const { fetchWithAuth } = usePersonaContext();
|
|
1722
1722
|
const [memory, setMemory] = (0, import_react4.useState)({
|
|
1723
1723
|
userFiles: [],
|
|
1724
|
-
agentMemories: []
|
|
1724
|
+
agentMemories: [],
|
|
1725
|
+
agentWorkspaces: []
|
|
1725
1726
|
});
|
|
1726
1727
|
const [isLoading, setIsLoading] = (0, import_react4.useState)(false);
|
|
1727
1728
|
const [error, setError] = (0, import_react4.useState)(null);
|
|
@@ -1739,7 +1740,7 @@ function useMemory(autoFetch = true) {
|
|
|
1739
1740
|
} catch (err) {
|
|
1740
1741
|
const errorObj = err instanceof Error ? err : new Error(String(err));
|
|
1741
1742
|
setError(errorObj);
|
|
1742
|
-
return { userFiles: [], agentMemories: [] };
|
|
1743
|
+
return { userFiles: [], agentMemories: [], agentWorkspaces: [] };
|
|
1743
1744
|
} finally {
|
|
1744
1745
|
setIsLoading(false);
|
|
1745
1746
|
}
|
|
@@ -1946,21 +1947,36 @@ function useThreads(autoFetch = true) {
|
|
|
1946
1947
|
|
|
1947
1948
|
// src/hooks/useWorkspaceFiles.ts
|
|
1948
1949
|
var import_react6 = require("react");
|
|
1949
|
-
function
|
|
1950
|
+
function toWorkspaceFile(file) {
|
|
1951
|
+
return {
|
|
1952
|
+
content: file.content,
|
|
1953
|
+
size: file.content.length,
|
|
1954
|
+
createdAt: file.createdAt ?? null,
|
|
1955
|
+
modifiedAt: file.updatedAt ?? null
|
|
1956
|
+
};
|
|
1957
|
+
}
|
|
1958
|
+
function useWorkspaceFiles(agentId, autoFetch = true) {
|
|
1950
1959
|
const { fetchWithAuth } = usePersonaContext();
|
|
1951
1960
|
const [files, setFiles] = (0, import_react6.useState)({});
|
|
1952
1961
|
const [isLoading, setIsLoading] = (0, import_react6.useState)(false);
|
|
1953
1962
|
const [isSaving, setIsSaving] = (0, import_react6.useState)(false);
|
|
1954
1963
|
const [error, setError] = (0, import_react6.useState)(null);
|
|
1955
1964
|
const fetchFiles = (0, import_react6.useCallback)(async () => {
|
|
1956
|
-
if (!
|
|
1965
|
+
if (!agentId) return {};
|
|
1957
1966
|
setIsLoading(true);
|
|
1958
1967
|
setError(null);
|
|
1959
1968
|
try {
|
|
1960
|
-
const res = await fetchWithAuth(
|
|
1969
|
+
const res = await fetchWithAuth("/memory");
|
|
1961
1970
|
if (!res.ok) throw new Error(`Failed to list workspace files: ${res.statusText}`);
|
|
1962
1971
|
const data = await res.json();
|
|
1963
|
-
const
|
|
1972
|
+
const body = data?.data ?? data;
|
|
1973
|
+
const group = (body?.agentWorkspaces ?? []).find(
|
|
1974
|
+
(g) => g.agentId === agentId
|
|
1975
|
+
);
|
|
1976
|
+
const normalized = {};
|
|
1977
|
+
for (const file of group?.files ?? []) {
|
|
1978
|
+
normalized[file.path] = toWorkspaceFile(file);
|
|
1979
|
+
}
|
|
1964
1980
|
setFiles(normalized);
|
|
1965
1981
|
return normalized;
|
|
1966
1982
|
} catch (err) {
|
|
@@ -1970,35 +1986,34 @@ function useWorkspaceFiles(threadId, autoFetch = true) {
|
|
|
1970
1986
|
} finally {
|
|
1971
1987
|
setIsLoading(false);
|
|
1972
1988
|
}
|
|
1973
|
-
}, [fetchWithAuth,
|
|
1989
|
+
}, [fetchWithAuth, agentId]);
|
|
1974
1990
|
const getFile = (0, import_react6.useCallback)(
|
|
1975
1991
|
async (path) => {
|
|
1976
|
-
if (!
|
|
1977
|
-
const
|
|
1978
|
-
|
|
1979
|
-
);
|
|
1992
|
+
if (!agentId) throw new Error("useWorkspaceFiles: no agentId set");
|
|
1993
|
+
const query = new URLSearchParams({ path, scope: "workspace", agentId });
|
|
1994
|
+
const res = await fetchWithAuth(`/memory/file?${query.toString()}`);
|
|
1980
1995
|
if (!res.ok) throw new Error(`Failed to read workspace file: ${res.statusText}`);
|
|
1981
1996
|
const data = await res.json();
|
|
1982
1997
|
const raw = data?.data ?? data;
|
|
1983
|
-
return
|
|
1998
|
+
return toWorkspaceFile(raw);
|
|
1984
1999
|
},
|
|
1985
|
-
[fetchWithAuth,
|
|
2000
|
+
[fetchWithAuth, agentId]
|
|
1986
2001
|
);
|
|
1987
2002
|
const writeFile = (0, import_react6.useCallback)(
|
|
1988
2003
|
async (path, content) => {
|
|
1989
|
-
if (!
|
|
2004
|
+
if (!agentId) throw new Error("useWorkspaceFiles: no agentId set");
|
|
1990
2005
|
setIsSaving(true);
|
|
1991
2006
|
setError(null);
|
|
1992
2007
|
try {
|
|
1993
|
-
const res = await fetchWithAuth(
|
|
2008
|
+
const res = await fetchWithAuth("/memory/file", {
|
|
1994
2009
|
method: "PUT",
|
|
1995
2010
|
headers: { "Content-Type": "application/json" },
|
|
1996
|
-
body: JSON.stringify({ path, content })
|
|
2011
|
+
body: JSON.stringify({ path, content, scope: "workspace", agentId })
|
|
1997
2012
|
});
|
|
1998
2013
|
if (!res.ok) throw new Error(`Failed to write workspace file: ${res.statusText}`);
|
|
1999
2014
|
const data = await res.json();
|
|
2000
2015
|
const raw = data?.data ?? data;
|
|
2001
|
-
const file =
|
|
2016
|
+
const file = toWorkspaceFile(raw);
|
|
2002
2017
|
setFiles((prev) => ({ ...prev, [path]: file }));
|
|
2003
2018
|
return file;
|
|
2004
2019
|
} catch (err) {
|
|
@@ -2009,15 +2024,13 @@ function useWorkspaceFiles(threadId, autoFetch = true) {
|
|
|
2009
2024
|
setIsSaving(false);
|
|
2010
2025
|
}
|
|
2011
2026
|
},
|
|
2012
|
-
[fetchWithAuth,
|
|
2027
|
+
[fetchWithAuth, agentId]
|
|
2013
2028
|
);
|
|
2014
2029
|
const deleteFile = (0, import_react6.useCallback)(
|
|
2015
2030
|
async (path) => {
|
|
2016
|
-
if (!
|
|
2017
|
-
const
|
|
2018
|
-
|
|
2019
|
-
{ method: "DELETE" }
|
|
2020
|
-
);
|
|
2031
|
+
if (!agentId) throw new Error("useWorkspaceFiles: no agentId set");
|
|
2032
|
+
const query = new URLSearchParams({ path, scope: "workspace", agentId });
|
|
2033
|
+
const res = await fetchWithAuth(`/memory/file?${query.toString()}`, { method: "DELETE" });
|
|
2021
2034
|
if (!res.ok) throw new Error(`Failed to delete workspace file: ${res.statusText}`);
|
|
2022
2035
|
setFiles((prev) => {
|
|
2023
2036
|
const next = { ...prev };
|
|
@@ -2025,15 +2038,15 @@ function useWorkspaceFiles(threadId, autoFetch = true) {
|
|
|
2025
2038
|
return next;
|
|
2026
2039
|
});
|
|
2027
2040
|
},
|
|
2028
|
-
[fetchWithAuth,
|
|
2041
|
+
[fetchWithAuth, agentId]
|
|
2029
2042
|
);
|
|
2030
2043
|
(0, import_react6.useEffect)(() => {
|
|
2031
|
-
if (autoFetch &&
|
|
2044
|
+
if (autoFetch && agentId) {
|
|
2032
2045
|
void fetchFiles();
|
|
2033
|
-
} else if (!
|
|
2046
|
+
} else if (!agentId) {
|
|
2034
2047
|
setFiles({});
|
|
2035
2048
|
}
|
|
2036
|
-
}, [autoFetch,
|
|
2049
|
+
}, [autoFetch, agentId, fetchFiles]);
|
|
2037
2050
|
return {
|
|
2038
2051
|
files,
|
|
2039
2052
|
isLoading,
|