From ca8be1ee4ab5691828389e2ceeadc3ba2eed7d78 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Mon, 10 Jun 2024 21:38:29 -0700 Subject: [PATCH] feat: import tools --- src/lib/components/workspace/Tools.svelte | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/lib/components/workspace/Tools.svelte b/src/lib/components/workspace/Tools.svelte index 837ba62dc..d8738c9fb 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, exportTools, getTools } from '$lib/apis/tools'; + import { createNewTool, deleteToolById, exportTools, getTools } from '$lib/apis/tools'; const i18n = getContext('i18n'); @@ -186,8 +186,18 @@ const reader = new FileReader(); reader.onload = async (event) => { - const tools = JSON.parse(event.target.result); - console.log(tools); + const _tools = JSON.parse(event.target.result); + console.log(_tools); + + for (const tool of _tools) { + const res = await createNewTool(localStorage.token, tool).catch((error) => { + toast.error(error); + return null; + }); + } + + toast.success('Tool imported successfully'); + tools.set(await getTools(localStorage.token)); }; reader.readAsText(importFiles[0]);