From b875efab1f463bb719a14364f2fe204133e33bde Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Mon, 1 Jul 2024 16:50:35 -0700 Subject: [PATCH] enh: validate required open webui version --- .../(app)/workspace/functions/create/+page.svelte | 10 ++++++++++ src/routes/(app)/workspace/functions/edit/+page.svelte | 10 ++++++++++ src/routes/(app)/workspace/tools/create/+page.svelte | 10 ++++++++++ src/routes/(app)/workspace/tools/edit/+page.svelte | 10 ++++++++++ 4 files changed, 40 insertions(+) diff --git a/src/routes/(app)/workspace/functions/create/+page.svelte b/src/routes/(app)/workspace/functions/create/+page.svelte index 49711b8ae..02e108e55 100644 --- a/src/routes/(app)/workspace/functions/create/+page.svelte +++ b/src/routes/(app)/workspace/functions/create/+page.svelte @@ -7,6 +7,8 @@ import { createNewFunction, getFunctions } from '$lib/apis/functions'; import FunctionEditor from '$lib/components/workspace/Functions/FunctionEditor.svelte'; import { getModels } from '$lib/apis'; + import { compareVersion, extractFrontmatter } from '$lib/utils'; + import { WEBUI_VERSION } from '$lib/constants'; const i18n = getContext('i18n'); @@ -16,6 +18,14 @@ const saveHandler = async (data) => { console.log(data); + + const manifest = extractFrontmatter(data.content); + if (compareVersion(manifest?.required_open_webui_version ?? '0.0.0', WEBUI_VERSION)) { + console.log('Version is lower than required'); + toast.error($i18n.t('Open WebUI version is lower than required version')); + return; + } + const res = await createNewFunction(localStorage.token, { id: data.id, name: data.name, diff --git a/src/routes/(app)/workspace/functions/edit/+page.svelte b/src/routes/(app)/workspace/functions/edit/+page.svelte index c54b38fa5..7c60e70c6 100644 --- a/src/routes/(app)/workspace/functions/edit/+page.svelte +++ b/src/routes/(app)/workspace/functions/edit/+page.svelte @@ -10,6 +10,8 @@ import FunctionEditor from '$lib/components/workspace/Functions/FunctionEditor.svelte'; import Spinner from '$lib/components/common/Spinner.svelte'; import { getModels } from '$lib/apis'; + import { compareVersion, extractFrontmatter } from '$lib/utils'; + import { WEBUI_VERSION } from '$lib/constants'; const i18n = getContext('i18n'); @@ -17,6 +19,14 @@ const saveHandler = async (data) => { console.log(data); + + const manifest = extractFrontmatter(data.content); + if (compareVersion(manifest?.required_open_webui_version ?? '0.0.0', WEBUI_VERSION)) { + console.log('Version is lower than required'); + toast.error($i18n.t('Open WebUI version is lower than required version')); + return; + } + const res = await updateFunctionById(localStorage.token, func.id, { id: data.id, name: data.name, diff --git a/src/routes/(app)/workspace/tools/create/+page.svelte b/src/routes/(app)/workspace/tools/create/+page.svelte index a3e243c21..0f0b90cbd 100644 --- a/src/routes/(app)/workspace/tools/create/+page.svelte +++ b/src/routes/(app)/workspace/tools/create/+page.svelte @@ -2,7 +2,9 @@ import { goto } from '$app/navigation'; import { createNewTool, getTools } from '$lib/apis/tools'; import ToolkitEditor from '$lib/components/workspace/Tools/ToolkitEditor.svelte'; + import { WEBUI_VERSION } from '$lib/constants'; import { tools } from '$lib/stores'; + import { compareVersion, extractFrontmatter } from '$lib/utils'; import { onMount, getContext } from 'svelte'; import { toast } from 'svelte-sonner'; @@ -14,6 +16,14 @@ const saveHandler = async (data) => { console.log(data); + + const manifest = extractFrontmatter(data.content); + if (compareVersion(manifest?.required_open_webui_version ?? '0.0.0', WEBUI_VERSION)) { + console.log('Version is lower than required'); + toast.error($i18n.t('Open WebUI version is lower than required version')); + return; + } + const res = await createNewTool(localStorage.token, { id: data.id, name: data.name, diff --git a/src/routes/(app)/workspace/tools/edit/+page.svelte b/src/routes/(app)/workspace/tools/edit/+page.svelte index aaa5fb836..48803db54 100644 --- a/src/routes/(app)/workspace/tools/edit/+page.svelte +++ b/src/routes/(app)/workspace/tools/edit/+page.svelte @@ -4,7 +4,9 @@ import { getToolById, getTools, updateToolById } from '$lib/apis/tools'; import Spinner from '$lib/components/common/Spinner.svelte'; import ToolkitEditor from '$lib/components/workspace/Tools/ToolkitEditor.svelte'; + import { WEBUI_VERSION } from '$lib/constants'; import { tools } from '$lib/stores'; + import { compareVersion, extractFrontmatter } from '$lib/utils'; import { onMount, getContext } from 'svelte'; import { toast } from 'svelte-sonner'; @@ -14,6 +16,14 @@ const saveHandler = async (data) => { console.log(data); + + const manifest = extractFrontmatter(data.content); + if (compareVersion(manifest?.required_open_webui_version ?? '0.0.0', WEBUI_VERSION)) { + console.log('Version is lower than required'); + toast.error($i18n.t('Open WebUI version is lower than required version')); + return; + } + const res = await updateToolById(localStorage.token, tool.id, { id: data.id, name: data.name,