feat: 将 StreamingAccumulator 中的 tool_calls 类型从 HashMap 更改为 BTreeMap;在 SkillSource 中添加自定义源支持

This commit is contained in:
oudecheng 2026-07-03 11:34:30 +08:00
parent d2af01eb30
commit 2a02adc7c3
2 changed files with 18 additions and 9 deletions

View File

@ -134,9 +134,13 @@ async fn handle_socket(ws: WebSocket, state: Arc<GatewayState>) {
let cli_sessions = state.session_manager.cli_sessions();
let store = state.session_manager.store();
// 1. 查询 websocket 通道的 Sessions
let websocket_sessions = store.list_sessions("websocket", false)
// 1. 查询 websocket 和 cli 两个通道的 Sessions(兼容旧版本 cli 通道创建的会话)
let mut websocket_sessions = store.list_sessions("websocket", false)
.unwrap_or_default();
let cli_channel_sessions = store.list_sessions("cli", false)
.unwrap_or_default();
websocket_sessions.extend(cli_channel_sessions);
websocket_sessions.sort_by_key(|s| -(s.last_active_at));
// 2. 如果没有,自动创建一个默认 Session
let initial_record = if websocket_sessions.is_empty() {
@ -178,16 +182,20 @@ async fn handle_socket(ws: WebSocket, state: Arc<GatewayState>) {
.send(WsOutbound::ChannelList { channels })
.await;
// 3. 重新查询 websocket 通道的 Session 列表(包含刚创建的)
let final_sessions = store.list_sessions("websocket", false)
.unwrap_or_default();
// 3. 发送合并后的 Session 列表(已在上面合并了 websocket + cli 通道)
// 如果刚创建了新会话,确保它也在列表中
let has_initial = websocket_sessions.iter().any(|s| s.id == initial_record.id);
if !has_initial {
websocket_sessions.push(initial_record);
websocket_sessions.sort_by_key(|s| -(s.last_active_at));
}
tracing::info!("Sending {} websocket sessions to client", final_sessions.len());
for s in &final_sessions {
tracing::info!("Sending {} sessions to client", websocket_sessions.len());
for s in &websocket_sessions {
tracing::info!(" - {}: {} (channel: {})", s.id, s.title, s.channel_name);
}
let session_summaries: Vec<crate::protocol::SessionSummary> = final_sessions
let session_summaries: Vec<crate::protocol::SessionSummary> = websocket_sessions
.into_iter()
.map(|s| crate::protocol::SessionSummary {
session_id: s.id,

View File

@ -1601,7 +1601,7 @@ impl SessionStore {
}
pub fn persistent_session_id(channel_name: &str, chat_id: &str) -> String {
if channel_name == "cli" {
if channel_name == "cli" || channel_name == "websocket" {
chat_id.to_string()
} else {
format!("{}:{}", channel_name, chat_id)
@ -2288,6 +2288,7 @@ mod tests {
#[test]
fn test_persistent_session_id_for_cli_and_channel() {
assert_eq!(persistent_session_id("cli", "abc"), "abc");
assert_eq!(persistent_session_id("websocket", "websocket:abc"), "websocket:abc");
assert_eq!(persistent_session_id(TEST_CHANNEL, "abc"), "test-channel:abc");
}