feat: add versioned app chat API and fix release isolation bug
This commit is contained in:
@@ -91,16 +91,16 @@ async def chat(
|
||||
Agent/Workflow 聊天接口
|
||||
|
||||
- 不传 version:使用当前生效版本(current_release,回滚后为回滚目标版本)
|
||||
- 传 version=N:使用指定版本号的历史快照,例如 {"version": 2}
|
||||
- 传 version=release_id:使用指定版本uuid的历史快照,例如 {"version": "{{release_id}}"}
|
||||
"""
|
||||
body = await request.json()
|
||||
payload = AppChatRequest(**body)
|
||||
|
||||
app = app_service.get_app(api_key_auth.resource_id, api_key_auth.workspace_id)
|
||||
|
||||
# 版本切换:指定 version 时查找对应历史快照,否则使用当前激活版本
|
||||
# 版本切换:指定 release_id 时查找对应历史快照,否则使用当前激活版本
|
||||
if payload.version is not None:
|
||||
active_release = app_service.get_release_by_version(app.id, payload.version)
|
||||
active_release = app_service.get_release_by_id(app.id, payload.version)
|
||||
else:
|
||||
active_release = app.current_release
|
||||
other_id = payload.user_id
|
||||
|
||||
@@ -63,7 +63,7 @@ def get_apps_by_id(db: Session, app_id: uuid.UUID) -> App:
|
||||
return repo.get_apps_by_id(app_id)
|
||||
|
||||
|
||||
def get_release_by_version(db: Session, app_id: uuid.UUID, release_id: uuid.UUID):
|
||||
def get_release_by_id(db: Session, app_id: uuid.UUID, release_id: uuid.UUID):
|
||||
"""根据发布版本ID查询发布快照(仅返回激活状态)"""
|
||||
from app.models.app_release_model import AppRelease
|
||||
return db.scalars(
|
||||
|
||||
@@ -619,7 +619,7 @@ class AppService:
|
||||
self._validate_app_accessible(app, workspace_id)
|
||||
return app
|
||||
|
||||
def get_release_by_version(self, app_id: uuid.UUID, release_id: uuid.UUID) -> AppRelease:
|
||||
def get_release_by_id(self, app_id: uuid.UUID, release_id: uuid.UUID) -> AppRelease:
|
||||
"""按发布版本ID获取发布快照
|
||||
|
||||
Args:
|
||||
@@ -632,8 +632,8 @@ class AppService:
|
||||
Raises:
|
||||
BusinessException: 版本不存在或已下线
|
||||
"""
|
||||
from app.repositories.app_repository import get_release_by_version
|
||||
release = get_release_by_version(self.db, app_id, release_id)
|
||||
from app.repositories.app_repository import get_release_by_id
|
||||
release = get_release_by_id(self.db, app_id, release_id)
|
||||
if not release:
|
||||
raise BusinessException(
|
||||
f"版本 {release_id} 不存在或已下线",
|
||||
|
||||
Reference in New Issue
Block a user