diff --git a/backend/open_webui/apps/webui/models/tools.py b/backend/open_webui/apps/webui/models/tools.py index ee2de91e7..1b7256df4 100644 --- a/backend/open_webui/apps/webui/models/tools.py +++ b/backend/open_webui/apps/webui/models/tools.py @@ -145,7 +145,7 @@ class ToolsTable: tool for tool in tools if tool.user_id == user_id - or has_access(tool.access_control, user_id, permission) + or has_access(user_id, permission, tool.access_control) ] def get_tool_valves_by_id(self, id: str) -> Optional[dict]: diff --git a/src/lib/apis/tools/index.ts b/src/lib/apis/tools/index.ts index 28e8dde86..25dcf03aa 100644 --- a/src/lib/apis/tools/index.ts +++ b/src/lib/apis/tools/index.ts @@ -62,6 +62,39 @@ export const getTools = async (token: string = '') => { return res; }; + +export const getToolList = async (token: string = '') => { + let error = null; + + const res = await fetch(`${WEBUI_API_BASE_URL}/tools/list`, { + method: 'GET', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + authorization: `Bearer ${token}` + } + }) + .then(async (res) => { + if (!res.ok) throw await res.json(); + return res.json(); + }) + .then((json) => { + return json; + }) + .catch((err) => { + error = err.detail; + console.log(err); + return null; + }); + + if (error) { + throw error; + } + + return res; +}; + + export const exportTools = async (token: string = '') => { let error = null; diff --git a/src/lib/components/workspace/Tools.svelte b/src/lib/components/workspace/Tools.svelte index 674911a53..4dbebf421 100644 --- a/src/lib/components/workspace/Tools.svelte +++ b/src/lib/components/workspace/Tools.svelte @@ -13,6 +13,7 @@ deleteToolById, exportTools, getToolById, + getToolList, getTools } from '$lib/apis/tools'; import ArrowDownTray from '../icons/ArrowDownTray.svelte'; @@ -47,6 +48,7 @@ let tools = []; let filteredItems = []; + $: filteredItems = tools.filter( (t) => query === '' || @@ -119,11 +121,18 @@ if (res) { toast.success($i18n.t('Tool deleted successfully')); - _tools.set(await getTools(localStorage.token)); + + init(); } }; + const init = async () => { + tools = await getToolList(localStorage.token); + _tools.set(await getTools(localStorage.token)); + }; + onMount(() => { + init(); const onKeyDown = (event) => { if (event.key === 'Shift') { shiftKey = true;