149bec6
use sea_orm::{DatabaseConnection, EntityTrait};
use uuid::Uuid;
/// 解析触发者偏好的输出语言(BCP-47)。
///
/// 生产侧在入队时把语言写进任务,消费侧便无需再查用户表;查不到时返回 `None`,
/// 由 aihost 回退到 `[ai].output_language`。
pub async fn actor_language(db: &DatabaseConnection, actor_id: Option<Uuid>) -> Option<String> {
use models::users::user;
let uid = actor_id?;
let row = user::Entity::find_by_id(uid).one(db).await.ok()??;
let raw = row
.language
.as_deref()
.filter(|value| !value.trim().is_empty())
.or_else(|| {
row.locale
.as_deref()
.filter(|value| !value.trim().is_empty())
})?;
let normalized = ci_protocol::ai_languages::normalize(raw);
(!normalized.is_empty()).then_some(normalized)
}