feat: 将 StreamingAccumulator 中的 tool_calls 类型从 HashMap 更改为 BTreeMap;在 SkillSource 中添加自定义源支持
This commit is contained in:
parent
d2af01eb30
commit
2a02adc7c3
@ -134,9 +134,13 @@ async fn handle_socket(ws: WebSocket, state: Arc<GatewayState>) {
|
|||||||
let cli_sessions = state.session_manager.cli_sessions();
|
let cli_sessions = state.session_manager.cli_sessions();
|
||||||
let store = state.session_manager.store();
|
let store = state.session_manager.store();
|
||||||
|
|
||||||
// 1. 先查询 websocket 通道的 Sessions
|
// 1. 查询 websocket 和 cli 两个通道的 Sessions(兼容旧版本 cli 通道创建的会话)
|
||||||
let websocket_sessions = store.list_sessions("websocket", false)
|
let mut websocket_sessions = store.list_sessions("websocket", false)
|
||||||
.unwrap_or_default();
|
.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
|
// 2. 如果没有,自动创建一个默认 Session
|
||||||
let initial_record = if websocket_sessions.is_empty() {
|
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 })
|
.send(WsOutbound::ChannelList { channels })
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
// 3. 重新查询 websocket 通道的 Session 列表(包含刚创建的)
|
// 3. 发送合并后的 Session 列表(已在上面合并了 websocket + cli 通道)
|
||||||
let final_sessions = store.list_sessions("websocket", false)
|
// 如果刚创建了新会话,确保它也在列表中
|
||||||
.unwrap_or_default();
|
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());
|
tracing::info!("Sending {} sessions to client", websocket_sessions.len());
|
||||||
for s in &final_sessions {
|
for s in &websocket_sessions {
|
||||||
tracing::info!(" - {}: {} (channel: {})", s.id, s.title, s.channel_name);
|
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()
|
.into_iter()
|
||||||
.map(|s| crate::protocol::SessionSummary {
|
.map(|s| crate::protocol::SessionSummary {
|
||||||
session_id: s.id,
|
session_id: s.id,
|
||||||
|
|||||||
@ -1601,7 +1601,7 @@ impl SessionStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn persistent_session_id(channel_name: &str, chat_id: &str) -> String {
|
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()
|
chat_id.to_string()
|
||||||
} else {
|
} else {
|
||||||
format!("{}:{}", channel_name, chat_id)
|
format!("{}:{}", channel_name, chat_id)
|
||||||
@ -2288,6 +2288,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_persistent_session_id_for_cli_and_channel() {
|
fn test_persistent_session_id_for_cli_and_channel() {
|
||||||
assert_eq!(persistent_session_id("cli", "abc"), "abc");
|
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");
|
assert_eq!(persistent_session_id(TEST_CHANNEL, "abc"), "test-channel:abc");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user