From 6a902b9ff9e10a4bf2a229c0146d340dba3de1ae Mon Sep 17 00:00:00 2001 From: ooodc <549496103@qq.com> Date: Sat, 16 May 2026 20:32:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=B8=A6=E8=AF=9D?= =?UTF-8?q?=E9=A2=98=E7=9A=84=E6=B6=88=E6=81=AF=E8=BF=BD=E5=8A=A0=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E6=94=AF=E6=8C=81=E5=9C=A8=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?=E4=B8=AD=E5=85=B3=E8=81=94=E5=BD=93=E5=89=8D=E8=AF=9D=E9=A2=98?= =?UTF-8?q?=20ID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gateway/session_history.rs | 4 +++- src/storage/ports.rs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/gateway/session_history.rs b/src/gateway/session_history.rs index f235383..3893929 100644 --- a/src/gateway/session_history.rs +++ b/src/gateway/session_history.rs @@ -187,8 +187,10 @@ impl SessionHistory { message: ChatMessage, ) -> Result<(), AgentError> { let session_id = self.persistent_session_id(chat_id); + // 获取当前话题 ID,用于关联消息 + let topic_id = self.chat_topic_ids.get(chat_id).map(|s| s.as_str()); self.conversations - .append_message(&session_id, &message) + .append_message_with_topic(&session_id, topic_id, &message) .map_err(|err| { AgentError::Other(format!("append message persistence error: {}", err)) })?; diff --git a/src/storage/ports.rs b/src/storage/ports.rs index 3a18aba..21a02e5 100644 --- a/src/storage/ports.rs +++ b/src/storage/ports.rs @@ -15,6 +15,13 @@ pub trait ConversationRepository: Send + Sync + 'static { fn append_message(&self, session_id: &str, message: &ChatMessage) -> Result<(), StorageError>; + fn append_message_with_topic( + &self, + session_id: &str, + topic_id: Option<&str>, + message: &ChatMessage, + ) -> Result<(), StorageError>; + fn clear_messages(&self, session_id: &str) -> Result<(), StorageError>; fn reset_session(&self, session_id: &str) -> Result<(), StorageError>; @@ -140,6 +147,15 @@ impl ConversationRepository for super::SessionStore { super::SessionStore::append_message(self, session_id, message) } + fn append_message_with_topic( + &self, + session_id: &str, + topic_id: Option<&str>, + message: &ChatMessage, + ) -> Result<(), StorageError> { + super::SessionStore::append_message_with_topic(self, session_id, topic_id, message) + } + fn clear_messages(&self, session_id: &str) -> Result<(), StorageError> { super::SessionStore::clear_messages(self, session_id) }