feat(matrix mcp): add resolve_invite tool to accept or reject pending invites
This commit is contained in:
parent
c59a0de01e
commit
86f0de751f
6 changed files with 121 additions and 19 deletions
|
|
@ -21,7 +21,7 @@ use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
|
|||
use tokio::net::UnixStream;
|
||||
|
||||
use hive_matrix_mcp::paths;
|
||||
use hive_matrix_mcp::protocol::{DaemonRequest, DaemonResponse};
|
||||
use hive_matrix_mcp::protocol::{DaemonRequest, DaemonResponse, InviteAction};
|
||||
|
||||
/// Send `req` to the daemon and read back the response. Each call is a
|
||||
/// fresh unix-socket connection — short-lived (the daemon dispatch is
|
||||
|
|
@ -127,6 +127,16 @@ struct JoinRoomArgs {
|
|||
room: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, JsonSchema)]
|
||||
struct ResolveInviteArgs {
|
||||
/// Matrix room id (`!abc:server`) or alias (`#name:server`) you have
|
||||
/// a pending invite to.
|
||||
room: String,
|
||||
/// What to do with the invite: `"accept"` (join the room) or
|
||||
/// `"reject"` (decline and leave).
|
||||
action: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, JsonSchema)]
|
||||
struct InviteUserArgs {
|
||||
/// Matrix room id (`!abc:server`) or canonical alias (`#name:server`)
|
||||
|
|
@ -231,7 +241,7 @@ impl MatrixBridge {
|
|||
#[tool(
|
||||
description = "List rooms this agent has been invited to but not yet joined. \
|
||||
Each row has the room id, canonical alias (when set), and display name. \
|
||||
Use `join_room` to accept an invite."
|
||||
Use `resolve_invite` to accept or reject an invite."
|
||||
)]
|
||||
async fn list_invites(&self, Parameters(_): Parameters<ListInvitesArgs>) -> String {
|
||||
render(round_trip(DaemonRequest::ListInvites).await)
|
||||
|
|
@ -239,13 +249,40 @@ impl MatrixBridge {
|
|||
|
||||
#[tool(
|
||||
description = "Join a matrix room by id (!abc:server) or alias (#name:server). \
|
||||
Accepts a pending invite if one exists; also joins public rooms. \
|
||||
After joining the room will appear in `list_rooms`."
|
||||
Also accepts a pending invite if one exists, but for invites prefer \
|
||||
`resolve_invite` (which can also reject). Use `join_room` to join a \
|
||||
public room you weren't invited to. After joining the room appears in \
|
||||
`list_rooms`."
|
||||
)]
|
||||
async fn join_room(&self, Parameters(args): Parameters<JoinRoomArgs>) -> String {
|
||||
render(round_trip(DaemonRequest::JoinRoom { room: args.room }).await)
|
||||
}
|
||||
|
||||
#[tool(
|
||||
description = "Accept or reject a pending matrix invite. `room` is a room id \
|
||||
(!abc:server) or alias (#name:server) you were invited to; `action` is \
|
||||
\"accept\" (join the room) or \"reject\" (decline and leave). See pending \
|
||||
invites with `list_invites`."
|
||||
)]
|
||||
async fn resolve_invite(&self, Parameters(args): Parameters<ResolveInviteArgs>) -> String {
|
||||
let action = match args.action.trim().to_ascii_lowercase().as_str() {
|
||||
"accept" => InviteAction::Accept,
|
||||
"reject" => InviteAction::Reject,
|
||||
other => {
|
||||
return format!(
|
||||
"matrix error: invalid action {other:?} — use \"accept\" or \"reject\""
|
||||
);
|
||||
}
|
||||
};
|
||||
render(
|
||||
round_trip(DaemonRequest::ResolveInvite {
|
||||
room: args.room,
|
||||
action,
|
||||
})
|
||||
.await,
|
||||
)
|
||||
}
|
||||
|
||||
#[tool(
|
||||
description = "Invite a user to a matrix room you're already in. `room` is a \
|
||||
room id (!abc:server) or alias (#name:server); `user_id` is the invitee \
|
||||
|
|
@ -290,9 +327,9 @@ impl MatrixBridge {
|
|||
to thread a reply, `mark_read` to acknowledge an event. Discover \
|
||||
rooms with `list_rooms`, members with `list_room_members`, recent \
|
||||
timeline with `read_room`. See pending invites with `list_invites`; \
|
||||
accept an invite or join a public room with `join_room`. Room \
|
||||
references accept ids (!abc:server) or aliases (#name:server); \
|
||||
user references use @user:server.")]
|
||||
accept or reject an invite with `resolve_invite`; join a public \
|
||||
room with `join_room`. Room references accept ids (!abc:server) \
|
||||
or aliases (#name:server); user references use @user:server.")]
|
||||
impl ServerHandler for MatrixBridge {}
|
||||
|
||||
#[tokio::main]
|
||||
|
|
|
|||
Loading…
Reference in a new issue