← Public packages
@kody/agent-mail
AgentMail inboxes for agents: create/list inboxes, messages, threads, and Svix webhook ingress.
Files
import { agentMailRequest, requireConfirmOrDryRun } from './core.ts'
import { listPath, normalizeEntry, type ListSelectorInput } from './lists.ts'
export type RemoveRuleInput = ListSelectorInput & {
/** Email address or domain to remove. */
entry?: string
/** Alias for `entry`. */
match?: string
/** Preview the request without calling AgentMail. */
dryRun?: boolean
/** Required true for a live delete (unless dryRun). */
confirm?: boolean
}
/**
* Remove an email address or domain from an AgentMail allow or block list.
* Requires confirm: true for a live DELETE, or dryRun: true to preview.
* Removing the last receive-allow entry turns allowlist-only mode off for
* that scope. Entries AgentMail marks `read_only` cannot be deleted.
* Uses DELETE /v0/lists/{direction}/{type}/{entry} (or pod / inbox variant).
*
* @param input.type - `allow` or `block` (required)
* @param input.entry - Email address or domain (or `match`)
* @param input.direction - `receive` (default), `reply`, or `send`
* @param input.inboxId - Optional inbox scope
* @param input.podId - Optional pod scope
* @param input.dryRun - Preview without deleting
* @param input.confirm - Must be true for a live delete
* @returns `{ dryRun, removed?, path, ... }`
*
* @example
* import removeRule from 'kody:@kody/agent-mail/remove-rule'
* const preview = await removeRule({ type: 'block', entry: 'spam.example', dryRun: true })
*/
export default async function removeRule(input: RemoveRuleInput) {
const mode = requireConfirmOrDryRun(input, 'remove a live AgentMail list entry')
const { entry, entryType } = normalizeEntry(input.entry ?? input.match)
const target = listPath(input, entry)
const base = {
scope: target.scope,
scopeId: target.scopeId,
direction: target.direction,
type: target.type,
entry,
entryType,
path: target.path,
}
if (mode === 'dryRun') {
return { dryRun: true as const, method: 'DELETE', ...base }
}
await agentMailRequest({
method: 'DELETE',
path: target.path,
label: 'AgentMail delete list entry',
})
return { dryRun: false as const, removed: true as const, ...base }
}