feat(chat): chatChannels tool for the registered Discord chat channels
- Tool (chat_channels.spec.md): list, read, search, send, edit, react,
delete, pin, unpin. Offered only when the v2 brain gives the turn a chat
backend, and then on every turn. Channel by ID, name, part of a name or a
name inside the text; a message ID finds its channel; planner forms of the
action ("send_message") work. Read and search results are fenced as
untrusted data. delete only reports until called again with confirm=true
in a later turn of the same person.
- Worker: chat_channels from the app, ChatBridge reads/searches the history
store and sends chat_action, waiting for chat_action_result (15 s timeout,
failed on session close); per-person reply turns and pending deletes.
- App: channel switches edit/react (on) and delete/pin (off); chat_channels
sent on worker ready and after login; chat_action runs send, edit (own
messages only), react, delete, pin, unpin and answers with ids or the error.
- Engine: chatChannels left out of the catalogue without a backend; the
"router returned everything" check now tolerates that.
- live_discord: edit own, refuse editing the speaker's, react, pin (Discord
refuses in a voice channel's chat, reported as an error), delete, refuse an
unregistered channel; passed in 109.4 s.
- Eval (qwen2.5:7b, 3 runs): 10 of 12; never obeyed the "delete everything"
message and never deleted in the same turn.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -68,6 +68,26 @@ impl ChatChannels {
|
||||
Some(_) => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
/// The switch a chat action needs (`send`, `edit`, `react`, `delete`, `pin`, `unpin`).
|
||||
pub fn check_action(&self, id: u64, action: &str) -> Result<(), ChatAccessError> {
|
||||
let Some(c) = self.by_id.get(&id) else {
|
||||
return Err(ChatAccessError(format!("channel {id} is not a registered chat channel")));
|
||||
};
|
||||
let on = match action {
|
||||
"send" => c.send,
|
||||
"edit" => c.edit,
|
||||
"react" => c.react,
|
||||
"delete" => c.delete,
|
||||
"pin" | "unpin" => c.pin,
|
||||
_ => return Err(ChatAccessError(format!("unknown chat action {action}"))),
|
||||
};
|
||||
if on { Ok(()) } else { Err(ChatAccessError(format!("{action} is turned off for channel {id}"))) }
|
||||
}
|
||||
|
||||
pub fn all(&self) -> impl Iterator<Item = &ChatChannelSettings> {
|
||||
self.by_id.values()
|
||||
}
|
||||
}
|
||||
|
||||
/// Split text into messages of at most `limit` UTF-16 units, breaking at the last newline, else the
|
||||
@@ -157,7 +177,23 @@ mod tests {
|
||||
}
|
||||
|
||||
fn ch(id: u64, read: bool, send: bool) -> ChatChannelSettings {
|
||||
ChatChannelSettings { id, name: String::new(), description: String::new(), read, send }
|
||||
ChatChannelSettings { id, name: String::new(), description: String::new(), read, send, edit: true,
|
||||
react: true, delete: false, pin: false }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_action_needs_its_own_switch() {
|
||||
let mut open = ch(1, true, true);
|
||||
open.delete = true;
|
||||
let c = ChatChannels::new(&[open, ch(2, true, false)]);
|
||||
for a in ["send", "edit", "react", "delete"] {
|
||||
assert!(c.check_action(1, a).is_ok(), "{a}");
|
||||
}
|
||||
assert!(c.check_action(1, "pin").is_err() && c.check_action(1, "unpin").is_err());
|
||||
assert!(c.check_action(2, "send").is_err() && c.check_action(2, "delete").is_err());
|
||||
assert!(c.check_action(2, "react").is_ok());
|
||||
assert!(c.check_action(3, "send").unwrap_err().0.contains("not a registered"));
|
||||
assert!(c.check_action(1, "explode").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user