From 6ab7d549829ce1a864f113a95f666ba17826daec Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sat, 24 Jan 2026 02:51:44 +0400 Subject: [PATCH] refac --- backend/open_webui/models/prompts.py | 10 ++- .../workspace/Prompts/PromptEditor.svelte | 74 +++++++------------ 2 files changed, 33 insertions(+), 51 deletions(-) diff --git a/backend/open_webui/models/prompts.py b/backend/open_webui/models/prompts.py index 42d724c65d..22ad884bb1 100644 --- a/backend/open_webui/models/prompts.py +++ b/backend/open_webui/models/prompts.py @@ -89,6 +89,7 @@ class PromptForm(BaseModel): access_control: Optional[dict] = None version_id: Optional[str] = None # Active version commit_message: Optional[str] = None # For history tracking + is_production: Optional[bool] = True # Whether to set new version as production class PromptsTable: @@ -252,8 +253,6 @@ class PromptsTable: prompt.data = form_data.data or prompt.data prompt.meta = form_data.meta or prompt.meta prompt.access_control = form_data.access_control - if form_data.version_id is not None: - prompt.version_id = form_data.version_id prompt.updated_at = int(time.time()) db.commit() @@ -269,7 +268,7 @@ class PromptsTable: "access_control": form_data.access_control, } - PromptHistories.create_history_entry( + history_entry = PromptHistories.create_history_entry( prompt_id=prompt.id, snapshot=snapshot, user_id=user_id, @@ -277,6 +276,11 @@ class PromptsTable: commit_message=form_data.commit_message, db=db, ) + + # Set as production if flag is True (default) + if form_data.is_production and history_entry: + prompt.version_id = history_entry.id + db.commit() return PromptModel.model_validate(prompt) except Exception: diff --git a/src/lib/components/workspace/Prompts/PromptEditor.svelte b/src/lib/components/workspace/Prompts/PromptEditor.svelte index ddb56dada6..dbc3997d8d 100644 --- a/src/lib/components/workspace/Prompts/PromptEditor.svelte +++ b/src/lib/components/workspace/Prompts/PromptEditor.svelte @@ -39,6 +39,7 @@ let command = ''; let content = ''; let commitMessage = ''; + let isProduction = true; let accessControl = {}; let showAccessControlModal = false; @@ -69,10 +70,12 @@ command, content, access_control: accessControl, - commit_message: commitMessage || undefined + commit_message: commitMessage || undefined, + is_production: isProduction }); showEditModal = false; commitMessage = ''; + isProduction = true; await loadHistory(); } else { toast.error( @@ -183,35 +186,6 @@
-
- -
-
- -
-
-
/
- -
-
-
-
-
{$i18n.t('Prompt Content')}
@@ -225,27 +199,30 @@ rows={6} required /> - -
- ⓘ {$i18n.t('Format your variables using brackets like this:')} {'{{'}{$i18n.t('variable')}{'}}'}. - {$i18n.t('Make sure to enclose them with')} - {'{{'} - {$i18n.t('and')} - {'}}'}. -
- -
-
+
+
{$i18n.t('Commit Message')} ({$i18n.t('optional')})
+
+ +
+
+ +
+ +