diff --git a/src/channels/cli.rs b/src/channels/cli.rs index 0ce9656..ee7703c 100644 --- a/src/channels/cli.rs +++ b/src/channels/cli.rs @@ -65,7 +65,7 @@ impl Default for CliChannel { #[async_trait] impl Channel for CliChannel { fn name(&self) -> &str { - "cli" + "websocket" } fn is_running(&self) -> bool { diff --git a/src/channels/manager.rs b/src/channels/manager.rs index a237971..396103e 100644 --- a/src/channels/manager.rs +++ b/src/channels/manager.rs @@ -15,19 +15,19 @@ use crate::protocol::Channel as ProtocolChannel; pub struct ChannelManager { channels: Arc>>>, bus: Arc, - cli_channel: Arc, + websocket_channel: Arc, } impl ChannelManager { pub fn new() -> Self { - let cli_channel = Arc::new(CliChannel::new()); + let websocket_channel = Arc::new(CliChannel::new()); let mut channels: HashMap> = HashMap::new(); - channels.insert("cli".to_string(), cli_channel.clone()); + channels.insert("websocket".to_string(), websocket_channel.clone()); Self { channels: Arc::new(RwLock::new(channels)), bus: MessageBus::new(100), - cli_channel, + websocket_channel, } } @@ -36,8 +36,8 @@ impl ChannelManager { self.bus.clone() } - pub fn cli_channel(&self) -> Arc { - self.cli_channel.clone() + pub fn websocket_channel(&self) -> Arc { + self.websocket_channel.clone() } /// Initialize all Channel instances from config @@ -142,16 +142,7 @@ impl ChannelManager { let mut seen = HashSet::new(); let mut channels: Vec = Vec::new(); - // 1. WebSocket 通道 — Web 前端自己的连接,始终存在 - seen.insert("websocket".to_string()); - channels.push(ProtocolChannel { - id: "websocket".to_string(), - name: "WebSocket".to_string(), - description: Some("Web 前端通道".to_string()), - is_writable: true, - }); - - // 2. 所有动态注册的通道(cli, feishu, wechat 等) + // 所有注册的通道(websocket, feishu, wechat 等) for (name, _channel) in self.channels().await { if seen.contains(&name) { continue; @@ -172,7 +163,6 @@ impl ChannelManager { fn channel_display_name(name: &str) -> String { match name { "websocket" => "WebSocket".to_string(), - "cli" => "命令行".to_string(), "feishu" => "飞书".to_string(), "wechat" => "微信".to_string(), other => other.to_string(), @@ -262,7 +252,7 @@ mod tests { .collect::>(); names.sort(); - assert_eq!(names, vec!["backup", "cli", "primary"]); + assert_eq!(names, vec!["backup", "primary", "websocket"]); assert_eq!(manager.get_channel("primary").await.unwrap().name(), "primary"); assert_eq!(manager.get_channel("backup").await.unwrap().name(), "backup"); } @@ -323,7 +313,7 @@ mod tests { .collect::>(); names.sort(); - assert_eq!(names, vec!["cli", "wechat_main"]); + assert_eq!(names, vec!["websocket", "wechat_main"]); assert_eq!(manager.get_channel("wechat_main").await.unwrap().name(), "wechat_main"); } } diff --git a/src/command/handlers/mod.rs b/src/command/handlers/mod.rs index 596af6b..d11d767 100644 --- a/src/command/handlers/mod.rs +++ b/src/command/handlers/mod.rs @@ -51,9 +51,13 @@ pub async fn get_messages_from_session( .map(|m| m.clone()) .unwrap_or_default()) } - None => Err(CommandError::new( - "SESSION_NOT_FOUND", - format!("Session not found for channel: {}", channel_name), - )), + None => { + tracing::warn!( + channel = %channel_name, + chat_id = %chat_id, + "No in-memory session, returning empty message list" + ); + Ok(Vec::new()) + } } } diff --git a/src/gateway/ws.rs b/src/gateway/ws.rs index 596daa6..3963190 100644 --- a/src/gateway/ws.rs +++ b/src/gateway/ws.rs @@ -40,7 +40,7 @@ use std::path::PathBuf; use std::sync::Arc; use tokio::sync::mpsc; -const CLI_CHANNEL_NAME: &str = "cli"; +const WS_CHANNEL_NAME: &str = "websocket"; /// Default media directory for WebSocket uploads fn default_ws_media_dir() -> PathBuf { @@ -157,7 +157,7 @@ async fn handle_socket(ws: WebSocket, state: Arc) { let mut current_topic_id: Option = None; state .channel_manager - .cli_channel() + .websocket_channel() .register_connection( current_session_id.clone(), runtime_session_id.clone(), @@ -273,7 +273,7 @@ async fn handle_socket(ws: WebSocket, state: Arc) { state .channel_manager - .cli_channel() + .websocket_channel() .unregister_connection(&runtime_session_id) .await; tracing::info!(session_id = %runtime_session_id, current_session_id = %current_session_id, "CLI session ended"); @@ -301,7 +301,7 @@ async fn handle_inbound( state .channel_manager - .cli_channel() + .websocket_channel() .register_connection( chat_id.clone(), runtime_session_id.to_string(), @@ -315,7 +315,7 @@ async fn handle_inbound( state .bus .publish_inbound(InboundMessage { - channel: CLI_CHANNEL_NAME.to_string(), + channel: WS_CHANNEL_NAME.to_string(), sender_id, chat_id, content, @@ -450,7 +450,7 @@ async fn handle_inbound( current_topic_id = ?current_topic_id, "Building CommandContext for WebSocket command" ); - let mut cmd_ctx = CommandContext::new("websocket", "cli") + let mut cmd_ctx = CommandContext::new("websocket", "websocket") .with_session_id(current_session_id.as_str()) .with_chat_id(current_session_id.as_str()); // 只在有 topic_id 时才设置 @@ -473,7 +473,7 @@ async fn handle_inbound( *current_session_id = session_id.clone(); state .channel_manager - .cli_channel() + .websocket_channel() .register_connection( session_id.clone(), runtime_session_id.to_string(), diff --git a/tests/test_request_format.rs b/tests/test_request_format.rs index 8e41f49..21b679b 100644 --- a/tests/test_request_format.rs +++ b/tests/test_request_format.rs @@ -126,6 +126,7 @@ fn test_tool_call_outbound_serialization() { topic_id: None, timestamp: None, reasoning_content: None, + user_message_id: None, }; let json = serde_json::to_string(&msg).unwrap();