diff --git a/backend/open_webui/models/skills.py b/backend/open_webui/models/skills.py index 5bc8b54efc..522e1304c3 100644 --- a/backend/open_webui/models/skills.py +++ b/backend/open_webui/models/skills.py @@ -259,7 +259,26 @@ class SkillsTable: permission='read', ) - stmt = stmt.order_by(Skill.updated_at.desc()) + order_by = filter.get('order_by') + direction = filter.get('direction') + + if order_by == 'name': + if direction == 'asc': + stmt = stmt.order_by(Skill.name.asc()) + else: + stmt = stmt.order_by(Skill.name.desc()) + elif order_by == 'created_at': + if direction == 'asc': + stmt = stmt.order_by(Skill.created_at.asc()) + else: + stmt = stmt.order_by(Skill.created_at.desc()) + elif order_by == 'updated_at': + if direction == 'asc': + stmt = stmt.order_by(Skill.updated_at.asc()) + else: + stmt = stmt.order_by(Skill.updated_at.desc()) + else: + stmt = stmt.order_by(Skill.updated_at.desc()) # Count BEFORE pagination count_result = await db.execute(select(func.count()).select_from(stmt.subquery())) diff --git a/backend/open_webui/routers/skills.py b/backend/open_webui/routers/skills.py index 9af2d81573..4fefa2cb7a 100644 --- a/backend/open_webui/routers/skills.py +++ b/backend/open_webui/routers/skills.py @@ -72,6 +72,8 @@ async def get_skills( async def get_skill_list( query: Optional[str] = None, view_option: Optional[str] = None, + order_by: Optional[str] = None, + direction: Optional[str] = None, page: Optional[int] = 1, user=Depends(get_verified_user), db: AsyncSession = Depends(get_async_session), @@ -86,6 +88,10 @@ async def get_skill_list( filter['query'] = query if view_option: filter['view_option'] = view_option + if order_by: + filter['order_by'] = order_by + if direction: + filter['direction'] = direction if not (user.role == 'admin' and BYPASS_ADMIN_ACCESS_CONTROL): groups = await Groups.get_groups_by_member_id(user.id, db=db) diff --git a/src/lib/apis/skills/index.ts b/src/lib/apis/skills/index.ts index 24139fa042..fc1dc24ce1 100644 --- a/src/lib/apis/skills/index.ts +++ b/src/lib/apis/skills/index.ts @@ -97,7 +97,9 @@ export const getSkillItems = async ( token: string = '', query: string | null = null, viewOption: string | null = null, - page: number | null = null + page: number | null = null, + orderBy: string | null = null, + direction: string | null = null ) => { let error = null; @@ -105,6 +107,8 @@ export const getSkillItems = async ( if (query) searchParams.append('query', query); if (viewOption) searchParams.append('view_option', viewOption); if (page) searchParams.append('page', page.toString()); + if (orderBy) searchParams.append('order_by', orderBy); + if (direction) searchParams.append('direction', direction); const res = await fetch(`${WEBUI_API_BASE_URL}/skills/list?${searchParams.toString()}`, { method: 'GET',