Prevent self-directed agent messages
This commit is contained in:
1 parent
1a7eb8f1b3
commit
a4af4a866a
6 files changed
+169
No files matched your search
@@ -155,6 +155,12 @@ function handleAgentNotification<K extends "notify_agent" | "send_message">({
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (channel === "direct" && toAgentId === fromAgentId) {
|
||||
logger.info(
|
||||
`[automation] Skipping rule "${rule.name}" - direct messages require two distinct participants`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const dispatchResult = dispatchAgentMessage(
|
||||
{ db, emitEvent, publishDomainChanged, wakeAgentIfPossible },
|
||||
|
||||
@@ -61,6 +61,9 @@ export function buildMessageMethods(
|
||||
if (channel === "direct" && !input.toAgentId) {
|
||||
throw new Error("Direct messages require a recipient.");
|
||||
}
|
||||
if (channel === "direct" && input.toAgentId === input.fromAgentId) {
|
||||
throw new Error("Direct messages require two distinct participants.");
|
||||
}
|
||||
const senderKind = input.senderKind
|
||||
?? (input.fromAgentId === BOARD_READER_ID ? "human" : "agent");
|
||||
const id = randomUUID();
|
||||
|
||||
@@ -53,6 +53,7 @@ export interface NormalizedAgentMessageInput {
|
||||
export interface MessageValidationError {
|
||||
code:
|
||||
| "DIRECT_MESSAGE_RECIPIENT_REQUIRED"
|
||||
| "SELF_DIRECT_MESSAGE_FORBIDDEN"
|
||||
| "NON_DIRECT_MESSAGE_RECIPIENT_FORBIDDEN"
|
||||
| "INVALID_COMPANY_REFERENCE"
|
||||
| "CHANNEL_TARGET_REQUIRED"
|
||||
@@ -147,6 +148,12 @@ export function validateAgentMessageInput(
|
||||
message: "Direct messages require a recipient agent.",
|
||||
};
|
||||
}
|
||||
if (input.channel === "direct" && input.toAgentId === input.fromAgentId) {
|
||||
return {
|
||||
code: "SELF_DIRECT_MESSAGE_FORBIDDEN",
|
||||
message: "Direct messages require two distinct participants.",
|
||||
};
|
||||
}
|
||||
if (input.channel !== "direct" && input.toAgentId) {
|
||||
return {
|
||||
code: "NON_DIRECT_MESSAGE_RECIPIENT_FORBIDDEN",
|
||||
|
||||
Reference in new issue
Block a user