{"version":3,"file":"15.CoD7HNM9.js","sources":["../../../../../../src/routes/(app)/workspace/functions/edit/+page.svelte"],"sourcesContent":["<script>\n\timport { toast } from 'svelte-sonner';\n\timport { onMount, getContext } from 'svelte';\n\n\timport { goto } from '$app/navigation';\n\timport { page } from '$app/stores';\n\timport { functions, models } from '$lib/stores';\n\timport { updateFunctionById, getFunctions, getFunctionById } from '$lib/apis/functions';\n\n\timport FunctionEditor from '$lib/components/workspace/Functions/FunctionEditor.svelte';\n\timport Spinner from '$lib/components/common/Spinner.svelte';\n\timport { getModels } from '$lib/apis';\n\timport { compareVersion, extractFrontmatter } from '$lib/utils';\n\timport { WEBUI_VERSION } from '$lib/constants';\n\n\tconst i18n = getContext('i18n');\n\n\tlet func = null;\n\n\tconst saveHandler = async (data) => {\n\t\tconsole.log(data);\n\n\t\tconst manifest = extractFrontmatter(data.content);\n\t\tif (compareVersion(manifest?.required_open_webui_version ?? '0.0.0', WEBUI_VERSION)) {\n\t\t\tconsole.log('Version is lower than required');\n\t\t\ttoast.error(\n\t\t\t\t$i18n.t(\n\t\t\t\t\t'Open WebUI version (v{{OPEN_WEBUI_VERSION}}) is lower than required version (v{{REQUIRED_VERSION}})',\n\t\t\t\t\t{\n\t\t\t\t\t\tOPEN_WEBUI_VERSION: WEBUI_VERSION,\n\t\t\t\t\t\tREQUIRED_VERSION: manifest?.required_open_webui_version ?? '0.0.0'\n\t\t\t\t\t}\n\t\t\t\t)\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst res = await updateFunctionById(localStorage.token, func.id, {\n\t\t\tid: data.id,\n\t\t\tname: data.name,\n\t\t\tmeta: data.meta,\n\t\t\tcontent: data.content\n\t\t}).catch((error) => {\n\t\t\ttoast.error(error);\n\t\t\treturn null;\n\t\t});\n\n\t\tif (res) {\n\t\t\ttoast.success($i18n.t('Function updated successfully'));\n\t\t\tfunctions.set(await getFunctions(localStorage.token));\n\t\t\tmodels.set(await getModels(localStorage.token));\n\t\t}\n\t};\n\n\tonMount(async () => {\n\t\tconsole.log('mounted');\n\t\tconst id = $page.url.searchParams.get('id');\n\n\t\tif (id) {\n\t\t\tfunc = await getFunctionById(localStorage.token, id).catch((error) => {\n\t\t\t\ttoast.error(error);\n\t\t\t\tgoto('/workspace/functions');\n\t\t\t\treturn null;\n\t\t\t});\n\n\t\t\tconsole.log(func);\n\t\t}\n\t});\n</script>\n\n{#if func}\n\t<FunctionEditor\n\t\tedit={true}\n\t\tid={func.id}\n\t\tname={func.name}\n\t\tmeta={func.meta}\n\t\tcontent={func.content}\n\t\ton:save={(e) => {\n\t\t\tsaveHandler(e.detail);\n\t\t}}\n\t/>\n{:else}\n\t<div class=\"flex items-center justify-center h-full\">\n\t\t<div class=\" pb-16\">\n\t\t\t<Spinner />\n\t\t</div>\n\t</div>\n{/if}\n"],"names":["insert_hydration","target","div1","anchor","append_hydration","div0","ctx","dirty","functioneditor_changes","i18n","getContext","func","saveHandler","data","manifest","extractFrontmatter","compareVersion","WEBUI_VERSION","toast","$i18n","updateFunctionById","error","functions","getFunctions","models","getModels","onMount","id","$page","getFunctionById","goto","e"],"mappings":"mjCAkFCA,EAIKC,EAAAC,EAAAC,CAAA,EAHJC,EAEKF,EAAAG,CAAA,+JAbC,GACF,GAAAC,KAAK,GACH,KAAAA,KAAK,KACL,KAAAA,KAAK,KACF,QAAAA,KAAK,sHAHVC,EAAA,IAAAC,EAAA,GAAAF,KAAK,IACHC,EAAA,IAAAC,EAAA,KAAAF,KAAK,MACLC,EAAA,IAAAC,EAAA,KAAAF,KAAK,MACFC,EAAA,IAAAC,EAAA,QAAAF,KAAK,uKANXA,EAAI,CAAA,EAAA,8WAvDFG,EAAOC,EAAW,MAAM,qBAE1B,IAAAC,EAAO,KAEL,MAAAC,QAAqBC,GAAI,CAC9B,QAAQ,IAAIA,CAAI,EAEV,MAAAC,EAAWC,EAAmBF,EAAK,OAAO,EAC5C,GAAAG,GAAeF,GAAA,YAAAA,EAAU,8BAA+B,QAASG,CAAa,EAAA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