This commit is contained in:
Timothy Jaeryang Baek
2026-02-10 15:47:21 -06:00
parent e3a8257690
commit 4aedfdc547
7 changed files with 184 additions and 18 deletions
+33
View File
@@ -289,6 +289,39 @@ export const updateKnowledgeById = async (token: string, id: string, form: Knowl
return res;
};
export const updateKnowledgeAccessGrants = async (
token: string,
id: string,
accessGrants: any[]
) => {
let error = null;
const res = await fetch(`${WEBUI_API_BASE_URL}/knowledge/${id}/access/update`, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
authorization: `Bearer ${token}`
},
body: JSON.stringify({ access_grants: accessGrants })
})
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.catch((err) => {
error = err.detail;
console.error(err);
return null;
});
if (error) {
throw error;
}
return res;
};
export const addFileToKnowledgeById = async (token: string, id: string, fileId: string) => {
let error = null;
+35 -3
View File
@@ -331,8 +331,7 @@ export const updatePromptMetadata = async (
promptId: string,
name: string,
command: string,
tags: string[] = [],
accessGrants: any[] | null = null
tags: string[] = []
) => {
let error = null;
@@ -343,7 +342,7 @@ export const updatePromptMetadata = async (
'Content-Type': 'application/json',
authorization: `Bearer ${token}`
},
body: JSON.stringify({ name, command, tags, access_grants: accessGrants })
body: JSON.stringify({ name, command, tags })
})
.then(async (res) => {
if (!res.ok) throw await res.json();
@@ -429,6 +428,39 @@ export const deletePromptById = async (token: string, promptId: string) => {
return res;
};
export const updatePromptAccessGrants = async (
token: string,
promptId: string,
accessGrants: any[]
) => {
let error = null;
const res = await fetch(`${WEBUI_API_BASE_URL}/prompts/id/${promptId}/access/update`, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
authorization: `Bearer ${token}`
},
body: JSON.stringify({ access_grants: accessGrants })
})
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.catch((err) => {
error = err.detail;
console.error(err);
return null;
});
if (error) {
throw error;
}
return res;
};
////////////////////////////
// Prompt History APIs
////////////////////////////
@@ -31,6 +31,7 @@
resetKnowledgeById,
updateFileFromKnowledgeById,
updateKnowledgeById,
updateKnowledgeAccessGrants,
searchKnowledgeFilesById
} from '$lib/apis/knowledge';
import { processWeb, processYoutubeVideo } from '$lib/apis/retrieval';
@@ -838,8 +839,13 @@
sharePublic={$user?.permissions?.sharing?.public_knowledge ||
$user?.role === 'admin' ||
knowledge?.write_access}
onChange={() => {
changeDebounceHandler();
onChange={async () => {
try {
await updateKnowledgeAccessGrants(localStorage.token, id, knowledge.access_grants ?? []);
toast.success($i18n.t('Saved'));
} catch (error) {
toast.error(`${error}`);
}
}}
accessRoles={['read', 'write']}
/>
@@ -18,6 +18,7 @@
setProductionPromptVersion,
deletePromptHistoryVersion,
updatePromptMetadata,
updatePromptAccessGrants,
getPromptTags
} from '$lib/apis/prompts';
import dayjs from 'dayjs';
@@ -227,8 +228,7 @@
prompt?.id,
name,
command,
tags.map((tag) => tag.name),
accessGrants
tags.map((tag) => tag.name)
);
// Update originals on success
originalName = name;
@@ -283,8 +283,15 @@
accessRoles={['read', 'write']}
share={$user?.permissions?.sharing?.prompts || $user?.role === 'admin'}
sharePublic={$user?.permissions?.sharing?.public_prompts || $user?.role === 'admin' || edit}
onChange={() => {
debouncedSaveMetadata();
onChange={async () => {
if (edit && prompt?.id) {
try {
await updatePromptAccessGrants(localStorage.token, prompt.id, accessGrants);
toast.success($i18n.t('Saved'));
} catch (error) {
toast.error(`${error}`);
}
}
}}
/>