- 后端:文本/转写后 AI 生成改为独立任务,避免断连取消整轮;按需 TTS 等与 WS 改动 - 前端:RealtimeSession 重绑 UI 时恢复流式 buffer;列表 onPressIn/挂载预热、已有会话立即 push - 同步会话相关类型、i18n、测试与 env/资源等累计改动 Co-authored-by: Cursor <cursoragent@cursor.com>
31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
"""ConversationMessage -> Redis conversation history 的纯映射(无 I/O)。"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from typing import Any, Dict, List
|
||
|
||
from app.features.conversation.models import ConversationMessage
|
||
|
||
|
||
def conversation_messages_to_redis_history(
|
||
rows: List[ConversationMessage],
|
||
) -> List[Dict[str, Any]]:
|
||
"""ConversationMessage 行 -> Redis conversation history 项。"""
|
||
history: List[Dict[str, Any]] = []
|
||
for row in rows:
|
||
item: Dict[str, Any] = {
|
||
"role": row.role,
|
||
"content": row.content,
|
||
"messageType": row.message_type,
|
||
"timestamp": row.created_at.isoformat() if row.created_at else None,
|
||
"durableMessageId": row.id,
|
||
}
|
||
if row.voice_session_id:
|
||
item["voiceSessionId"] = row.voice_session_id
|
||
if row.duration_seconds:
|
||
item["durationSeconds"] = row.duration_seconds
|
||
if row.tts_audio_urls:
|
||
item["ttsAudioUrls"] = row.tts_audio_urls
|
||
history.append(item)
|
||
return history
|