This commit is contained in:
Timothy J. Baek 2024-06-10 22:10:53 -07:00
parent c961964647
commit 8464b30485
4 changed files with 40 additions and 6 deletions

View File

@ -80,6 +80,8 @@ async def create_new_toolkit(form_data: ToolForm, user=Depends(get_admin_user)):
detail="Only alphanumeric characters and underscores are allowed in the id", detail="Only alphanumeric characters and underscores are allowed in the id",
) )
form_data.id = form_data.id.lower()
toolkit = Tools.get_tool_by_id(form_data.id) toolkit = Tools.get_tool_by_id(form_data.id)
if toolkit == None: if toolkit == None:
toolkit_path = os.path.join(TOOLS_DIR, f"{form_data.id}.py") toolkit_path = os.path.join(TOOLS_DIR, f"{form_data.id}.py")
@ -151,7 +153,7 @@ async def update_toolkit_by_id(
specs = get_tools_specs(TOOLS[id]) specs = get_tools_specs(TOOLS[id])
updated = { updated = {
**form_data.model_dump(), **form_data.model_dump(exclude={"id"}),
"specs": specs, "specs": specs,
} }

View File

@ -8,7 +8,13 @@
import { createNewPrompt, deletePromptByCommand, getPrompts } from '$lib/apis/prompts'; import { createNewPrompt, deletePromptByCommand, getPrompts } from '$lib/apis/prompts';
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { createNewTool, deleteToolById, exportTools, getTools } from '$lib/apis/tools'; import {
createNewTool,
deleteToolById,
exportTools,
getToolById,
getTools
} from '$lib/apis/tools';
const i18n = getContext('i18n'); const i18n = getContext('i18n');
@ -121,9 +127,20 @@
<button <button
class="self-center w-fit text-sm px-2 py-2 dark:text-gray-300 dark:hover:text-white hover:bg-black/5 dark:hover:bg-white/5 rounded-xl" class="self-center w-fit text-sm px-2 py-2 dark:text-gray-300 dark:hover:text-white hover:bg-black/5 dark:hover:bg-white/5 rounded-xl"
type="button" type="button"
on:click={() => { on:click={async () => {
sessionStorage.tool = JSON.stringify(tool); const _tool = await getToolById(localStorage.token, tool.id).catch((error) => {
goto('/workspace/tools/create'); toast.error(error);
return null;
});
if (_tool) {
sessionStorage.tool = JSON.stringify({
..._tool,
id: `${_tool.id}_clone`,
name: `${_tool.name} (Clone)`
});
goto('/workspace/tools/create');
}
}} }}
> >
<svg <svg

View File

@ -9,7 +9,6 @@
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
let formElement = null; let formElement = null;
let loading = false; let loading = false;
export let edit = false; export let edit = false;

View File

@ -3,8 +3,11 @@
import { createNewTool, getTools } from '$lib/apis/tools'; import { createNewTool, getTools } from '$lib/apis/tools';
import ToolkitEditor from '$lib/components/workspace/Tools/ToolkitEditor.svelte'; import ToolkitEditor from '$lib/components/workspace/Tools/ToolkitEditor.svelte';
import { tools } from '$lib/stores'; import { tools } from '$lib/stores';
import { onMount } from 'svelte';
import { toast } from 'svelte-sonner'; import { toast } from 'svelte-sonner';
let tool = null;
const saveHandler = async (data) => { const saveHandler = async (data) => {
console.log(data); console.log(data);
const res = await createNewTool(localStorage.token, { const res = await createNewTool(localStorage.token, {
@ -24,9 +27,22 @@
await goto('/workspace/tools'); await goto('/workspace/tools');
} }
}; };
onMount(() => {
console.log('mounted');
if (sessionStorage.tool) {
tool = JSON.parse(sessionStorage.tool);
sessionStorage.removeItem('tool');
}
});
</script> </script>
<ToolkitEditor <ToolkitEditor
id={tool?.id ?? ''}
name={tool?.name ?? ''}
meta={tool?.meta ?? { description: '' }}
content={tool?.content ?? ''}
on:save={(e) => { on:save={(e) => {
saveHandler(e.detail); saveHandler(e.detail);
}} }}