diff --git a/src/routes/tools/ToolEdit.svelte b/src/routes/tools/ToolEdit.svelte index 6d54bb0f53a..5b6bb0b79aa 100644 --- a/src/routes/tools/ToolEdit.svelte +++ b/src/routes/tools/ToolEdit.svelte @@ -27,7 +27,8 @@ return returnForm?.errors.find((error) => error.field === field)?.message ?? ""; } - let loading = false; + let APIloading = false; + let formLoading = false; const dispatch = createEventDispatcher<{ close: void }>(); onMount(async () => { @@ -56,6 +57,9 @@ return; } + form = { error: false, errors: [] }; + APIloading = true; + const api = await getGradioApi(editableTool.baseUrl); const newInputs = api.named_endpoints[editableTool.endpoint].parameters.map((param, idx) => { @@ -87,9 +91,28 @@ }); editableTool.inputs = newInputs; - editableTool.outputComponent = ToolOutputComponents.parse( - api.named_endpoints[editableTool.endpoint].returns[0].component + const parsedOutputComponent = ToolOutputComponents.safeParse( + api.named_endpoints[editableTool.endpoint].returns?.[0]?.component ?? null ); + + if (parsedOutputComponent.success) { + editableTool.outputComponent = parsedOutputComponent.data; + } else { + form = { + error: true, + errors: [ + { + field: "outputComponent", + message: `Invalid output component. Type ${ + api.named_endpoints[editableTool.endpoint].returns?.[0]?.component + } is not yet supported. Feel free to report this issue so we can add support for it.`, + }, + ], + }; + editableTool.outputComponent = null; + } + + APIloading = false; } async function onEndpointChange(e: Event) { @@ -119,10 +142,11 @@ method="POST" class="relative flex h-full flex-col overflow-y-auto p-4 md:p-8" use:enhance={async ({ formData }) => { + formLoading = true; formData.append("tool", JSON.stringify(editableTool)); return async ({ result }) => { - loading = false; + formLoading = false; await applyAction(result); }; }} @@ -242,9 +266,9 @@ {#await getGradioApi(spaceUrl)}
Loading...
{:then api} -Loading API...
{/if} {:catch error}{error}
@@ -486,12 +521,12 @@ {#if !readonly} {/if}