Fix gateway bot proxying freeform messages as commands
The gateway proxy was sending every message's first word to the project server's /api/bot/command endpoint, then displaying the "Unknown command" response before falling through to the LLM. Now the proxy only fires when the first word matches a known bot command. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -201,7 +201,16 @@ pub(super) async fn on_room_message(
|
|||||||
None => (stripped.to_ascii_lowercase(), String::new()),
|
None => (stripped.to_ascii_lowercase(), String::new()),
|
||||||
};
|
};
|
||||||
|
|
||||||
if !cmd.is_empty() && !GATEWAY_LOCAL_COMMANDS.contains(&cmd.as_str()) {
|
// Only proxy if the first word is a known bot command (sync or async).
|
||||||
|
let is_known_command = !cmd.is_empty()
|
||||||
|
&& !GATEWAY_LOCAL_COMMANDS.contains(&cmd.as_str())
|
||||||
|
&& (crate::chat::commands::commands()
|
||||||
|
.iter()
|
||||||
|
.any(|c| c.name == cmd)
|
||||||
|
|| ["assign", "start", "delete", "rebuild", "rmtree", "htop", "timer"]
|
||||||
|
.contains(&cmd.as_str()));
|
||||||
|
|
||||||
|
if is_known_command {
|
||||||
// Proxy to the active project server.
|
// Proxy to the active project server.
|
||||||
let response = match ctx.proxy_bot_command(&cmd, &args).await {
|
let response = match ctx.proxy_bot_command(&cmd, &args).await {
|
||||||
Some(r) => r,
|
Some(r) => r,
|
||||||
@@ -216,16 +225,7 @@ pub(super) async fn on_room_message(
|
|||||||
{
|
{
|
||||||
ctx.bot_sent_event_ids.lock().await.insert(event_id);
|
ctx.bot_sent_event_ids.lock().await.insert(event_id);
|
||||||
}
|
}
|
||||||
// If the command was recognized by the project server, we're done.
|
return;
|
||||||
// If it was not a command at all (freeform text), fall through to the LLM.
|
|
||||||
if crate::chat::commands::commands()
|
|
||||||
.iter()
|
|
||||||
.any(|c| c.name == cmd)
|
|
||||||
|| ["assign", "start", "delete", "rebuild", "rmtree", "htop", "timer"]
|
|
||||||
.contains(&cmd.as_str())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Gateway-local commands and freeform text fall through to normal handling below.
|
// Gateway-local commands and freeform text fall through to normal handling below.
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user