Compare commits
No commits in common. "8edc7ef9050949536cd8d154cf25934b489aef3d" and "a2d4ed91935e14e0fded6db590502e4ea90a2f04" have entirely different histories.
8edc7ef905
...
a2d4ed9193
@ -10,6 +10,7 @@ use crate::command::handler::CommandRouter;
|
|||||||
use crate::command::handlers::save_session::SaveSessionCommandHandler;
|
use crate::command::handlers::save_session::SaveSessionCommandHandler;
|
||||||
use crate::command::handlers::session::SessionCommandHandler;
|
use crate::command::handlers::session::SessionCommandHandler;
|
||||||
use crate::command::handlers::session_query::SessionQueryCommandHandler;
|
use crate::command::handlers::session_query::SessionQueryCommandHandler;
|
||||||
|
use crate::command::Command;
|
||||||
use crate::config::LLMProviderConfig;
|
use crate::config::LLMProviderConfig;
|
||||||
use crate::gateway::agent_prompt_provider::AgentPromptProvider;
|
use crate::gateway::agent_prompt_provider::AgentPromptProvider;
|
||||||
use crate::skills::SkillPromptProvider;
|
use crate::skills::SkillPromptProvider;
|
||||||
@ -122,14 +123,6 @@ impl InboundProcessor {
|
|||||||
// 计算正确的 session_id(根据 channel_name 和 chat_id)
|
// 计算正确的 session_id(根据 channel_name 和 chat_id)
|
||||||
let session_id = persistent_session_id(&inbound.channel, &inbound.chat_id);
|
let session_id = persistent_session_id(&inbound.channel, &inbound.chat_id);
|
||||||
|
|
||||||
// 获取当前话题(如果有 Session)
|
|
||||||
let current_topic = if let Some(session) = self.session_manager.get(&inbound.channel).await {
|
|
||||||
let guard = session.lock().await;
|
|
||||||
guard.current_topic(&inbound.chat_id).map(|s| s.to_string())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
// 使用 ChannelInputAdapter 尝试解析命令
|
// 使用 ChannelInputAdapter 尝试解析命令
|
||||||
let adapter = ChannelInputAdapter::new();
|
let adapter = ChannelInputAdapter::new();
|
||||||
let ctx = crate::command::context::AdapterContext::new(&inbound.channel)
|
let ctx = crate::command::context::AdapterContext::new(&inbound.channel)
|
||||||
@ -137,13 +130,12 @@ impl InboundProcessor {
|
|||||||
|
|
||||||
if let Ok(Some(cmd)) = adapter.try_parse(&inbound.content, ctx) {
|
if let Ok(Some(cmd)) = adapter.try_parse(&inbound.content, ctx) {
|
||||||
// 使用命令路由器处理
|
// 使用命令路由器处理
|
||||||
let mut cmd_ctx = crate::command::context::CommandContext::new(&inbound.channel, &inbound.channel)
|
let cmd_ctx = crate::command::context::CommandContext::new(&inbound.channel, &inbound.channel)
|
||||||
.with_session_id(&session_id)
|
.with_session_id(&session_id)
|
||||||
.with_chat_id(&inbound.chat_id);
|
.with_chat_id(&inbound.chat_id);
|
||||||
// 只在有话题时才设置 topic_id
|
|
||||||
if let Some(ref topic_id) = current_topic {
|
// 记录是否是创建会话命令(用于后续处理)
|
||||||
cmd_ctx = cmd_ctx.with_topic_id(topic_id.as_str());
|
let _is_create_session = matches!(cmd, Command::CreateSession { .. });
|
||||||
}
|
|
||||||
|
|
||||||
let response = self.command_router.dispatch_with_response(cmd, cmd_ctx).await;
|
let response = self.command_router.dispatch_with_response(cmd, cmd_ctx).await;
|
||||||
|
|
||||||
|
|||||||
@ -184,9 +184,6 @@ impl Session {
|
|||||||
// 清除当前历史
|
// 清除当前历史
|
||||||
self.history.remove_history(chat_id);
|
self.history.remove_history(chat_id);
|
||||||
|
|
||||||
// 先设置当前话题(set_history 需要这个)
|
|
||||||
self.history.set_chat_topic(chat_id, topic_id.to_string());
|
|
||||||
|
|
||||||
// 加载新话题的历史
|
// 加载新话题的历史
|
||||||
let messages = self
|
let messages = self
|
||||||
.store
|
.store
|
||||||
@ -194,6 +191,7 @@ impl Session {
|
|||||||
.map_err(|e| AgentError::Other(format!("load topic messages error: {}", e)))?;
|
.map_err(|e| AgentError::Other(format!("load topic messages error: {}", e)))?;
|
||||||
|
|
||||||
self.history.set_history(chat_id, messages);
|
self.history.set_history(chat_id, messages);
|
||||||
|
self.history.set_chat_topic(chat_id, topic_id.to_string());
|
||||||
|
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
topic_id = %topic_id,
|
topic_id = %topic_id,
|
||||||
|
|||||||
@ -243,13 +243,10 @@ async fn handle_inbound(
|
|||||||
current_topic_id = ?current_topic_id,
|
current_topic_id = ?current_topic_id,
|
||||||
"Building CommandContext for WebSocket command"
|
"Building CommandContext for WebSocket command"
|
||||||
);
|
);
|
||||||
let mut cmd_ctx = CommandContext::new("websocket", "cli")
|
let cmd_ctx = CommandContext::new("websocket", "cli")
|
||||||
.with_session_id(current_session_id.as_str())
|
.with_session_id(current_session_id.as_str())
|
||||||
.with_chat_id(current_session_id.as_str());
|
.with_chat_id(current_session_id.as_str())
|
||||||
// 只在有 topic_id 时才设置
|
.with_topic_id(current_topic_id.as_deref().unwrap_or(""));
|
||||||
if let Some(ref topic_id) = *current_topic_id {
|
|
||||||
cmd_ctx = cmd_ctx.with_topic_id(topic_id.as_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 执行命令
|
// 执行命令
|
||||||
let response = router.dispatch_with_response(cmd, cmd_ctx).await;
|
let response = router.dispatch_with_response(cmd, cmd_ctx).await;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user