feat: 添加当前话题获取功能,优化命令上下文处理
This commit is contained in:
parent
549bf4df04
commit
8edc7ef905
@ -10,7 +10,6 @@ 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;
|
||||||
@ -123,6 +122,14 @@ 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)
|
||||||
@ -130,12 +137,13 @@ 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 cmd_ctx = crate::command::context::CommandContext::new(&inbound.channel, &inbound.channel)
|
let mut 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 {
|
||||||
let _is_create_session = matches!(cmd, Command::CreateSession { .. });
|
cmd_ctx = cmd_ctx.with_topic_id(topic_id.as_str());
|
||||||
|
}
|
||||||
|
|
||||||
let response = self.command_router.dispatch_with_response(cmd, cmd_ctx).await;
|
let response = self.command_router.dispatch_with_response(cmd, cmd_ctx).await;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user