diff --git a/backend/apps/webui/routers/tools.py b/backend/apps/webui/routers/tools.py index dc76bb312..048813c72 100644 --- a/backend/apps/webui/routers/tools.py +++ b/backend/apps/webui/routers/tools.py @@ -62,7 +62,7 @@ async def get_toolkits(user=Depends(get_current_user)): @router.get("/export", response_model=List[ToolModel]) -async def get_toolkits(user=Depends(get_current_user)): +async def get_toolkits(user=Depends(get_admin_user)): toolkits = [toolkit for toolkit in Tools.get_tools()] return toolkits diff --git a/src/lib/apis/tools/index.ts b/src/lib/apis/tools/index.ts index 7fc0ed03d..47a535cdf 100644 --- a/src/lib/apis/tools/index.ts +++ b/src/lib/apis/tools/index.ts @@ -62,6 +62,37 @@ export const getTools = async (token: string = '') => { return res; }; +export const exportTools = async (token: string = '') => { + let error = null; + + const res = await fetch(`${WEBUI_API_BASE_URL}/tools/export`, { + 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 getToolById = async (token: string, id: string) => { let error = null; diff --git a/src/lib/components/workspace/Tools.svelte b/src/lib/components/workspace/Tools.svelte index b7a5461e6..837ba62dc 100644 --- a/src/lib/components/workspace/Tools.svelte +++ b/src/lib/components/workspace/Tools.svelte @@ -8,7 +8,7 @@ import { createNewPrompt, deletePromptByCommand, getPrompts } from '$lib/apis/prompts'; import { goto } from '$app/navigation'; - import { deleteToolById, getTools } from '$lib/apis/tools'; + import { deleteToolById, exportTools, getTools } from '$lib/apis/tools'; const i18n = getContext('i18n'); @@ -221,10 +221,17 @@