From ef975649b26d3e7cd589c49be2fc77cee80fad8f Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Tue, 19 May 2026 20:19:23 +0400 Subject: [PATCH] refac --- .../admin/Functions/FunctionEditor.svelte | 12 ++++- .../workspace/Skills/SkillEditor.svelte | 54 ++++--------------- .../workspace/Tools/ToolkitEditor.svelte | 12 ++++- 3 files changed, 33 insertions(+), 45 deletions(-) diff --git a/src/lib/components/admin/Functions/FunctionEditor.svelte b/src/lib/components/admin/Functions/FunctionEditor.svelte index 6c84dd35d4..eca65e929f 100644 --- a/src/lib/components/admin/Functions/FunctionEditor.svelte +++ b/src/lib/components/admin/Functions/FunctionEditor.svelte @@ -4,7 +4,7 @@ const i18n = getContext('i18n'); - import { nameToId } from '$lib/utils'; + import { extractFrontmatter, formatSkillName, nameToId } from '$lib/utils'; import CodeEditor from '$lib/components/common/CodeEditor.svelte'; import ConfirmDialog from '$lib/components/common/ConfirmDialog.svelte'; import Badge from '$lib/components/common/Badge.svelte'; @@ -375,6 +375,16 @@ class Pipe: {boilerplate} onChange={(e) => { _content = e; + if (!edit) { + const fm = extractFrontmatter(e); + if (fm.title && !name) { + name = formatSkillName(fm.title); + id = nameToId(fm.title); + } + if (fm.description && !meta.description) { + meta = { ...meta, description: fm.description }; + } + } }} onSave={async () => { if (formElement) { diff --git a/src/lib/components/workspace/Skills/SkillEditor.svelte b/src/lib/components/workspace/Skills/SkillEditor.svelte index 7537ec45e7..79c0158229 100644 --- a/src/lib/components/workspace/Skills/SkillEditor.svelte +++ b/src/lib/components/workspace/Skills/SkillEditor.svelte @@ -30,47 +30,21 @@ let accessGrants = []; let showAccessControlModal = false; - let hasManualEdit = false; - let hasManualName = false; - let hasManualDescription = false; - let isFrontmatterDetected = false; + $: if (!edit && !clone && name) { + id = slugify(name); + } - // Auto-detect frontmatter and fill name/description in create mode - $: if (!edit && content) { + const handleContentInput = () => { + if (edit) return; const fm = parseFrontmatter(content); - if (fm.name) { - isFrontmatterDetected = true; - if (!hasManualName) { - name = formatSkillName(fm.name); - } - if (!hasManualEdit) { - id = fm.name; - } - } else { - isFrontmatterDetected = false; + if (fm.name && !name) { + name = formatSkillName(fm.name); + id = fm.name; } - if (fm.description && !hasManualDescription) { + if (fm.description && !description) { description = fm.description; } - } else if (!edit && !content) { - isFrontmatterDetected = false; - } - - $: if (!edit && !hasManualEdit && !isFrontmatterDetected) { - id = name !== '' ? slugify(name) : ''; - } - - function handleIdInput(e: Event) { - hasManualEdit = true; - } - - function handleNameInput(e: Event) { - hasManualName = true; - } - - function handleDescriptionInput(e: Event) { - hasManualDescription = true; - } + }; const submitHandler = async () => { if (disabled) { @@ -100,10 +74,6 @@ description = skill.description || ''; content = skill.content || ''; accessGrants = skill?.access_grants === undefined ? [] : skill?.access_grants; - - if (name) hasManualName = true; - if (description) hasManualDescription = true; - if (id) hasManualEdit = true; } }); @@ -156,7 +126,6 @@ placeholder={$i18n.t('Skill Name')} aria-label={$i18n.t('Skill Name')} bind:value={name} - on:input={handleNameInput} required {disabled} /> @@ -202,7 +171,6 @@ placeholder={$i18n.t('Skill ID')} aria-label={$i18n.t('Skill ID')} bind:value={id} - on:input={handleIdInput} required disabled={edit} /> @@ -220,7 +188,6 @@ placeholder={$i18n.t('Skill Description')} aria-label={$i18n.t('Skill Description')} bind:value={description} - on:input={handleDescriptionInput} {disabled} /> @@ -240,6 +207,7 @@