refactor(session): 移除 InboundMessage.dialog_id,dialog_id 完全由 SessionManager 管理

Channel 消息不再携带 dialog_id,完全由 SessionManager 通过
current_sessions 内部管理。/new 后下一条消息会自动路由到新 session。

改动:
- InboundMessage 移除 dialog_id 字段
- handle_message 移除 dialog_id 参数
- Feishu/CLI channel 创建 InboundMessage 时不再设置 dialog_id
- 路由逻辑简化为:current_sessions → find_active_session → 创建新 session
This commit is contained in:
xiaoxixi 2026-04-28 23:05:06 +08:00
parent e235268133
commit c48ed83a23
5 changed files with 4 additions and 12 deletions

View File

@ -164,7 +164,6 @@ pub struct InboundMessage {
pub channel: String, pub channel: String,
pub sender_id: String, pub sender_id: String,
pub chat_id: String, pub chat_id: String,
pub dialog_id: Option<String>,
pub content: String, pub content: String,
pub timestamp: i64, pub timestamp: i64,
pub media: Vec<MediaItem>, pub media: Vec<MediaItem>,

View File

@ -117,7 +117,6 @@ impl CliChatChannel {
channel: self.name().to_string(), channel: self.name().to_string(),
sender_id: "cli".to_string(), sender_id: "cli".to_string(),
chat_id: chat_id.unwrap_or_else(short_id), chat_id: chat_id.unwrap_or_else(short_id),
dialog_id: None,
content, content,
timestamp: crate::bus::message::current_timestamp(), timestamp: crate::bus::message::current_timestamp(),
media: Vec::new(), media: Vec::new(),

View File

@ -1110,7 +1110,6 @@ impl FeishuChannel {
channel: "feishu".to_string(), channel: "feishu".to_string(),
sender_id: parsed.open_id.clone(), sender_id: parsed.open_id.clone(),
chat_id: parsed.chat_id.clone(), chat_id: parsed.chat_id.clone(),
dialog_id: None, // Use default/current dialog
content: parsed.content.clone(), content: parsed.content.clone(),
timestamp: crate::bus::message::current_timestamp(), timestamp: crate::bus::message::current_timestamp(),
media: parsed.media.map(|m| vec![m]).unwrap_or_default(), media: parsed.media.map(|m| vec![m]).unwrap_or_default(),

View File

@ -107,7 +107,6 @@ impl GatewayState {
&inbound.channel, &inbound.channel,
&inbound.sender_id, &inbound.sender_id,
&inbound.chat_id, &inbound.chat_id,
inbound.dialog_id.as_deref(),
&inbound.content, &inbound.content,
inbound.media, inbound.media,
).await { ).await {

View File

@ -1039,15 +1039,11 @@ impl SessionManager {
channel: &str, channel: &str,
_sender_id: &str, _sender_id: &str,
chat_id: &str, chat_id: &str,
dialog_id: Option<&str>,
content: &str, content: &str,
media: Vec<crate::bus::MediaItem>, media: Vec<crate::bus::MediaItem>,
) -> Result<HandleResult, AgentError> { ) -> Result<HandleResult, AgentError> {
// Determine dialog_id: if not provided, use current session or find active or create new // Channel messages never carry dialog_id — routing is entirely via current_sessions
let unified_id = if let Some(did) = dialog_id { let unified_id = {
UnifiedSessionId::new(channel, chat_id, did)
} else {
// Check if we have a current session tracked for this channel:chat_id
let chat_scope = format!("{}:{}", channel, chat_id); let chat_scope = format!("{}:{}", channel, chat_id);
let current_session_id = { let current_session_id = {
let inner = self.inner.lock().await; let inner = self.inner.lock().await;
@ -1056,8 +1052,8 @@ impl SessionManager {
if let Some(current_id) = current_session_id { if let Some(current_id) = current_session_id {
// Verify current session still exists in Storage // Verify current session still exists in Storage
match self.storage.get_session(&current_id).await { match self.storage.get_session(&current_id).await {
Ok(meta) => { Ok(_) => {
// Current session still valid // Current session still valid, extract dialog_id
let parts: Vec<&str> = current_id.split(':').collect(); let parts: Vec<&str> = current_id.split(':').collect();
if parts.len() == 3 { if parts.len() == 3 {
UnifiedSessionId::new(channel, chat_id, parts[2]) UnifiedSessionId::new(channel, chat_id, parts[2])