feat(api): Support specifying app version for chat

This commit is contained in:
wxy
2026-04-10 11:04:59 +08:00
parent 3a62d50048
commit fd05c000f6
2 changed files with 27 additions and 0 deletions

View File

@@ -86,10 +86,36 @@ async def chat(
app_service: Annotated[AppService, Depends(get_app_service)] = None,
message: str = Body(..., description="聊天消息内容"),
):
"""
Agent/Workflow 聊天接口
- 不传 version使用当前发布版本current_release
- 传 version=N使用指定版本号的历史快照例如 /v1/app/chat?version=2
"""
body = await request.json()
payload = AppChatRequest(**body)
app = app_service.get_app(api_key_auth.resource_id, api_key_auth.workspace_id)
# 版本切换:指定 version 时查找对应历史快照
if payload.version is not None:
from sqlalchemy import select as _select
from app.models.app_release_model import AppRelease as _AppRelease
release = db.scalars(
_select(_AppRelease).where(
_AppRelease.app_id == app.id,
_AppRelease.version == payload.version,
_AppRelease.is_active.is_(True),
)
).first()
if not release:
raise BusinessException(
f"版本 {payload.version} 不存在或已下线",
BizCode.AGENT_CONFIG_MISSING,
)
# 临时替换 current_release后续逻辑无需改动
app.current_release = release
app.current_release_id = release.id
other_id = payload.user_id
workspace_id = api_key_auth.workspace_id
end_user_repo = EndUserRepository(db)

View File

@@ -616,6 +616,7 @@ class AppChatRequest(BaseModel):
stream: bool = Field(default=False, description="是否流式返回")
thinking: bool = Field(default=False, description="是否启用深度思考需Agent配置支持")
files: List[FileInput] = Field(default_factory=list, description="附件列表(支持多文件)")
version: Optional[int] = Field(default=None, description="指定发布版本号,不传则使用当前发布版本")
class DraftRunRequest(BaseModel):