refactor: 简化 AgentScope 运行时模块与 prompt 系统

This commit is contained in:
zl-q
2026-03-15 17:14:15 +08:00
parent 61997f3613
commit 072c09d99d
32 changed files with 750 additions and 1863 deletions
+18 -12
View File
@@ -13,8 +13,9 @@ from core.agentscope.persistence.user_context_cache import (
)
from core.db.base_service import BaseService
from core.logging import get_logger
from schemas.user.context import UserContext, parse_profile_settings
from v1.users.repository import UserRepository
from v1.users.schemas import UserResponse, UserSearchRequest, UserUpdateRequest
from v1.users.schemas import UserSearchRequest, UserUpdateRequest
if TYPE_CHECKING:
from sqlalchemy.ext.asyncio import AsyncSession
@@ -82,7 +83,7 @@ class UserService(BaseService):
user_context_cache or create_user_context_cache(),
)
async def get_me(self) -> UserResponse:
async def get_me(self) -> UserContext:
user_id = self.require_user_id()
try:
user = await self._repository.get_by_user_id(user_id)
@@ -92,12 +93,13 @@ class UserService(BaseService):
if user is None:
raise HTTPException(status_code=404, detail="User not found")
email = self._current_user.email if self._current_user else None
return UserResponse(
return UserContext(
id=str(user.id),
username=user.username,
email=email,
avatar_url=user.avatar_url,
bio=user.bio,
settings=parse_profile_settings(user.settings),
)
async def get_user_by_id(self, user_id: UUID) -> "UserContext":
@@ -116,7 +118,7 @@ class UserService(BaseService):
avatar_url=profile.avatar_url,
)
async def update_me(self, update: UserUpdateRequest) -> UserResponse:
async def update_me(self, update: UserUpdateRequest) -> UserContext:
user_id = self.require_user_id()
update_data: dict[str, str | None] = {
key: value
@@ -151,15 +153,16 @@ class UserService(BaseService):
)
email = self._current_user.email if self._current_user else None
return UserResponse(
return UserContext(
id=str(user.id),
username=user.username,
email=email,
avatar_url=user.avatar_url,
bio=user.bio,
settings=parse_profile_settings(user.settings),
)
async def get_by_username(self, username: str) -> UserResponse:
async def get_by_username(self, username: str) -> UserContext:
try:
user = await self._repository.get_by_username(username)
except SQLAlchemyError:
@@ -167,14 +170,15 @@ class UserService(BaseService):
if user is None:
raise HTTPException(status_code=404, detail="User not found")
return UserResponse(
return UserContext(
id=str(user.id),
username=user.username,
avatar_url=user.avatar_url,
bio=user.bio,
settings=parse_profile_settings(user.settings),
)
async def search_users(self, request: UserSearchRequest) -> list[UserResponse]:
async def search_users(self, request: UserSearchRequest) -> list[UserContext]:
query = request.query.strip()
if _EMAIL_PATTERN.match(query):
@@ -182,7 +186,7 @@ class UserService(BaseService):
return await self._search_by_username(query)
async def _search_by_email(self, email: str) -> list[UserResponse]:
async def _search_by_email(self, email: str) -> list[UserContext]:
if self._auth_gateway is None:
raise HTTPException(status_code=503, detail="Auth lookup unavailable")
@@ -199,26 +203,28 @@ class UserService(BaseService):
return []
return [
UserResponse(
UserContext(
id=str(user.id),
username=user.username,
avatar_url=user.avatar_url,
bio=user.bio,
settings=parse_profile_settings(user.settings),
)
]
async def _search_by_username(self, query: str) -> list[UserResponse]:
async def _search_by_username(self, query: str) -> list[UserContext]:
try:
users = await self._repository.search_users(query, limit=20)
except SQLAlchemyError:
raise HTTPException(status_code=503, detail="User store unavailable")
return [
UserResponse(
UserContext(
id=str(user.id),
username=user.username,
avatar_url=user.avatar_url,
bio=user.bio,
settings=parse_profile_settings(user.settings),
)
for user in users
]