From 44b71f87ab0433db9f9376d685653ff516c4e7e5 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sat, 10 Oct 2026 14:18:09 +0400 Subject: [PATCH] refac --- .../Models/LocalizedPromptSuggestions.svelte | 17 +- .../workspace/Models/ModelEditor.svelte | 87 +++-- .../workspace/Models/PromptSuggestions.svelte | 321 +++++++++--------- src/lib/i18n/locales/en-US/translation.json | 8 +- 4 files changed, 222 insertions(+), 211 deletions(-) diff --git a/src/lib/components/workspace/Models/LocalizedPromptSuggestions.svelte b/src/lib/components/workspace/Models/LocalizedPromptSuggestions.svelte index cf02fee0aa..f7d9baf4d6 100644 --- a/src/lib/components/workspace/Models/LocalizedPromptSuggestions.svelte +++ b/src/lib/components/workspace/Models/LocalizedPromptSuggestions.svelte @@ -9,6 +9,7 @@ export let locale = ''; export let localeLabel = ''; export let onChange = () => {}; + export let disabled = false; const clone = (value) => JSON.parse(JSON.stringify(value ?? [])); @@ -47,32 +48,30 @@ {#if !locale} - onChange()}> + onChange()}> {:else} - + {#if hasCustomLocalePrompts} {/if} - + diff --git a/src/lib/components/workspace/Models/ModelEditor.svelte b/src/lib/components/workspace/Models/ModelEditor.svelte index 004cf0e843..fc964c0017 100644 --- a/src/lib/components/workspace/Models/ModelEditor.svelte +++ b/src/lib/components/workspace/Models/ModelEditor.svelte @@ -120,6 +120,7 @@ let showSystemPrompt = true; let showAdvanced = false; let showPreview = false; + let customPromptDraft: any[] | null = null; let showAccessControlModal = false; let loaded = false; @@ -584,6 +585,7 @@ }; const loadModel = async (value: any) => { + customPromptDraft = null; model = value ? structuredClone(value) : null; backgroundFile = null; avatarFile = null; @@ -970,7 +972,7 @@ -
+
- {#if (info?.meta?.suggestion_prompts ?? null) === null} - {$i18n.t('Default')} - {:else} - {$i18n.t('Custom')} - {/if} - + + {:else} +
+ {$i18n.t('Using default prompt suggestions')} + +
{/if} -
- - {#if editingLocale} - - {:else if info?.meta?.suggestion_prompts} - - {/if} +
diff --git a/src/lib/components/workspace/Models/PromptSuggestions.svelte b/src/lib/components/workspace/Models/PromptSuggestions.svelte index 96e2feb6e6..5abdad155f 100644 --- a/src/lib/components/workspace/Models/PromptSuggestions.svelte +++ b/src/lib/components/workspace/Models/PromptSuggestions.svelte @@ -1,21 +1,23 @@ -
-
-
- {$i18n.t('Default Prompt Suggestions')} -
+
+ { + const files = e.target.files; + if (!files || files.length === 0) { + return; + } -
- - { - const files = e.target.files; - if (!files || files.length === 0) { - return; - } + let reader = new FileReader(); + reader.onload = async (event) => { + try { + let suggestions = JSON.parse(event.target.result); + if ( + !Array.isArray(suggestions) || + suggestions.some( + (s) => + !s || + typeof s.content !== 'string' || + (s.title != null && + typeof s.title !== 'string' && + (!Array.isArray(s.title) || s.title.some((part) => typeof part !== 'string'))) + ) + ) + throw new Error('Invalid prompt suggestions'); - let reader = new FileReader(); - reader.onload = async (event) => { - try { - let suggestions = JSON.parse(event.target.result); - if ( - !Array.isArray(suggestions) || - suggestions.some( - (s) => - !s || - typeof s.content !== 'string' || - (s.title != null && - typeof s.title !== 'string' && - (!Array.isArray(s.title) || s.title.some((part) => typeof part !== 'string'))) - ) - ) - throw new Error('Invalid prompt suggestions'); - - suggestions = suggestions.map((s) => { - if (typeof s.title === 'string') { - s.title = [s.title, '']; - } else if (!Array.isArray(s.title)) { - s.title = ['', '']; - } - - return s; - }); - - updateSuggestions([...promptSuggestions, ...suggestions]); - } catch (error) { - toast.error($i18n.t('Invalid JSON file')); - return; + suggestions = suggestions.map((s) => { + if (typeof s.title === 'string') { + s.title = [s.title, '']; + } else if (!Array.isArray(s.title)) { + s.title = ['', '']; } - }; - reader.readAsText(files[0]); + return s; + }); - e.target.value = ''; // Reset the input value - }} - /> + updateSuggestions([...promptSuggestions, ...suggestions]); + } catch (error) { + toast.error($i18n.t('Invalid JSON file')); + return; + } + }; - + reader.readAsText(files[0]); - {#if promptSuggestions.length} - + +
+
+ - {$i18n.t('Export')} - - {/if} - - - - -
-
- - {#if _promptSuggestions.length > 0} -
- {#each _promptSuggestions as prompt, promptIdx} -
-
-
- - { - prompt.title[0] = e.currentTarget.value; - updateSuggestions(_promptSuggestions); - }} - /> - - - - { - prompt.title[1] = e.currentTarget.value; - updateSuggestions(_promptSuggestions); - }} - /> - -
- - - - -
- - + /> + + {/each}
- {/each} +
{:else} -
+

{$i18n.t('No suggestion prompts')} +

+ {/each} +
+ +
+ + + +
- {/if} +
diff --git a/src/lib/i18n/locales/en-US/translation.json b/src/lib/i18n/locales/en-US/translation.json index 9a483cc434..d91fcdbda7 100644 --- a/src/lib/i18n/locales/en-US/translation.json +++ b/src/lib/i18n/locales/en-US/translation.json @@ -3820,5 +3820,11 @@ "Default terminal": "Default terminal", "No terminal servers available": "No terminal servers available", "Add tools in the Tools workspace or connect a tool server.": "Add tools in the Tools workspace or connect a tool server.", - "Used in native function calling mode. Workspace settings and user permissions still apply.": "Used in native function calling mode. Workspace settings and user permissions still apply." + "Used in native function calling mode. Workspace settings and user permissions still apply.": "Used in native function calling mode. Workspace settings and user permissions still apply.", + "Prompt actions": "Prompt actions", + "Write a prompt…": "Write a prompt…", + "Display text": "Display text", + "Add prompt": "Add prompt", + "Using default prompt suggestions": "Using default prompt suggestions", + "Customize": "Customize" }