feat: add ChatMessage::user_with_source and Session::create_user_message_with_source

This commit is contained in:
xiaoski 2026-05-05 00:09:00 +08:00
parent 4e5f412c2d
commit eccae20a0a
2 changed files with 27 additions and 0 deletions

View File

@ -195,6 +195,20 @@ impl ChatMessage {
source: None, source: None,
} }
} }
pub fn user_with_source(content: impl Into<String>, source: MessageSource) -> Self {
Self {
id: uuid::Uuid::new_v4().to_string(),
role: "user".to_string(),
content: content.into(),
media_refs: Vec::new(),
timestamp: current_timestamp(),
tool_call_id: None,
tool_name: None,
tool_calls: None,
source: Some(source),
}
}
} }
// ============================================================================ // ============================================================================

View File

@ -251,6 +251,19 @@ impl Session {
} }
} }
pub fn create_user_message_with_source(
&self,
content: &str,
media_refs: Vec<String>,
source: MessageSource,
) -> ChatMessage {
if media_refs.is_empty() {
ChatMessage::user_with_source(content, source)
} else {
ChatMessage::user_with_source(content, source)
}
}
/// 将 session 元数据写回 Storage /// 将 session 元数据写回 Storage
pub async fn persist_session_meta(&self) -> Result<(), StorageError> { pub async fn persist_session_meta(&self) -> Result<(), StorageError> {
if let Some(ref storage) = self.storage { if let Some(ref storage) = self.storage {