From affe67b7df3944dfee6213e548b988f3af82df68 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 30 Nov 2026 21:27:41 +0400 Subject: [PATCH] refac --- backend/open_webui/models/automations.py | 13 +- backend/open_webui/routers/automations.py | 6 +- src/lib/apis/automations/index.ts | 9 +- .../Models/Manage/ManageOllama.svelte | 68 ++----- .../automations/AutomationEditor.svelte | 189 +++++++++++------- src/lib/i18n/locales/en-US/translation.json | 1 + 6 files changed, 161 insertions(+), 125 deletions(-) diff --git a/backend/open_webui/models/automations.py b/backend/open_webui/models/automations.py index 5d0d4bdf11..b989e47f58 100644 --- a/backend/open_webui/models/automations.py +++ b/backend/open_webui/models/automations.py @@ -641,13 +641,20 @@ class AutomationRunTable: skip: int = 0, limit: int = 50, direction: str = 'desc', + query: Optional[str] = None, + status: Optional[str] = None, db: Optional[AsyncSession] = None, ) -> list[AutomationRunModel]: order = AutomationRun.created_at.asc() if direction == 'asc' else AutomationRun.created_at.desc() async with get_async_db_context(db) as db: - result = await db.execute( - select(AutomationRun).filter_by(automation_id=automation_id).order_by(order).offset(skip).limit(limit) - ) + stmt = select(AutomationRun).filter_by(automation_id=automation_id) + if status: + stmt = stmt.filter(AutomationRun.status == status) + if query: + stmt = stmt.filter( + or_(AutomationRun.error.icontains(query, autoescape=True), AutomationRun.output.icontains(query, autoescape=True)) + ) + result = await db.execute(stmt.order_by(order).offset(skip).limit(limit)) rows = result.scalars().all() return [AutomationRunModel.model_validate(r) for r in rows] diff --git a/backend/open_webui/routers/automations.py b/backend/open_webui/routers/automations.py index bce651ebe1..a1557143aa 100644 --- a/backend/open_webui/routers/automations.py +++ b/backend/open_webui/routers/automations.py @@ -666,12 +666,16 @@ async def get_automation_runs( skip: int = 0, limit: int = 50, direction: Literal['asc', 'desc'] = 'desc', + query: Optional[str] = None, + status: Optional[Literal['success', 'error']] = None, user=Depends(get_verified_user), db: AsyncSession = Depends(get_async_session), ): await check_automations_permission(request, user) await get_accessible_automation(id, user, 'read', db) - return await AutomationRuns.get_by_automation(id, skip=skip, limit=limit, direction=direction, db=db) + return await AutomationRuns.get_by_automation( + id, skip=skip, limit=limit, direction=direction, query=query, status=status, db=db + ) @router.get('/{id}/runs/{run_id}', response_model=AutomationRunModel) diff --git a/src/lib/apis/automations/index.ts b/src/lib/apis/automations/index.ts index db466c34e2..a80a1b9d4c 100644 --- a/src/lib/apis/automations/index.ts +++ b/src/lib/apis/automations/index.ts @@ -440,12 +440,17 @@ export const getAutomationRuns = async ( id: string, skip: number = 0, limit: number = 50, - direction: 'asc' | 'desc' = 'desc' + direction: 'asc' | 'desc' = 'desc', + query: string = '', + status: '' | 'success' | 'error' = '' ) => { let error = null; + const params = new URLSearchParams({ skip: `${skip}`, limit: `${limit}`, direction }); + if (query) params.set('query', query); + if (status) params.set('status', status); const res = await fetch( - `${WEBUI_API_BASE_URL}/automations/${id}/runs?skip=${skip}&limit=${limit}&direction=${direction}`, + `${WEBUI_API_BASE_URL}/automations/${id}/runs?${params}`, { method: 'GET', headers: { diff --git a/src/lib/components/admin/Settings/Models/Manage/ManageOllama.svelte b/src/lib/components/admin/Settings/Models/Manage/ManageOllama.svelte index c5989c541c..d07daa139b 100644 --- a/src/lib/components/admin/Settings/Models/Manage/ManageOllama.svelte +++ b/src/lib/components/admin/Settings/Models/Manage/ManageOllama.svelte @@ -73,6 +73,7 @@ const updateModelsHandler = async () => { updateCancelled = false; + let failed = false; toast.info('Checking for model updates...'); for (const model of ollamaModels) { @@ -80,66 +81,39 @@ break; } - console.debug(model); - updateModelId = model.id; - const [res, controller] = await pullModel(localStorage.token, model.id, urlIdx).catch( - (error) => { - if (error.name !== 'AbortError') { - toast.error(`${error}`); - } - return [null, null]; - } - ); + try { + const [res, controller] = await pullModel(localStorage.token, model.id, urlIdx); + updateModelsControllers = { ...updateModelsControllers, [model.id]: controller }; - updateModelsControllers = { - ...updateModelsControllers, - [model.id]: controller - }; - - if (res) { const reader = res.body .pipeThrough(new TextDecoderStream()) .pipeThrough(splitStream('\n')) .getReader(); while (true) { - try { - const { value, done } = await reader.read(); - if (done) break; + const { value, done } = await reader.read(); + if (done) break; - let lines = value.split('\n'); + for (const line of value.split('\n')) { + if (line === '') continue; - for (const line of lines) { - if (line !== '') { - let data = JSON.parse(line); - - console.log(data); - if (data.error) { - throw data.error; - } - if (data.detail) { - throw data.detail; - } - if (data.status) { - if (data.digest) { - updateProgress = 0; - if (data.completed) { - updateProgress = Math.round((data.completed / data.total) * 1000) / 10; - } else { - updateProgress = 100; - } - } - } - } + const data = JSON.parse(line); + if (data.error || data.detail) { + throw data.error ?? data.detail; } - } catch (err) { - if (err.name !== 'AbortError') { - console.error(err); + if (data.status && data.digest) { + updateProgress = data.completed + ? Math.round((data.completed / data.total) * 1000) / 10 + : 100; } - break; } } + } catch (err) { + if (err.name !== 'AbortError') { + failed = true; + toast.error(`${model.id}: ${err}`); + } } delete updateModelsControllers[model.id]; @@ -148,7 +122,7 @@ if (updateCancelled) { toast.info('Model update cancelled'); - } else { + } else if (!failed) { toast.success('All models are up to date'); } updateModelId = null; diff --git a/src/lib/components/automations/AutomationEditor.svelte b/src/lib/components/automations/AutomationEditor.svelte index 741a9938a9..d7d87eff85 100644 --- a/src/lib/components/automations/AutomationEditor.svelte +++ b/src/lib/components/automations/AutomationEditor.svelte @@ -77,6 +77,7 @@ import LinkIcon from '$lib/components/icons/Link.svelte'; import WebhookDropdown from '$lib/components/automations/WebhookDropdown.svelte'; import InputVariablesModal from '$lib/components/chat/MessageInput/InputVariablesModal.svelte'; + import CodeEditor from '$lib/components/common/CodeEditor.svelte'; import CodeEditorModal from '$lib/components/common/CodeEditorModal.svelte'; import Cube from '$lib/components/icons/Cube.svelte'; import CodeBracket from '$lib/components/icons/CodeBracket.svelte'; @@ -128,6 +129,10 @@ void prompt; tick().then(measurePrompt); } + // Code shows in a small editor; a long program starts collapsed like a long prompt. + let showCode = false; + $: codeClamped = code.split('\n').length > 8; + onMount(() => { const observer = new ResizeObserver(measurePrompt); if (promptMeasureEl) observer.observe(promptMeasureEl); @@ -734,80 +739,10 @@ {#if selectedTab === 'overview'}
- {#if action_type !== 'code'} -
- -
- {#if showPrompt || !promptClamped} -