matrix-mcp: document the bare name in the DM tool schemas, expand it once
This commit is contained in:
parent
64c0b8b3f0
commit
ccac95fcf4
1 changed files with 16 additions and 15 deletions
|
|
@ -524,7 +524,8 @@ fn expand_user_id(own_server: Option<&str>, input: &str) -> String {
|
|||
}
|
||||
}
|
||||
|
||||
/// Find the existing DM room with `user_id` or create one, and say where the
|
||||
/// Find the existing DM room with `user_id` (a full id, or a bare agent name,
|
||||
/// see [`expand_user_id`]) or create one, and say where the
|
||||
/// recipient stands in it. Shared by `send_dm` and `open_dm`.
|
||||
/// `direct_targets()` (cached state) is used rather than the async
|
||||
/// `is_direct()`.
|
||||
|
|
@ -535,7 +536,7 @@ fn expand_user_id(own_server: Option<&str>, input: &str) -> String {
|
|||
async fn resolve_or_create_dm(
|
||||
client: &Client,
|
||||
user_id: &str,
|
||||
) -> Result<(matrix_sdk::Room, Recipient), DaemonResponse> {
|
||||
) -> Result<(matrix_sdk::Room, Recipient, OwnedUserId), DaemonResponse> {
|
||||
let own = client.user_id().map(|u| u.server_name().to_string());
|
||||
let user_id = expand_user_id(own.as_deref(), user_id);
|
||||
let uid: OwnedUserId = user_id
|
||||
|
|
@ -567,7 +568,7 @@ async fn resolve_or_create_dm(
|
|||
room.room_id()
|
||||
)));
|
||||
}
|
||||
Ok((room, recipient))
|
||||
Ok((room, recipient, uid))
|
||||
}
|
||||
|
||||
/// The JSON fields that tell the caller where the recipient stands, with a
|
||||
|
|
@ -583,10 +584,7 @@ fn recipient_fields(recipient: Recipient) -> serde_json::Value {
|
|||
}
|
||||
|
||||
pub async fn send_dm(client: &Client, user_id: &str, body: &str) -> DaemonResponse {
|
||||
let own = client.user_id().map(|u| u.server_name().to_string());
|
||||
let user_id = expand_user_id(own.as_deref(), user_id);
|
||||
let user_id = user_id.as_str();
|
||||
let (room, recipient) = match resolve_or_create_dm(client, user_id).await {
|
||||
let (room, recipient, uid) = match resolve_or_create_dm(client, user_id).await {
|
||||
Ok(r) => r,
|
||||
Err(e) => return e,
|
||||
};
|
||||
|
|
@ -599,12 +597,12 @@ pub async fn send_dm(client: &Client, user_id: &str, body: &str) -> DaemonRespon
|
|||
let mut payload = serde_json::json!({
|
||||
"event_id": resp.response.event_id.to_string(),
|
||||
"room_id": room.room_id().to_string(),
|
||||
"user_id": user_id,
|
||||
"user_id": uid.to_string(),
|
||||
});
|
||||
merge(&mut payload, recipient_fields(recipient));
|
||||
DaemonResponse::ok(&payload)
|
||||
}
|
||||
Err(e) => DaemonResponse::error(format!("send DM to {user_id}: {e}")),
|
||||
Err(e) => DaemonResponse::error(format!("send DM to {uid}: {e}")),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -691,13 +689,13 @@ pub async fn send_file(
|
|||
/// tools (`send_file`, `send_message`, …) against that id — so there is
|
||||
/// no per-tool `_dm` variant.
|
||||
pub async fn open_dm(client: &Client, user_id: &str) -> DaemonResponse {
|
||||
let (room, recipient) = match resolve_or_create_dm(client, user_id).await {
|
||||
let (room, recipient, uid) = match resolve_or_create_dm(client, user_id).await {
|
||||
Ok(r) => r,
|
||||
Err(e) => return e,
|
||||
};
|
||||
let mut payload = serde_json::json!({
|
||||
"room_id": room.room_id().to_string(),
|
||||
"user_id": user_id,
|
||||
"user_id": uid.to_string(),
|
||||
});
|
||||
merge(&mut payload, recipient_fields(recipient));
|
||||
DaemonResponse::ok(&payload)
|
||||
|
|
|
|||
Loading…
Reference in a new issue