feat: 添加按通道查询会话功能,优化会话列表处理

This commit is contained in:
oudecheng 2026-05-15 08:43:33 +08:00
parent 054cb718de
commit 0095ace411
2 changed files with 19 additions and 4 deletions

View File

@ -49,9 +49,11 @@ async fn handle_list_sessions(
include_archived: bool,
ctx: CommandContext,
) -> Result<CommandResponse, CommandError> {
// 使用当前通道名称查询会话,而不是硬编码 "cli"
let channel_name = &ctx.channel_name;
let records = handler
.cli_sessions
.list(include_archived)
.list_by_channel(channel_name, include_archived)
.map_err(|e| CommandError::new("LIST_SESSIONS_ERROR", e.to_string()))?;
let summaries: Vec<SessionSummary> = records
@ -131,7 +133,8 @@ mod tests {
async fn test_list_sessions_empty() {
let service = create_test_service();
let handler = SessionQueryCommandHandler::new(service);
let ctx = CommandContext::new("test", "test");
// 使用 "cli" 通道,与 CliSessionService::create 一致
let ctx = CommandContext::new("test", "cli");
let cmd = Command::ListSessions {
include_archived: false,
};
@ -149,10 +152,11 @@ mod tests {
let service = create_test_service();
let handler = SessionQueryCommandHandler::new(service.clone());
// 创建一些会话
// 创建一些会话(使用 cli 通道)
service.create(Some("test session")).unwrap();
let ctx = CommandContext::new("test", "test");
// 使用 "cli" 通道查询,与创建会话的通道一致
let ctx = CommandContext::new("test", "cli");
let cmd = Command::ListSessions {
include_archived: false,
};

View File

@ -42,6 +42,17 @@ impl CliSessionService {
.map_err(|err| AgentError::Other(format!("list sessions error: {}", err)))
}
/// 列出指定通道的会话
pub(crate) fn list_by_channel(
&self,
channel_name: &str,
include_archived: bool,
) -> Result<Vec<SessionRecord>, AgentError> {
self.store
.list_sessions(channel_name, include_archived)
.map_err(|err| AgentError::Other(format!("list sessions error: {}", err)))
}
pub(crate) fn rename(&self, session_id: &str, title: &str) -> Result<(), AgentError> {
self.store
.rename_session(session_id, title)