# Mail Rule Builder

> Write a mail rule as a sentence and get it compiled into editable parts: when, if, then, ask first, and the agent that runs it. Every condition and step is a token you can change or remove. A dry run over recent mail shows what it would have matched, with the matching phrase highlighted and which emails it would ask about, and the agent view shows the same rule as a create_rule call.

- Slug: `mail-rule-builder`
- Category: [Email](https://www.assembli.design/category/email.md)
- Type: component
- Tags: email, rules, automation, agents, natural-language, filters
- npm dependencies: lucide-react, motion
- shadcn/ui dependencies: button, dropdown-menu, @assembli/avatar, @assembli/autosize-textarea, @assembli/chip, @assembli/switch
- Live preview: https://www.assembli.design/preview/mail-rule-builder
- Page: https://www.assembli.design/components/mail-rule-builder

![Mail Rule Builder preview](https://www.assembli.design/thumbnails/mail-rule-builder-light.png)

## Props

Other props pass through to the root element.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `defaultSentence` | `string` | `""` |  |
| `defaultRule` | `Rule` |  |  |
| `compile` | `(sentence: string) => Rule \| Promise<Rule>` |  | Turn a sentence into a rule, e.g. with a model. Defaults to `compileRule`, a small deterministic parser. |
| `history` | `RuleTestMail[]` | `[]` | Recent mail for the dry run. |
| `historyLabel` | `string` | `"last 30 days"` |  |
| `onAction` | `(action: MailAction) => void` |  | `create_rule` with `rule: ruleToJSON(rule)` on save, the person as the actor. |
| `agents` | `MailAgent[]` | `DEFAULT_AGENTS` |  |
| `user` | `string` | `"Ines Moreau"` |  |
| `domain` | `string` | `"larkspur.co"` | Domain for bare forwarding names ("forward to accounting"). |

## Install

One-time setup (needs a subscription):

1. Add the registry to the project's `components.json`: `{"@assembli":{"url":"https://www.assembli.design/r/{name}.json","headers":{"Authorization":"Bearer ${ASSEMBLI_API_KEY}"}}}` (merge into `"registries"`).
2. Put an API key from https://www.assembli.design/account in `.env.local` as `ASSEMBLI_API_KEY=asm_…`.

Then install with the shadcn CLI (writes `components/mail-rule-builder/mail-rule-builder.tsx` and installs dependencies):

```bash
npx shadcn@latest add @assembli/mail-rule-builder
```

Registry item JSON: https://www.assembli.design/r/mail-rule-builder.json (send `Authorization: Bearer <api key>`)

## Code

> Component source needs an Assembli subscription ($12/month or $96/year) and an API key sent as `Authorization: Bearer <key>`. To get one without copying anything, POST https://www.assembli.design/api/agent/login (or call the MCP tool connect_account), show the user the link it returns, and poll https://www.assembli.design/api/agent/token for the key. Or subscribe at https://www.assembli.design/pricing and create a key at https://www.assembli.design/account.
