Add conversation history management and API endpoints

- Introduce new database models for conversation sessions, messages, and artifacts to support conversation history tracking.
- Implement API routes for listing conversations and retrieving detailed conversation data, enhancing user interaction with historical records.
- Add a conversation recorder service to persist conversation messages in real-time without disrupting ongoing calls.
- Update the frontend to display conversation history, including filtering and sorting options, improving user experience.
- Enhance the pipeline to integrate conversation history recording seamlessly during interactions.
This commit is contained in:
Xin Wang
2026-07-10 16:25:06 +08:00
parent 5705726cfb
commit 059ad8162e
13 changed files with 1096 additions and 43 deletions

View File

@@ -24,13 +24,16 @@ from starlette.websockets import WebSocketDisconnect
router = APIRouter()
async def _resolve_start_config(raw: str) -> AssistantConfig:
async def _resolve_start_config(raw: str) -> tuple[AssistantConfig, str | None]:
data = json.loads(raw)
if data.get("assistant_id"):
async with SessionLocal() as session:
return await resolve_runtime_config(session, data["assistant_id"])
return (
await resolve_runtime_config(session, data["assistant_id"]),
data["assistant_id"],
)
if data.get("inline_config"):
return AssistantConfig(**data["inline_config"])
return AssistantConfig(**data["inline_config"]), None
raise ValueError("启动参数缺少 assistant_id 或 inline_config")
@@ -43,10 +46,10 @@ async def voice_stream(websocket: WebSocket):
return
await websocket.accept()
try:
cfg = await _resolve_start_config(await websocket.receive_text())
cfg, assistant_id = await _resolve_start_config(await websocket.receive_text())
transport = build_ws_transport(websocket)
# 直接 await:管线持续读这条 WS 的音频帧,直到对端断开
await run_pipeline(transport, cfg)
await run_pipeline(transport, cfg, assistant_id=assistant_id, channel="websocket")
except WebSocketDisconnect:
logger.info("WS 音频流断开")
except Exception as e: