@mailsai/sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mails.ai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,127 @@
1
+ # @mailsai/sdk
2
+
3
+ Email API for AI agents — TypeScript / JavaScript SDK.
4
+
5
+ Per-agent email addresses on your domain, per-agent reputation, and prompt-injection scanning on every inbound. Your agent reads the reply and decides what to say — intent + entity extraction is opt-in.
6
+
7
+ ```bash
8
+ npm install @mailsai/sdk
9
+ ```
10
+
11
+ ## Quick start
12
+
13
+ ```ts
14
+ import { mails } from "@mailsai/sdk";
15
+
16
+ // Reads MAILS_API_KEY from env (or pass via mails.agent(name, { apiKey: "mk_live_..." }))
17
+ const sarah = mails.agent("sarah");
18
+
19
+ await sarah.send({
20
+ to: "lead@example.com",
21
+ subject: "Demo",
22
+ body: "Hi — looking forward to talking.",
23
+ });
24
+
25
+ sarah.onReply((reply) => {
26
+ // Always present — the delivery + security + identity layer:
27
+ // reply.injection_score → 0.02 (six-category prompt-injection scan)
28
+ // reply.sender_reputation → 0.91 (per-agent reputation)
29
+ //
30
+ // Present only when classification is enabled (opt-in, +$0.003/inbound):
31
+ // reply.intent → "schedule_demo" | "ask_question" | "decline" | …
32
+ // reply.entities → { date: "2026-05-16", time: "10:00", … }
33
+ // reply.urgency → 0.8
34
+ //
35
+ // Your agent reads the reply and decides what to send next.
36
+ console.log(reply.injection_score, reply.sender_reputation);
37
+ });
38
+ ```
39
+
40
+ ## Lower-level client
41
+
42
+ For full access to all resources (threads, drafts, events, agents, suppression, webhooks, reputation, billing, logs):
43
+
44
+ ```ts
45
+ import { createClient } from "@mailsai/sdk";
46
+
47
+ const client = createClient({ apiKey: process.env.MAILS_API_KEY! });
48
+
49
+ // Send via any agent
50
+ await client.send("sarah", { to: "lead@example.com", subject: "Demo", body: "…" });
51
+
52
+ // Or call resources directly
53
+ const threads = await client.threads.list({ agent_id: "agent_abc123" });
54
+ const usage = await client.billing.usage();
55
+ const reputation = await client.reputation.get("agent_abc123");
56
+
57
+ // SSE stream of inbound events
58
+ const ctrl = client.events.stream({
59
+ event_types: ["reply.received", "message.delivered"],
60
+ onEvent: (e) => console.log(e.type, e),
61
+ onError: (err) => console.error(err),
62
+ });
63
+ // …later
64
+ ctrl.abort();
65
+ ```
66
+
67
+ ## Webhook verification
68
+
69
+ ```ts
70
+ import { mails } from "@mailsai/sdk";
71
+
72
+ // In your webhook handler:
73
+ const event = mails.webhooks.verify(
74
+ rawBody,
75
+ req.headers["x-mails-signature"]!,
76
+ process.env.MAILS_WEBHOOK_SECRET!
77
+ );
78
+ if (!event) return new Response("invalid signature", { status: 400 });
79
+ // event is the verified inbound event payload
80
+ ```
81
+
82
+ ## Configuration
83
+
84
+ | Option | Env var | Default |
85
+ |---|---|---|
86
+ | `apiKey` | `MAILS_API_KEY` | none — required |
87
+ | `baseUrl` | `MAILS_BASE_URL` | `https://api.mails.ai` |
88
+ | `fetch` | — | global `fetch` |
89
+
90
+ ## Idempotency
91
+
92
+ ```ts
93
+ await sarah.send({
94
+ to: "lead@example.com",
95
+ subject: "Demo",
96
+ body: "…",
97
+ idempotency_key: "weekly-followup-2026-05-14-lead-123",
98
+ });
99
+ ```
100
+
101
+ Replays within 24 hours return the original response with `Idempotent-Replay: true` header.
102
+
103
+ ## Errors
104
+
105
+ All API errors throw `MailsError`:
106
+
107
+ ```ts
108
+ import { MailsError } from "@mailsai/sdk";
109
+
110
+ try {
111
+ await sarah.send({ to: "blocked@example.com", subject: "…", body: "…" });
112
+ } catch (err) {
113
+ if (err instanceof MailsError) {
114
+ console.error(err.type, err.code, err.message, err.status, err.requestId);
115
+ }
116
+ }
117
+ ```
118
+
119
+ ## Documentation
120
+
121
+ - Full docs: [mails.ai/docs](https://mails.ai/docs)
122
+ - API reference: [mails.ai/docs/api](https://mails.ai/docs)
123
+ - Source: [github.com/RolloutsAI/mails-api](https://github.com/RolloutsAI/mails-api/tree/main/packages/sdk)
124
+
125
+ ## License
126
+
127
+ MIT