@aimail/mail-core
v0.1.15
Published
AIMail shared TS core: gateway client, tool functions, inbound preprocess chain (framework-agnostic; single runtime dep: typebox).
Maintainers
Readme
@aimail/mail-core
Framework-agnostic AIMail core for TypeScript: gateway HTTP client, mail /
contact / note / board tool functions, the full inbound preprocess chain,
and agentmail.json read/write. Only dependency: typebox (parameter schemas) — import it directly from
any TS agent runtime (dsh, OpenClaw, pi, or your own).
Install
pnpm add @aimail/mail-corePoint AIMAIL_HOME at your aimail home directory (default
~/.aimail), where per-address agentmail.json bindings live.
What it does
GatewayClient— authenticated HTTP client for the AIMail gateway (send / upload / download / whitelist / contacts / agent-state / threads / boards). Outbound requests carry theX-AIMail-Agentidentity header and are signed with the v1 HMAC scheme.- Tool functions —
sendMail,manageContacts,contactProfile,setContactProfile,emailSummary,setEmailSummary,searchMail, plus the board API (boardStatus,boardTaskList,boardTaskShow,boardHeartbeat,boardMembers,setPublicWhoami,activateAddressCode). - Inbound chain —
processInboundMailruns the full inbound preprocess (recipient/sender enrichment, persona normalization, direct-message and mention detection, attachment download, backend-field stripping, inbound logging) and intercepts ping/pong health probes;verifySignaturechecks webhook HMAC signatures. MAIL_TOOLS— the semantic registry of all 15 tools (names, descriptions, TypeBox parameter shapes, handlers). Adapters iterate this single array so every platform surfaces an identical tool surface.- Config loaders —
loadConfigByEmail,loadConfigByAgentId,loadConfigBySessionId,saveAgentConfig,updateAgentConfig(per-addressagentmail.jsonis the sole identity source). - Identity —
setAgentIdentity/setAgentModelset the outboundX-AIMail-Agentheader ({platform}/{version}+{model}).
Usage sketch
import { sendMail, processInboundMail, verifySignature, MAIL_TOOLS } from '@aimail/mail-core'
// send (tool functions take a ToolCtx resolved from agentmail.json)
const result = await sendMail({ systemId, email }, { to, subject, body })
// inbound (HMAC-verified payload from the aimail-bridge)
if (verifySignature(rawBody, sig, webhookSecret)) {
const enriched = await processInboundMail(payload, headers, { systemId, email })
if (enriched === null) {
// ping/pong intercepted — already answered
} else {
// deliver enriched JSON into the agent session
}
}
// adapter registration: iterate the semantic registry
for (const tool of MAIL_TOOLS) { /* bind name/description/params/handler */ }API notes
processInboundMailreturnsnullwhen the mail was a ping/pong probe (the chain answers it in-place); otherwise it returns the enriched payload to hand to the agent.verifySignaturecompares a timing-safe HMAC-SHA256 of the raw body against theX-Webhook-Signatureheader, keyed by the per-addresswebhook_secret.- The inbound chain is the inbound contract (not an optional preprocessing layer): every platform adapter must call it before handing mail to the agent.
Related repositories
- metercai/aimail — the AIMail monorepo:
CLI (
cli/), Python SDK (pysdk/), TypeScript SDK (tssdk/), bridge distributions. - metercai/aimail-gateway — the AIMail gateway: SMTP/HTTP mail service, address & activation APIs, and the board endpoints the SDK client talks to.
