Files
life-echo/api/app/features/auth/schemas.py
Kevin ccdc4e4277 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>
2026-05-11 16:16:49 +08:00

141 lines
4.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from typing import Literal, Optional
from pydantic import BaseModel, Field
LanguagePreference = Literal["zh", "en"]
class RegisterRequest(BaseModel):
phone: str = Field(..., min_length=11, max_length=11, description="手机号11位")
password: str = Field(..., min_length=6, description="密码至少6位")
nickname: str = Field(..., min_length=1, max_length=50, description="昵称")
email: Optional[str] = Field(None, description="邮箱(可选)")
agreed_to_terms: bool = Field(..., description="是否同意用户协议和隐私政策")
language: Optional[LanguagePreference] = Field(
None,
description="device language at signup; only used when creating a new user",
)
class LoginRequest(BaseModel):
phone: str = Field(..., min_length=11, max_length=11, description="手机号11位")
password: str = Field(..., min_length=1, description="密码")
agreed_to_terms: bool = Field(..., description="是否同意用户协议和隐私政策")
class TokenResponse(BaseModel):
access_token: str
refresh_token: str
token_type: str = "bearer"
class RefreshTokenRequest(BaseModel):
refresh_token: str = Field(..., description="刷新令牌")
class UserResponse(BaseModel):
id: str
phone: str
email: Optional[str] = None
nickname: str
avatar_url: Optional[str] = None
subscription_type: str
created_at: str
language_preference: LanguagePreference = "zh"
class SendSmsRequest(BaseModel):
phone: str = Field(..., min_length=11, max_length=11, description="手机号11位")
purpose: str = Field(
..., description="用途register/login/reset_password/change_phone"
)
class SendSmsResponse(BaseModel):
success: bool
message: str
expires_in: Optional[int] = None
class SmsLoginRequest(BaseModel):
phone: str = Field(..., min_length=11, max_length=11, description="手机号11位")
code: str = Field(..., min_length=6, max_length=6, description="验证码6位")
agreed_to_terms: bool = Field(..., description="是否同意用户协议和隐私政策")
nickname: Optional[str] = Field(
None, max_length=50, description="昵称(注册时必填,登录时可选)"
)
language: Optional[LanguagePreference] = Field(
None,
description="device language at signup; only used when creating a new user",
)
class MockSmsLoginRequest(BaseModel):
"""开发/评测专用:与 MOCK_SMS_LOGIN_ENABLED 联用,跳过短信校验。"""
phone: str = Field(..., min_length=11, max_length=11, description="手机号11位")
agreed_to_terms: bool = Field(..., description="是否同意用户协议和隐私政策")
nickname: Optional[str] = Field(
None, max_length=50, description="新用户昵称(可选)"
)
language: Optional[LanguagePreference] = Field(
None,
description="device language at signup; only used when creating a new user",
)
class SmsRegisterRequest(BaseModel):
phone: str = Field(..., min_length=11, max_length=11, description="手机号11位")
code: str = Field(..., min_length=6, max_length=6, description="验证码6位")
password: str = Field(..., min_length=6, description="密码至少6位")
nickname: str = Field(..., min_length=1, max_length=50, description="昵称")
email: Optional[str] = Field(None, description="邮箱(可选)")
agreed_to_terms: bool = Field(..., description="是否同意用户协议和隐私政策")
language: Optional[LanguagePreference] = Field(
None,
description="device language at signup; only used when creating a new user",
)
class ResetPasswordRequest(BaseModel):
phone: str = Field(..., min_length=11, max_length=11, description="手机号11位")
code: str = Field(..., min_length=6, max_length=6, description="验证码6位")
new_password: str = Field(..., min_length=6, description="新密码至少6位")
class ChangePasswordRequest(BaseModel):
old_password: str = Field(..., min_length=1, description="旧密码")
new_password: str = Field(..., min_length=6, description="新密码至少6位")
class ChangePhoneRequest(BaseModel):
new_phone: str = Field(
..., min_length=11, max_length=11, description="新手机号11位"
)
code: str = Field(..., min_length=6, max_length=6, description="验证码6位")
class UpdateNicknameRequest(BaseModel):
nickname: str = Field(
..., min_length=1, max_length=50, description="昵称1-50个字符"
)
class AvatarUploadResponse(BaseModel):
avatar_url: str
class SetAvatarPresetRequest(BaseModel):
preset_id: str = Field(
...,
min_length=2,
max_length=2,
pattern=r"^\d{2}$",
description="预设编号,如 0108",
)
class AvatarPresetItem(BaseModel):
id: str
url: str