feat(i18n): persist language preference and thread through chat, memoir, TTS

- Add users.language_preference (Alembic 0018, default zh); capture at signup/SMS
  only; expose on auth and profile APIs
- Lite English prompts for chat and memoir; localized stage labels and agent
  names (Life Echo / 岁月知己)
- Tencent TTS: language-aware synthesis, ModelType=1 for 501004, English chunking
- WebSocket pipeline: emit all AGENT_RESPONSE segments when TTS cancels; INFO logs
  for tts_this_turn and TTS decisions; on-demand TTS logging
- Expo: device language on auth, i18n tiers/agent name, [SPLIT] streaming UX fixes
- Tests for migration, prompts, pipeline, router tts_this_turn, reply segments

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Kevin
2026-05-11 16:16:49 +08:00
parent 5ce29aad64
commit ccdc4e4277
64 changed files with 3233 additions and 208 deletions

View File

@@ -0,0 +1,34 @@
"""验证 0018 迁移使用 server_default='zh' 落库(防止已有用户 NULL"""
from __future__ import annotations
from pathlib import Path
from app.features.user.models import User
def test_migration_0018_uses_server_default_zh() -> None:
path = (
Path(__file__).resolve().parent.parent
/ "alembic"
/ "versions"
/ "0018_users_language_preference.py"
)
src = path.read_text(encoding="utf-8")
assert "language_preference" in src
# server_default 'zh' 是已有用户回填的关键
assert "server_default=sa.text(\"'zh'\")" in src
assert "nullable=False" in src
# 在多行 op.add_column 调用中第一参数为 "users"
assert "op.add_column" in src
assert '"users"' in src
def test_user_model_language_preference_default_zh() -> None:
"""模型层默认值与迁移一致;新建实例不传值时为 'zh'"""
column = User.__table__.c.language_preference
assert column.default is not None
assert column.default.arg == "zh"
assert column.server_default is not None
assert "zh" in str(column.server_default.arg)
assert column.nullable is False