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