Merge pull request #73 from SuanmoSuanyangTechnology/feature/agent-tool_xjn
feat(home page and apps):
This commit is contained in:
@@ -48,6 +48,7 @@ def list_apps(
|
||||
include_shared: bool = True,
|
||||
page: int = 1,
|
||||
pagesize: int = 10,
|
||||
ids: Optional[str] = None,
|
||||
db: Session = Depends(get_db),
|
||||
current_user=Depends(get_current_user),
|
||||
):
|
||||
@@ -55,8 +56,19 @@ def list_apps(
|
||||
|
||||
- 默认包含本工作空间的应用和分享给本工作空间的应用
|
||||
- 设置 include_shared=false 可以只查看本工作空间的应用
|
||||
- 当提供 ids 参数时,按逗号分割获取指定应用,不分页
|
||||
"""
|
||||
workspace_id = current_user.current_workspace_id
|
||||
service = app_service.AppService(db)
|
||||
|
||||
# 当 ids 存在且不为 None 时,根据 ids 获取应用
|
||||
if ids is not None:
|
||||
app_ids = [id.strip() for id in ids.split(',') if id.strip()]
|
||||
items_orm = app_service.get_apps_by_ids(db, app_ids, workspace_id)
|
||||
items = [service._convert_to_schema(app, workspace_id) for app in items_orm]
|
||||
return success(data=items)
|
||||
|
||||
# 正常分页查询
|
||||
items_orm, total = app_service.list_apps(
|
||||
db,
|
||||
workspace_id=workspace_id,
|
||||
@@ -69,8 +81,6 @@ def list_apps(
|
||||
pagesize=pagesize,
|
||||
)
|
||||
|
||||
# 使用 AppService 的转换方法来设置 is_shared 字段
|
||||
service = app_service.AppService(db)
|
||||
items = [service._convert_to_schema(app, workspace_id) for app in items_orm]
|
||||
meta = PageMeta(page=page, pagesize=pagesize, total=total, hasnext=(page * pagesize) < total)
|
||||
return success(data=PageData(page=meta, items=items))
|
||||
|
||||
@@ -31,5 +31,8 @@ def get_workspace_list(
|
||||
|
||||
@router.get("/version", response_model=ApiResponse)
|
||||
def get_system_version():
|
||||
"""获取系统版本号"""
|
||||
return success(data={"version": settings.SYSTEM_VERSION}, msg="系统版本获取成功")
|
||||
"""获取系统版本号+说明"""
|
||||
return success(data={
|
||||
"version": settings.SYSTEM_VERSION,
|
||||
"introduction": settings.SYSTEM_INTRODUCTION
|
||||
}, msg="系统版本获取成功")
|
||||
@@ -166,7 +166,8 @@ class Settings:
|
||||
ENABLE_TOOL_MANAGEMENT: bool = os.getenv("ENABLE_TOOL_MANAGEMENT", "true").lower() == "true"
|
||||
|
||||
# official environment system version
|
||||
SYSTEM_VERSION: str = os.getenv("SYSTEM_VERSION", "v1.0.0")
|
||||
SYSTEM_VERSION: str = os.getenv("SYSTEM_VERSION", "v0.2.0")
|
||||
SYSTEM_INTRODUCTION: str = os.getenv("SYSTEM_INTRODUCTION", "")
|
||||
|
||||
def get_memory_output_path(self, filename: str = "") -> str:
|
||||
"""
|
||||
|
||||
@@ -812,6 +812,37 @@ class AppService:
|
||||
)
|
||||
return items, int(total)
|
||||
|
||||
def get_apps_by_ids(
|
||||
self,
|
||||
app_ids: List[str],
|
||||
workspace_id: uuid.UUID
|
||||
) -> List[App]:
|
||||
"""根据ID列表获取应用
|
||||
|
||||
Args:
|
||||
app_ids: 应用ID列表
|
||||
workspace_id: 工作空间ID(用于权限验证)
|
||||
|
||||
Returns:
|
||||
List[App]: 应用列表
|
||||
"""
|
||||
if not app_ids:
|
||||
return []
|
||||
|
||||
# 转换字符串ID为UUID
|
||||
try:
|
||||
uuid_ids = [uuid.UUID(app_id) for app_id in app_ids]
|
||||
except ValueError:
|
||||
return []
|
||||
|
||||
# 查询本工作空间的应用 + 分享给本工作空间的应用
|
||||
stmt = select(App).where(
|
||||
App.id.in_(uuid_ids),
|
||||
App.workspace_id == workspace_id
|
||||
)
|
||||
|
||||
return list(self.db.scalars(stmt).all())
|
||||
|
||||
# ==================== Agent 配置管理 ====================
|
||||
|
||||
def update_agent_config(
|
||||
@@ -2068,6 +2099,16 @@ def list_apps(
|
||||
)
|
||||
|
||||
|
||||
def get_apps_by_ids(
|
||||
db: Session,
|
||||
app_ids: List[str],
|
||||
workspace_id: uuid.UUID
|
||||
) -> List[App]:
|
||||
"""根据ID列表获取应用(向后兼容接口)"""
|
||||
service = AppService(db)
|
||||
return service.get_apps_by_ids(app_ids, workspace_id)
|
||||
|
||||
|
||||
# ==================== 向后兼容的函数接口 ====================
|
||||
|
||||
async def draft_run(
|
||||
|
||||
Reference in New Issue
Block a user