From b6cf23f33246adeda65edbb559a6e0f1e6a3b2f9 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sun, 13 Sep 2026 23:34:35 -0400 Subject: [PATCH] refac --- backend/open_webui/utils/middleware.py | 8 ++++++-- backend/open_webui/utils/skills.py | 26 -------------------------- backend/open_webui/utils/terminals.py | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 28 deletions(-) delete mode 100644 backend/open_webui/utils/skills.py diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 83ab30eb08..8cdbec9cc0 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -2808,8 +2808,12 @@ async def process_chat_payload(request, form_data, user, metadata, model): import aiohttp from open_webui.env import AIOHTTP_CLIENT_SESSION_TOOL_SERVER_SSL, AIOHTTP_CLIENT_TIMEOUT_TOOL_SERVER_DATA from open_webui.models.skills import Skills as SkillsModel - from open_webui.utils.skills import format_terminal_skill_context, format_terminal_skill_manifest_entry - from open_webui.utils.terminals import get_terminal_request_info, get_terminal_skill + from open_webui.utils.terminals import ( + format_terminal_skill_context, + format_terminal_skill_manifest_entry, + get_terminal_request_info, + get_terminal_skill, + ) terminal_skill_prefix = 'terminal:' db_skill_ids = [sid for sid in skill_ids if not sid.startswith(terminal_skill_prefix)] diff --git a/backend/open_webui/utils/skills.py b/backend/open_webui/utils/skills.py deleted file mode 100644 index d3c743078b..0000000000 --- a/backend/open_webui/utils/skills.py +++ /dev/null @@ -1,26 +0,0 @@ -"""Shared helpers for model-facing skill prompts.""" - - -def format_terminal_skill_context(skill: dict) -> str: - resources = skill.get('resources') if isinstance(skill.get('resources'), list) else [] - parts = [f'', skill.get('content') or ''] - if skill.get('directory'): - parts.append(f'{skill["directory"]}') - if resources: - parts.append('') - parts.extend(f'{resource}' for resource in resources) - parts.append('') - parts.append('') - return '\n'.join(parts) - - -def format_terminal_skill_manifest_entry(skill: dict) -> str: - location = skill.get('location') or skill.get('path') or '' - location_tag = f'{location}\n' if location else '' - return ( - f'\n{skill["id"]}\n{skill["name"]}\n' - f'{skill.get("description") or ""}\n' - f'terminal\n' - f'{location_tag}' - f'\n' - ) diff --git a/backend/open_webui/utils/terminals.py b/backend/open_webui/utils/terminals.py index eef46bc470..9054c1f042 100644 --- a/backend/open_webui/utils/terminals.py +++ b/backend/open_webui/utils/terminals.py @@ -206,3 +206,27 @@ async def get_terminal_skill(request, user, metadata: dict, skill_name: str, ext 'resources': resources, } + +def format_terminal_skill_context(skill: dict) -> str: + resources = skill.get('resources') if isinstance(skill.get('resources'), list) else [] + parts = [f'', skill.get('content') or ''] + if skill.get('directory'): + parts.append(f'{skill["directory"]}') + if resources: + parts.append('') + parts.extend(f'{resource}' for resource in resources) + parts.append('') + parts.append('') + return '\n'.join(parts) + + +def format_terminal_skill_manifest_entry(skill: dict) -> str: + location = skill.get('location') or skill.get('path') or '' + location_tag = f'{location}\n' if location else '' + return ( + f'\n{skill["id"]}\n{skill["name"]}\n' + f'{skill.get("description") or ""}\n' + f'terminal\n' + f'{location_tag}' + f'\n' + )