inboxer 0.0.0-stage → 0.2.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 +21 -0
- package/README.md +376 -2
- package/dist/app.d.ts +6 -0
- package/dist/app.js +56 -0
- package/dist/auth.d.ts +33 -0
- package/dist/auth.js +111 -0
- package/dist/config.d.ts +23 -0
- package/dist/config.js +90 -0
- package/dist/core/address.d.ts +6 -0
- package/dist/core/address.js +16 -0
- package/dist/core/attachments.d.ts +9 -0
- package/dist/core/attachments.js +30 -0
- package/dist/core/context.d.ts +10 -0
- package/dist/core/context.js +21 -0
- package/dist/core/mail.d.ts +170 -0
- package/dist/core/mail.js +656 -0
- package/dist/core/sync.d.ts +16 -0
- package/dist/core/sync.js +44 -0
- package/dist/core/text.d.ts +8 -0
- package/dist/core/text.js +45 -0
- package/dist/core/threads.d.ts +21 -0
- package/dist/core/threads.js +81 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +51 -0
- package/dist/mcp.d.ts +5 -0
- package/dist/mcp.js +198 -0
- package/dist/provider/index.d.ts +3 -0
- package/dist/provider/index.js +11 -0
- package/dist/provider/resend.d.ts +8 -0
- package/dist/provider/resend.js +184 -0
- package/dist/provider/types.d.ts +77 -0
- package/dist/provider/types.js +6 -0
- package/dist/store.d.ts +54 -0
- package/dist/store.js +148 -0
- package/dist/types.d.ts +138 -0
- package/dist/types.js +1 -0
- package/dist/ui/assets.d.ts +8 -0
- package/dist/ui/assets.js +13 -0
- package/dist/ui/routes.d.ts +11 -0
- package/dist/ui/routes.js +232 -0
- package/dist/ui/static/app.js +27 -0
- package/dist/ui/static/htmx.min.js +1 -0
- package/dist/ui/static/style.css +179 -0
- package/dist/ui/strings.d.ts +67 -0
- package/dist/ui/strings.js +67 -0
- package/dist/ui/views.d.ts +45 -0
- package/dist/ui/views.js +275 -0
- package/package.json +81 -4
- package/skills/inboxer/SKILL.md +118 -0
- package/src/app.ts +56 -0
- package/src/auth.ts +119 -0
- package/src/config.ts +92 -0
- package/src/core/address.ts +19 -0
- package/src/core/attachments.ts +33 -0
- package/src/core/context.ts +28 -0
- package/src/core/mail.ts +737 -0
- package/src/core/sync.ts +51 -0
- package/src/core/text.ts +52 -0
- package/src/core/threads.ts +102 -0
- package/src/index.ts +93 -0
- package/src/mcp.ts +233 -0
- package/src/provider/index.ts +14 -0
- package/src/provider/resend.ts +235 -0
- package/src/provider/types.ts +82 -0
- package/src/store.ts +187 -0
- package/src/types.ts +140 -0
- package/src/ui/assets.ts +21 -0
- package/src/ui/routes.ts +252 -0
- package/src/ui/static/app.js +27 -0
- package/src/ui/static/htmx.min.js +1 -0
- package/src/ui/static/style.css +179 -0
- package/src/ui/strings.ts +73 -0
- package/src/ui/views.ts +315 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** Every user-facing UI string. Translate here. */
|
|
2
|
+
export const S = {
|
|
3
|
+
appName: "Inboxer",
|
|
4
|
+
navDrafts: "Drafts",
|
|
5
|
+
navInbox: "Inbox",
|
|
6
|
+
navDevices: "Devices",
|
|
7
|
+
logout: "Log out",
|
|
8
|
+
themeSystem: "System",
|
|
9
|
+
themeLight: "Light",
|
|
10
|
+
themeDark: "Dark",
|
|
11
|
+
theme: "Theme",
|
|
12
|
+
draftsEmpty: "No drafts waiting for review.",
|
|
13
|
+
to: "To",
|
|
14
|
+
cc: "Cc",
|
|
15
|
+
bcc: "Bcc",
|
|
16
|
+
subject: "Subject",
|
|
17
|
+
body: "Message",
|
|
18
|
+
from: "From",
|
|
19
|
+
edit: "Edit",
|
|
20
|
+
send: "Send",
|
|
21
|
+
discard: "Discard",
|
|
22
|
+
save: "Save",
|
|
23
|
+
saveAndSend: "Save & Send",
|
|
24
|
+
cancel: "Cancel",
|
|
25
|
+
attach: "Attach",
|
|
26
|
+
remove: "Remove",
|
|
27
|
+
dropFiles: "Drop files to attach",
|
|
28
|
+
tooLarge: "is larger than",
|
|
29
|
+
sending: "Sending to",
|
|
30
|
+
discarding: "Discarding draft",
|
|
31
|
+
undo: "Undo",
|
|
32
|
+
sentTo: "Sent to",
|
|
33
|
+
discarded: "Draft discarded.",
|
|
34
|
+
editedByHuman: "Edited by you",
|
|
35
|
+
thread: "Thread",
|
|
36
|
+
thisThread: "This thread",
|
|
37
|
+
context: "Context",
|
|
38
|
+
draft: "Draft",
|
|
39
|
+
conflictTitle: "This draft changed while you were editing.",
|
|
40
|
+
yourVersion: "Your version",
|
|
41
|
+
currentVersion: "Current version",
|
|
42
|
+
filterUnanswered: "Unanswered",
|
|
43
|
+
filterAll: "All",
|
|
44
|
+
filterArchived: "Archived",
|
|
45
|
+
allMailboxes: "All mailboxes",
|
|
46
|
+
filter: "Filter",
|
|
47
|
+
inboxEmpty: "No threads.",
|
|
48
|
+
unread: "unread",
|
|
49
|
+
hasDraft: "draft",
|
|
50
|
+
archive: "Archive",
|
|
51
|
+
unarchive: "Move to inbox",
|
|
52
|
+
status: "Status",
|
|
53
|
+
devicesEmpty: "No signed-in devices.",
|
|
54
|
+
thisDevice: "This device",
|
|
55
|
+
revoke: "Revoke",
|
|
56
|
+
createdBy: "Link from",
|
|
57
|
+
lastSeen: "Last seen",
|
|
58
|
+
signedIn: "Signed in",
|
|
59
|
+
unknownDevice: "Unknown browser",
|
|
60
|
+
signInTitle: "Sign in on this device",
|
|
61
|
+
signInButton: "Sign in",
|
|
62
|
+
linkUsed: "This link was already used or expired.",
|
|
63
|
+
notSignedIn: "You are not signed in. Ask your agent for a login link.",
|
|
64
|
+
signedOut: "You are signed out.",
|
|
65
|
+
notFound: "Not found.",
|
|
66
|
+
error: "Something went wrong.",
|
|
67
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { HtmlEscapedString } from "hono/utils/html";
|
|
2
|
+
import type { MessageView } from "../core/mail.ts";
|
|
3
|
+
import type { Contact, Context, Message, Session, Thread } from "../types.ts";
|
|
4
|
+
export type View = HtmlEscapedString;
|
|
5
|
+
export type Theme = "system" | "light" | "dark";
|
|
6
|
+
export type Page = "drafts" | "inbox" | "devices" | null;
|
|
7
|
+
export declare function layout(title: string, body: View, opts: {
|
|
8
|
+
theme: Theme;
|
|
9
|
+
page: Page;
|
|
10
|
+
draftCount?: number;
|
|
11
|
+
signedIn: boolean;
|
|
12
|
+
domains?: string[];
|
|
13
|
+
}): View;
|
|
14
|
+
export declare function message(lines: string[]): View;
|
|
15
|
+
export declare function signIn(token: string, valid: boolean): View;
|
|
16
|
+
/** Image types a browser renders without running code; SVG is left out on purpose. */
|
|
17
|
+
export declare function isPreviewable(contentType: string): boolean;
|
|
18
|
+
export declare function messageCard(m: MessageView): View;
|
|
19
|
+
export interface ContextView {
|
|
20
|
+
context: Context | null;
|
|
21
|
+
contacts: Contact[];
|
|
22
|
+
}
|
|
23
|
+
export declare function draftCard(d: Message, history: MessageView[], ctx: ContextView | null): View;
|
|
24
|
+
export interface DraftForm {
|
|
25
|
+
to: string;
|
|
26
|
+
cc: string;
|
|
27
|
+
subject: string;
|
|
28
|
+
text: string;
|
|
29
|
+
}
|
|
30
|
+
export declare function draftEditor(d: Message, form: DraftForm, conflict: Message | null): View;
|
|
31
|
+
/** The editor's attachment list with remove buttons, and the picker that drag and drop also feeds. */
|
|
32
|
+
export declare function draftFiles(d: Message, error: string | null): View;
|
|
33
|
+
export declare function draftDone(id: string, text: string): View;
|
|
34
|
+
export declare function draftsPage(drafts: {
|
|
35
|
+
draft: Message;
|
|
36
|
+
history: MessageView[];
|
|
37
|
+
ctx: ContextView;
|
|
38
|
+
}[]): View;
|
|
39
|
+
export declare function inboxPage(threads: Thread[], mailboxes: string[], filter: {
|
|
40
|
+
mailbox: string;
|
|
41
|
+
status: string;
|
|
42
|
+
}, own: Set<string>): View;
|
|
43
|
+
export declare function threadPage(thread: Thread, items: View[], ctx: ContextView): View;
|
|
44
|
+
export declare function archiveButton(thread: Thread): View;
|
|
45
|
+
export declare function devicesPage(sessions: Session[], currentId: string): View;
|
package/dist/ui/views.js
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { html, raw } from "hono/html";
|
|
2
|
+
import { ASSETS } from "./assets.js";
|
|
3
|
+
import { S } from "./strings.js";
|
|
4
|
+
/** Views never await, so `html` returns a plain escaped string. */
|
|
5
|
+
function h(strings, ...values) {
|
|
6
|
+
return html(strings, ...values);
|
|
7
|
+
}
|
|
8
|
+
function join(items) {
|
|
9
|
+
return raw(items.join(""));
|
|
10
|
+
}
|
|
11
|
+
function when(condition, view) {
|
|
12
|
+
return condition ? view() : "";
|
|
13
|
+
}
|
|
14
|
+
function formatDate(iso) {
|
|
15
|
+
const date = new Date(iso);
|
|
16
|
+
const sameDay = date.toDateString() === new Date().toDateString();
|
|
17
|
+
return sameDay
|
|
18
|
+
? date.toLocaleTimeString("en", { hour: "2-digit", minute: "2-digit" })
|
|
19
|
+
: date.toLocaleDateString("en", { month: "short", day: "numeric", year: "numeric" });
|
|
20
|
+
}
|
|
21
|
+
export function layout(title, body, opts) {
|
|
22
|
+
const nav = (page, href, label, extra = "") => h `<a href="${href}" ${raw(opts.page === page ? 'aria-current="page"' : "")}>${label}${extra}</a>`;
|
|
23
|
+
return h `<!doctype html>
|
|
24
|
+
<html lang="en" ${raw(opts.theme === "system" ? "" : `data-theme="${opts.theme}"`)}>
|
|
25
|
+
<head>
|
|
26
|
+
<meta charset="utf-8">
|
|
27
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
28
|
+
<title>${title} · ${S.appName}</title>
|
|
29
|
+
<link rel="stylesheet" href="${ASSETS["style.css"].url}">
|
|
30
|
+
<script src="${ASSETS["htmx.min.js"].url}" defer></script>
|
|
31
|
+
<script src="${ASSETS["app.js"].url}" defer></script>
|
|
32
|
+
</head>
|
|
33
|
+
<body>
|
|
34
|
+
${when(opts.signedIn, () => h `<header>
|
|
35
|
+
<nav>
|
|
36
|
+
${nav("drafts", "/", S.navDrafts, opts.draftCount ? h ` <span class="count">${opts.draftCount}</span>` : "")}
|
|
37
|
+
${nav("inbox", "/inbox", S.navInbox)}
|
|
38
|
+
${nav("devices", "/devices", S.navDevices)}
|
|
39
|
+
</nav>
|
|
40
|
+
<form method="post" action="/theme">
|
|
41
|
+
<span class="select"><select name="theme" aria-label="${S.theme}" onchange="this.form.submit()">
|
|
42
|
+
${join(["system", "light", "dark"].map(t => h `<option value="${t}" ${raw(t === opts.theme ? "selected" : "")}>${{ system: S.themeSystem, light: S.themeLight, dark: S.themeDark }[t]}</option>`))}
|
|
43
|
+
</select></span>
|
|
44
|
+
</form>
|
|
45
|
+
<form method="post" action="/logout"><button class="link">${S.logout}</button></form>
|
|
46
|
+
</header>`)}
|
|
47
|
+
<main>${when(opts.domains?.length, () => h `<div class="domain">${opts.domains.join(" · ")}</div>`)}${body}</main>
|
|
48
|
+
</body>
|
|
49
|
+
</html>`;
|
|
50
|
+
}
|
|
51
|
+
export function message(lines) {
|
|
52
|
+
return h `<div class="centered">${join(lines.map(l => h `<p>${l}</p>`))}</div>`;
|
|
53
|
+
}
|
|
54
|
+
export function signIn(token, valid) {
|
|
55
|
+
if (!valid)
|
|
56
|
+
return message([S.linkUsed]);
|
|
57
|
+
return h `<div class="centered">
|
|
58
|
+
<h1>${S.signInTitle}</h1>
|
|
59
|
+
<form method="post" action="/auth/${token}"><button class="primary">${S.signInButton}</button></form>
|
|
60
|
+
</div>`;
|
|
61
|
+
}
|
|
62
|
+
function mailboxBadge(mailbox) {
|
|
63
|
+
return h `<span class="badge">${mailbox}</span>`;
|
|
64
|
+
}
|
|
65
|
+
const PREVIEWABLE = new Set(["image/png", "image/jpeg", "image/gif", "image/webp", "image/avif"]);
|
|
66
|
+
/** Image types a browser renders without running code; SVG is left out on purpose. */
|
|
67
|
+
export function isPreviewable(contentType) {
|
|
68
|
+
return PREVIEWABLE.has(contentType);
|
|
69
|
+
}
|
|
70
|
+
function formatSize(bytes) {
|
|
71
|
+
if (bytes === null)
|
|
72
|
+
return "";
|
|
73
|
+
if (bytes < 1024)
|
|
74
|
+
return `${bytes} B`;
|
|
75
|
+
if (bytes < 1048576)
|
|
76
|
+
return `${Math.round(bytes / 1024)} KB`;
|
|
77
|
+
return `${(bytes / 1048576).toFixed(1)} MB`;
|
|
78
|
+
}
|
|
79
|
+
/** Images first as thumbnails, inline ones included; the rest as file links. */
|
|
80
|
+
function attachments(m) {
|
|
81
|
+
if (!m.attachments.length)
|
|
82
|
+
return "";
|
|
83
|
+
const href = (id) => `/attachments/${encodeURIComponent(m.id)}/${encodeURIComponent(id)}`;
|
|
84
|
+
const images = m.attachments.filter(a => isPreviewable(a.content_type));
|
|
85
|
+
const files = m.attachments.filter(a => !isPreviewable(a.content_type));
|
|
86
|
+
return h `${when(images.length, () => h `<div class="images">${join(images.map(a => h `<a href="${href(a.id)}" target="_blank" rel="noopener"><img src="${href(a.id)}" alt="${a.filename}" loading="lazy"></a>`))}</div>`)}
|
|
87
|
+
${when(files.length, () => h `<div class="files">${join(files.map(a => h `<a class="file" href="${href(a.id)}" target="_blank" rel="noopener"><span>${a.filename}</span><span class="size">${formatSize(a.size)}</span></a>`))}</div>`)}`;
|
|
88
|
+
}
|
|
89
|
+
/** Mail clients write "[image: name.png]" in the text part where an image sat; the image shows below instead. */
|
|
90
|
+
function withoutImagePlaceholders(m) {
|
|
91
|
+
let text = m.text;
|
|
92
|
+
for (const a of m.attachments) {
|
|
93
|
+
if (isPreviewable(a.content_type))
|
|
94
|
+
text = text.split(`[image: ${a.filename}]`).join("");
|
|
95
|
+
}
|
|
96
|
+
return text.replace(/\n{3,}/g, "\n\n").trim();
|
|
97
|
+
}
|
|
98
|
+
export function messageCard(m) {
|
|
99
|
+
return h `<article class="card ${m.direction}">
|
|
100
|
+
<div class="meta">
|
|
101
|
+
<strong>${m.from}</strong>
|
|
102
|
+
<span>${formatDate(m.date)}</span>
|
|
103
|
+
${when(m.direction === "out" && m.status !== "draft", () => h `<span>${m.status}</span>`)}
|
|
104
|
+
</div>
|
|
105
|
+
${when(m.to.length || m.cc.length, () => h `<div class="meta">${when(m.to.length, () => h `<span>${S.to}: ${m.to.join(", ")}</span>`)}${when(m.cc.length, () => h `<span>${S.cc}: ${m.cc.join(", ")}</span>`)}</div>`)}
|
|
106
|
+
<pre class="body">${withoutImagePlaceholders(m)}</pre>
|
|
107
|
+
${attachments(m)}
|
|
108
|
+
</article>`;
|
|
109
|
+
}
|
|
110
|
+
/** Read-only context agents attached to the thread and its participants. */
|
|
111
|
+
function contextBlock(ctx) {
|
|
112
|
+
if (!ctx)
|
|
113
|
+
return "";
|
|
114
|
+
const rows = [
|
|
115
|
+
...ctx.contacts.map(c => ({ who: c.address, meta: c.meta, note: c.note })),
|
|
116
|
+
...(ctx.context ? [{ who: S.thisThread, meta: ctx.context.meta, note: ctx.context.note }] : []),
|
|
117
|
+
].filter(r => r.note || Object.keys(r.meta).length);
|
|
118
|
+
if (!rows.length)
|
|
119
|
+
return "";
|
|
120
|
+
return h `<details class="context"><summary>${S.context}</summary>${join(rows.map(r => h `<section>
|
|
121
|
+
<div class="who">${r.who}</div>
|
|
122
|
+
${when(Object.keys(r.meta).length, () => h `<dl>${join(Object.entries(r.meta).map(([k, v]) => h `<dt>${k}</dt><dd>${String(v)}</dd>`))}</dl>`)}
|
|
123
|
+
${when(r.note, () => h `<p>${r.note}</p>`)}
|
|
124
|
+
</section>`))}</details>`;
|
|
125
|
+
}
|
|
126
|
+
/** A send or discard in its undo window; reloads itself when the window closes. */
|
|
127
|
+
function pendingCard(d) {
|
|
128
|
+
const left = Math.max(0, Date.parse(d.pending.at) - Date.now());
|
|
129
|
+
return h `<article class="card pending" id="draft-${d.id}" hx-get="/drafts/${d.id}/card" hx-trigger="load delay:${left + 400}ms" hx-swap="outerHTML">
|
|
130
|
+
<div class="pending-row">
|
|
131
|
+
<span>${d.pending.action === "send" ? h `${S.sending} <strong>${d.to.join(", ")}</strong>` : S.discarding}</span>
|
|
132
|
+
<button hx-post="/drafts/${d.id}/undo" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.undo}</button>
|
|
133
|
+
</div>
|
|
134
|
+
<i class="countdown" style="animation-duration: ${left}ms"></i>
|
|
135
|
+
</article>`;
|
|
136
|
+
}
|
|
137
|
+
export function draftCard(d, history, ctx) {
|
|
138
|
+
if (d.pending)
|
|
139
|
+
return pendingCard(d);
|
|
140
|
+
return h `<article class="card" id="draft-${d.id}">
|
|
141
|
+
<div class="meta">
|
|
142
|
+
${mailboxBadge(d.mailbox)}
|
|
143
|
+
<span class="badge draft">${S.draft}</span>
|
|
144
|
+
${when(d.edited_by_human, () => h `<span>${S.editedByHuman}</span>`)}
|
|
145
|
+
<span>${formatDate(d.created_at)}</span>
|
|
146
|
+
</div>
|
|
147
|
+
<div class="meta"><span>${S.to}: <strong>${d.to.join(", ")}</strong></span>${when(d.cc.length, () => h `<span>${S.cc}: ${d.cc.join(", ")}</span>`)}</div>
|
|
148
|
+
<div class="subject">${d.subject}</div>
|
|
149
|
+
${contextBlock(ctx)}
|
|
150
|
+
${when(d.note, () => h `<div class="note">${d.note}</div>`)}
|
|
151
|
+
<pre class="body">${d.text}</pre>
|
|
152
|
+
${attachments(d)}
|
|
153
|
+
<div class="actions">
|
|
154
|
+
<button hx-get="/drafts/${d.id}/edit" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.edit}</button>
|
|
155
|
+
<button class="primary" hx-post="/drafts/${d.id}/send" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.send}</button>
|
|
156
|
+
<button class="danger" hx-post="/drafts/${d.id}/discard" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.discard}</button>
|
|
157
|
+
</div>
|
|
158
|
+
${when(history.length, () => h `<details>
|
|
159
|
+
<summary>${S.thread} (${history.length})</summary>
|
|
160
|
+
${join(history.map(messageCard))}
|
|
161
|
+
</details>`)}
|
|
162
|
+
</article>`;
|
|
163
|
+
}
|
|
164
|
+
export function draftEditor(d, form, conflict) {
|
|
165
|
+
const version = conflict ? conflict.version : d.version;
|
|
166
|
+
return h `<article class="card ${conflict ? "conflict" : ""}" id="draft-${d.id}" data-drop>
|
|
167
|
+
<div class="drop-hint">${S.dropFiles}</div>
|
|
168
|
+
<div class="meta">${mailboxBadge(d.mailbox)}<span class="badge draft">${S.draft}</span></div>
|
|
169
|
+
${when(d.note, () => h `<div class="note">${d.note}</div>`)}
|
|
170
|
+
${when(conflict, () => h `<p class="warn">${S.conflictTitle}</p><div class="subject">${S.yourVersion}</div>`)}
|
|
171
|
+
<form hx-post="/drafts/${d.id}/save" hx-target="#draft-${d.id}" hx-swap="outerHTML">
|
|
172
|
+
<input type="hidden" name="version" value="${version}">
|
|
173
|
+
<div class="field">
|
|
174
|
+
<label for="to-${d.id}">${S.to}</label>
|
|
175
|
+
<input id="to-${d.id}" name="to" value="${form.to}" autocomplete="off" required>
|
|
176
|
+
${when(!form.cc, () => h `<button type="button" class="link" onclick="this.remove();var r=document.getElementById('cc-row-${d.id}');r.hidden=false;r.querySelector('input').focus()">${S.cc}</button>`)}
|
|
177
|
+
</div>
|
|
178
|
+
<div class="field" id="cc-row-${d.id}" ${raw(form.cc ? "" : "hidden")}>
|
|
179
|
+
<label for="cc-${d.id}">${S.cc}</label>
|
|
180
|
+
<input id="cc-${d.id}" name="cc" value="${form.cc}" autocomplete="off">
|
|
181
|
+
</div>
|
|
182
|
+
<div class="field">
|
|
183
|
+
<label for="subject-${d.id}">${S.subject}</label>
|
|
184
|
+
<input id="subject-${d.id}" name="subject" value="${form.subject}" required>
|
|
185
|
+
</div>
|
|
186
|
+
<textarea id="text-${d.id}" name="text" aria-label="${S.body}" required>${form.text}</textarea>
|
|
187
|
+
${draftFiles(d, null)}
|
|
188
|
+
<div class="actions">
|
|
189
|
+
<button type="submit">${S.save}</button>
|
|
190
|
+
<button type="submit" name="send" value="1" class="primary">${S.saveAndSend}</button>
|
|
191
|
+
<button type="button" class="link" hx-get="/drafts/${d.id}/card" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.cancel}</button>
|
|
192
|
+
</div>
|
|
193
|
+
</form>
|
|
194
|
+
${when(conflict, () => h `<details open>
|
|
195
|
+
<summary>${S.currentVersion}</summary>
|
|
196
|
+
<div class="card">
|
|
197
|
+
<div class="meta"><span>${S.to}: ${conflict.to.join(", ")}</span>${when(conflict.cc.length, () => h `<span>${S.cc}: ${conflict.cc.join(", ")}</span>`)}</div>
|
|
198
|
+
<div class="subject">${conflict.subject}</div>
|
|
199
|
+
<pre class="body">${conflict.text}</pre>
|
|
200
|
+
</div>
|
|
201
|
+
</details>`)}
|
|
202
|
+
</article>`;
|
|
203
|
+
}
|
|
204
|
+
/** The editor's attachment list with remove buttons, and the picker that drag and drop also feeds. */
|
|
205
|
+
export function draftFiles(d, error) {
|
|
206
|
+
return h `<div class="draft-files" id="files-${d.id}">
|
|
207
|
+
${join(d.attachments.map(a => h `<span class="file"><span>${a.filename}</span><span class="size">${formatSize(a.size)}</span><button type="button" class="link" aria-label="${S.remove} ${a.filename}" hx-post="/drafts/${d.id}/attachments/${a.id}/remove" hx-target="#files-${d.id}" hx-swap="outerHTML">×</button></span>`))}
|
|
208
|
+
<label class="file attach">${S.attach}<input type="file" name="files" multiple hidden hx-post="/drafts/${d.id}/attachments" hx-encoding="multipart/form-data" hx-trigger="change" hx-target="#files-${d.id}" hx-swap="outerHTML" hx-include="this"></label>
|
|
209
|
+
${when(error, () => h `<p class="warn">${error}</p>`)}
|
|
210
|
+
</div>`;
|
|
211
|
+
}
|
|
212
|
+
export function draftDone(id, text) {
|
|
213
|
+
return h `<article class="card notice" id="draft-${id}">${text}</article>`;
|
|
214
|
+
}
|
|
215
|
+
export function draftsPage(drafts) {
|
|
216
|
+
return h `<h1>${S.navDrafts}</h1>
|
|
217
|
+
${drafts.length ? join(drafts.map(d => draftCard(d.draft, d.history, d.ctx))) : h `<p class="empty">${S.draftsEmpty}</p>`}`;
|
|
218
|
+
}
|
|
219
|
+
export function inboxPage(threads, mailboxes, filter, own) {
|
|
220
|
+
const tab = (status, label) => {
|
|
221
|
+
const query = new URLSearchParams({ status, ...(filter.mailbox ? { mailbox: filter.mailbox } : {}) });
|
|
222
|
+
return h `<a href="/inbox?${query.toString()}" ${raw(filter.status === status ? 'aria-current="page"' : "")}>${label}</a>`;
|
|
223
|
+
};
|
|
224
|
+
return h `<h1>${S.navInbox}</h1>
|
|
225
|
+
<form class="filters" method="get" action="/inbox">
|
|
226
|
+
<input type="hidden" name="status" value="${filter.status}">
|
|
227
|
+
<span class="select"><select name="mailbox" aria-label="${S.filter}" onchange="this.form.submit()">
|
|
228
|
+
<option value="">${S.allMailboxes}</option>
|
|
229
|
+
${join(mailboxes.map(m => h `<option value="${m}" ${raw(m === filter.mailbox ? "selected" : "")}>${m}</option>`))}
|
|
230
|
+
</select></span>
|
|
231
|
+
<nav class="tabs">${tab("unanswered", S.filterUnanswered)}${tab("all", S.filterAll)}${tab("archived", S.filterArchived)}</nav>
|
|
232
|
+
</form>
|
|
233
|
+
${threads.length ? join(threads.map(t => threadRow(t, own))) : h `<p class="empty">${S.inboxEmpty}</p>`}`;
|
|
234
|
+
}
|
|
235
|
+
function threadRow(t, own) {
|
|
236
|
+
return h `<a class="card thread-row" href="/threads/${t.id}">
|
|
237
|
+
<div class="meta">
|
|
238
|
+
${mailboxBadge(t.mailbox)}
|
|
239
|
+
${when(t.unread, () => h `<span class="dot" title="${S.unread}"></span>`)}
|
|
240
|
+
${when(t.has_draft, () => h `<span class="badge draft">${S.hasDraft}</span>`)}
|
|
241
|
+
<span>${formatDate(t.last_at)}</span>
|
|
242
|
+
</div>
|
|
243
|
+
<div class="subject">${t.subject || "—"}</div>
|
|
244
|
+
<div class="meta"><span>${t.participants.filter(p => !own.has(p)).join(", ")}</span></div>
|
|
245
|
+
</a>`;
|
|
246
|
+
}
|
|
247
|
+
export function threadPage(thread, items, ctx) {
|
|
248
|
+
return h `<h1>${thread.subject || "—"}</h1>
|
|
249
|
+
<div class="meta thread-head">${mailboxBadge(thread.mailbox)}${archiveButton(thread)}</div>
|
|
250
|
+
${contextBlock(ctx)}
|
|
251
|
+
<section class="messages">${join(items)}</section>`;
|
|
252
|
+
}
|
|
253
|
+
export function archiveButton(thread) {
|
|
254
|
+
return h `<form id="archive" hx-post="/threads/${thread.id}/archive" hx-swap="outerHTML">
|
|
255
|
+
<input type="hidden" name="archived" value="${thread.archived ? "0" : "1"}">
|
|
256
|
+
<button class="link">${thread.archived ? S.unarchive : S.archive}</button>
|
|
257
|
+
</form>`;
|
|
258
|
+
}
|
|
259
|
+
export function devicesPage(sessions, currentId) {
|
|
260
|
+
return h `<h1>${S.navDevices}</h1>
|
|
261
|
+
${sessions.length ? join(sessions.map(s => h `<article class="card" id="session-${s.id}">
|
|
262
|
+
<div class="meta">
|
|
263
|
+
<strong>${s.label ?? s.user_agent ?? S.unknownDevice}</strong>
|
|
264
|
+
${when(s.id === currentId, () => h `<span class="badge">${S.thisDevice}</span>`)}
|
|
265
|
+
${when(s.scope, () => join(s.scope.map(mailboxBadge)))}
|
|
266
|
+
</div>
|
|
267
|
+
${when(s.label && s.user_agent, () => h `<div class="meta"><span>${s.user_agent}</span></div>`)}
|
|
268
|
+
<div class="meta">
|
|
269
|
+
<span>${S.signedIn}: ${formatDate(s.created_at)}</span>
|
|
270
|
+
<span>${S.lastSeen}: ${formatDate(s.last_seen)}</span>
|
|
271
|
+
<span>${S.createdBy}: ${s.created_by}</span>
|
|
272
|
+
</div>
|
|
273
|
+
${when(s.id !== currentId, () => h `<div class="actions"><button class="danger" hx-post="/devices/${s.id}/revoke" hx-target="#session-${s.id}" hx-swap="delete">${S.revoke}</button></div>`)}
|
|
274
|
+
</article>`)) : h `<p class="empty">${S.devicesEmpty}</p>`}`;
|
|
275
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,83 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inboxer",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "A self-hosted mail layer for agents: persists every inbound and outbound email, exposes an MCP server, and ships a minimal UI to review drafts.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"src",
|
|
17
|
+
"skills/inboxer/SKILL.md"
|
|
18
|
+
],
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=22.16.0"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc -p tsconfig.json && node -e \"require('node:fs').cpSync('src/ui/static','dist/ui/static',{recursive:true})\"",
|
|
24
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
25
|
+
"test": "node --test 'test/**/*.test.ts'",
|
|
26
|
+
"test:bun": "bun test test",
|
|
27
|
+
"prepack": "npm run build"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"email",
|
|
31
|
+
"mail",
|
|
32
|
+
"mailbox",
|
|
33
|
+
"inbox",
|
|
34
|
+
"inbound-email",
|
|
35
|
+
"drafts",
|
|
36
|
+
"threading",
|
|
37
|
+
"support",
|
|
38
|
+
"helpdesk",
|
|
39
|
+
"customer-support",
|
|
40
|
+
"mcp",
|
|
41
|
+
"mcp-server",
|
|
42
|
+
"model-context-protocol",
|
|
43
|
+
"agent",
|
|
44
|
+
"ai",
|
|
45
|
+
"llm",
|
|
46
|
+
"claude",
|
|
47
|
+
"skill",
|
|
48
|
+
"resend",
|
|
49
|
+
"webhook",
|
|
50
|
+
"self-hosted",
|
|
51
|
+
"htmx",
|
|
52
|
+
"hono",
|
|
53
|
+
"sqlite",
|
|
54
|
+
"deepbase",
|
|
55
|
+
"roster-server",
|
|
56
|
+
"bun",
|
|
57
|
+
"nodejs",
|
|
58
|
+
"clasen"
|
|
59
|
+
],
|
|
60
|
+
"author": "Martin Clasen",
|
|
61
|
+
"license": "MIT",
|
|
62
|
+
"repository": {
|
|
63
|
+
"type": "git",
|
|
64
|
+
"url": "git+https://github.com/clasen/Inboxer.git"
|
|
65
|
+
},
|
|
66
|
+
"bugs": {
|
|
67
|
+
"url": "https://github.com/clasen/Inboxer/issues"
|
|
68
|
+
},
|
|
69
|
+
"homepage": "https://github.com/clasen/Inboxer#readme",
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"@hono/node-server": "^2.1.8",
|
|
72
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
73
|
+
"deepbase": "^4.0.0",
|
|
74
|
+
"deepbase-sqlite": "^4.0.0",
|
|
75
|
+
"hono": "^4.13.18",
|
|
76
|
+
"svix": "^2.10.0",
|
|
77
|
+
"zod": "^4.6.7"
|
|
78
|
+
},
|
|
79
|
+
"devDependencies": {
|
|
80
|
+
"@types/node": "^22.20.5",
|
|
81
|
+
"typescript": "^7.0.2"
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: inboxer
|
|
3
|
+
description: Sets up, deploys and uses Inboxer, a self-hosted mail layer with an MCP server and a draft review UI. Use when adding Inboxer to a Node.js or Bun app or a roster-server site, configuring mailboxes, Resend and the domain, connecting an MCP client, or reading, triaging, drafting and sending email through Inboxer's MCP tools. Do not use for modifying Inboxer internals.
|
|
4
|
+
metadata:
|
|
5
|
+
category: workflow-automation
|
|
6
|
+
tags: [email, mcp, agent, resend, drafts, support, inbox]
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Inboxer
|
|
10
|
+
|
|
11
|
+
Inboxer stores every inbound and outbound email in one SQLite file, exposes MCP tools to read, draft and send, and serves a phone-friendly UI where a human reviews drafts. It has no business rules: the consumer's prompt decides what to answer and whether to send directly.
|
|
12
|
+
|
|
13
|
+
## Set up
|
|
14
|
+
|
|
15
|
+
Install with `npm install inboxer`; requires Node.js 22.16+ or Bun. `createInboxer` takes one plain object; load it the way the project already loads configuration (JSON file, environment variables, a loader such as Configre).
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
const config = {
|
|
19
|
+
publicUrl: "https://inboxer.example.com",
|
|
20
|
+
dataDir: "/var/lib/inboxer", // absolute
|
|
21
|
+
syncIntervalMin: 10,
|
|
22
|
+
threadWindowDays: 30,
|
|
23
|
+
mailboxes: {
|
|
24
|
+
support: { address: "support@example.com", name: "Example Support",
|
|
25
|
+
signatureText: "-- Example Support", signatureHtml: "<p>-- Example Support</p>",
|
|
26
|
+
tokens: { "support-schedule": "<openssl rand -hex 32>" } } // support only
|
|
27
|
+
},
|
|
28
|
+
provider: { type: "resend", apiKey: "re_...", webhookSecret: "whsec_..." },
|
|
29
|
+
mcp: { tokens: { "admin": "<openssl rand -hex 32>" }, maxAttachmentMb: 10 }, // every mailbox
|
|
30
|
+
ui: { cookieSecret: "<openssl rand -hex 32>", loginLinkTtlMin: 10, undoSec: 10, maxUploadMb: 20 }
|
|
31
|
+
};
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
- Every key above is required except the mailbox signatures and mailbox tokens; `createInboxer` throws on a missing or invalid one. There are no defaults.
|
|
35
|
+
- `mailboxes` is an object keyed by id. `catchall` is reserved: unknown recipients land there, and it cannot send.
|
|
36
|
+
- `provider.apiKey`, `provider.webhookSecret`, every token and `ui.cookieSecret` are secrets: keep them out of Git and out of logs.
|
|
37
|
+
|
|
38
|
+
## Serve
|
|
39
|
+
|
|
40
|
+
`createInboxer(cfg, { provider? })` is synchronous, does not listen, and returns `{ fetch, handler, ready, close }`. Requests wait for `ready`.
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { createInboxer } from "inboxer";
|
|
44
|
+
|
|
45
|
+
const inboxer = createInboxer(config);
|
|
46
|
+
Bun.serve({ port: 4000, fetch: inboxer.fetch }); // or createServer(inboxer.handler) on Node
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
For roster-server, return `inboxer.handler` from the `SiteFactory` and register `server.onClose(() => inboxer.close())`.
|
|
50
|
+
|
|
51
|
+
- Run exactly one process per `dataDir`. Login links and draft versions rely on an in-process write queue.
|
|
52
|
+
- Routes: `/` UI, `/static/*`, `/mcp`, `/webhooks/<provider>`, `/auth/<token>`.
|
|
53
|
+
|
|
54
|
+
## Resend and the domain
|
|
55
|
+
|
|
56
|
+
Keep two domains apart: the app runs on its own host, e.g. `inboxer.example.com` (`A`/`AAAA` + HTTPS, the `publicUrl`), while the addresses live on the mail domain, e.g. `support@example.com` (`MX` to Resend + SPF, DKIM, DMARC).
|
|
57
|
+
|
|
58
|
+
1. Deploy Inboxer over HTTPS at `publicUrl` first.
|
|
59
|
+
2. In Resend, add the domain, create its SPF, DKIM and MX records, and enable receiving. The MX switch moves the whole domain's mail to Resend; use a subdomain to keep the root elsewhere.
|
|
60
|
+
3. Add a DMARC TXT record at `_dmarc.<domain>`.
|
|
61
|
+
4. Create a full-access API key (Inboxer reads emails, not only sends) → `provider.apiKey`.
|
|
62
|
+
5. Create a webhook at `<publicUrl>/webhooks/resend` for `email.received`, `email.sent`, `email.delivered`, `email.bounced`, `email.failed`, `email.suppressed` → its signing secret is `provider.webhookSecret`.
|
|
63
|
+
6. Restart and send a test email from outside. A webhook `401` means a wrong signing secret.
|
|
64
|
+
|
|
65
|
+
Missed webhooks are recovered by the periodic sync.
|
|
66
|
+
|
|
67
|
+
## Another provider
|
|
68
|
+
|
|
69
|
+
Implement `MailProvider` (exported types) and pass it as `createInboxer(cfg, { provider })`; `cfg.provider.type` is then not required. `send()` must not deliver twice for the same `idempotencyKey` (Inboxer passes the draft id). `parseWebhook()` throws `WebhookSignatureError` on a bad signature.
|
|
70
|
+
|
|
71
|
+
## Connect an MCP client
|
|
72
|
+
|
|
73
|
+
One token per client, so the audit log names the actor and revoking one leaves the rest. Revoke by deleting the entry and restarting.
|
|
74
|
+
|
|
75
|
+
Tokens in `mcp.tokens` reach every mailbox. A token under `mailboxes.<id>.tokens` reaches only that mailbox: everything else reads as not found, it reaches only contacts in its own threads, and its login links sign browsers into the same mailboxes. Repeat the same name and token under several mailboxes to reach all of them.
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
claude mcp add --transport http inboxer https://inboxer.example.com/mcp --header "Authorization: Bearer <token>"
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
JSON clients: `{ "type": "http", "url": "<publicUrl>/mcp", "headers": { "Authorization": "Bearer <token>" } }`. OAuth-only connectors are not supported.
|
|
82
|
+
|
|
83
|
+
## Work with mail through MCP
|
|
84
|
+
|
|
85
|
+
Typical support loop:
|
|
86
|
+
|
|
87
|
+
1. `list_threads({ mailbox: "support" })`: status defaults to `unanswered` (last message inbound and no pending draft).
|
|
88
|
+
2. `get_thread({ thread_id })`: messages as plain text, oldest first, with pending drafts, plus `context` (the thread's) and `contacts` (its external participants').
|
|
89
|
+
3. Decide with the consumer's own rules and data.
|
|
90
|
+
4. `create_draft({ reply_to_id, text, note })` for human review, or `reply({ message_id, text })` only when the rules allow sending without review.
|
|
91
|
+
|
|
92
|
+
Rules for agents:
|
|
93
|
+
|
|
94
|
+
- Pass a **message id** as `reply_to_id` or `message_id`. Recipients, `Re:` subject, `In-Reply-To` and `References` are derived; do not set them by hand. `reply_all` adds the original To/Cc minus the mailbox itself.
|
|
95
|
+
- Put what the reviewer must do or check in `note`, not in the body. The note is never sent.
|
|
96
|
+
- A new conversation needs `mailbox`, `to` and `subject`.
|
|
97
|
+
- `update_draft` needs the draft's current `version`. On a conflict the error includes `current`; re-read it before retrying.
|
|
98
|
+
- A draft whose `pending` is set is in the reviewer's undo window and is about to be sent or discarded; `update_draft` fails until it ends.
|
|
99
|
+
- Never `force` an update of a draft with `edited_by_human: true` unless the user explicitly asks; the human's edit wins.
|
|
100
|
+
- `send_draft` sends the last saved version. A failed send leaves the draft pending and retrying is safe.
|
|
101
|
+
- `label` and `mark` accept message ids or thread ids; a thread id applies to every message in it. Archived threads come back to the inbox when a new message arrives.
|
|
102
|
+
- `search` matches every term, ignoring case and accents, across subject, body, from and to; narrow with `mailbox`, `from`, `since`, `until`, `meta`. Pass `query`, `meta`, or both.
|
|
103
|
+
- Messages list their `attachments` (`inline: true` is an image embedded in the body). `get_attachment` returns the content: images as images you can look at, text as text, other files (PDF, documents) as an embedded resource. Files over `mcp.maxAttachmentMb` return an error. Agents cannot attach files to drafts; the reviewer can, in the UI, and they are listed in the draft's `attachments`.
|
|
104
|
+
- Threads, messages and drafts in results carry `url`, which opens them in the review UI (scrolled to the draft). When telling the user what you drafted or sent, include that `url`.
|
|
105
|
+
- Times are ISO 8601. `catchall` messages can be read and labeled but not answered from Inboxer.
|
|
106
|
+
|
|
107
|
+
Context:
|
|
108
|
+
|
|
109
|
+
- Read `contacts` and `context` from `get_thread` before looking anything up elsewhere; earlier runs may have stored it.
|
|
110
|
+
- After identifying a sender in another system, store the link with `set_contact({ address, meta: { <system>_id: ... } })`. Use the key names the consumer's prompt defines and keep them stable across runs.
|
|
111
|
+
- Use `set_thread_meta` for facts about one conversation (ticket, promise, pending step) and `note` for short human-readable context.
|
|
112
|
+
- Updates merge: send only the keys you change; `null` removes a key or clears the note. Never resend the whole object to "replace" it.
|
|
113
|
+
- To find every conversation with a customer, use `list_threads({ status: "all", meta: { ... } })`; without `status: "all"` only unanswered threads come back.
|
|
114
|
+
- The reviewer sees contact and thread context in the UI. Do not store secrets there.
|
|
115
|
+
|
|
116
|
+
## Give a human access to the UI
|
|
117
|
+
|
|
118
|
+
Call `create_login_link({ label: "Ana's phone" })` and hand the returned URL to the person; add `thread_id` to land on that thread after signing in. It works once, expires after `ui.loginLinkTtlMin` minutes if unused, and signs in one browser for good. `list_sessions` and `revoke_session({ id })` manage devices. Without MCP, call `createLoginLink(cfg, { label, threadId? })` (exported by `inboxer`) from a script on the server with the app's config; it returns `{ url, expires_at }`.
|
package/src/app.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import { matchBearer, type Access } from "./auth.ts";
|
|
3
|
+
import { mcpTokens } from "./config.ts";
|
|
4
|
+
import { InvalidRequestError, type Mail } from "./core/mail.ts";
|
|
5
|
+
import { handleMcp } from "./mcp.ts";
|
|
6
|
+
import { WebhookSignatureError } from "./provider/types.ts";
|
|
7
|
+
import { NotFoundError } from "./store.ts";
|
|
8
|
+
import type { InboxerConfig } from "./types.ts";
|
|
9
|
+
import { ASSETS } from "./ui/assets.ts";
|
|
10
|
+
import { registerUi, type UiEnv } from "./ui/routes.ts";
|
|
11
|
+
|
|
12
|
+
export function buildApp(mail: Mail, access: Access, cfg: InboxerConfig, ready: Promise<void>): Hono<UiEnv> {
|
|
13
|
+
const app = new Hono<UiEnv>();
|
|
14
|
+
const tokens = mcpTokens(cfg);
|
|
15
|
+
|
|
16
|
+
app.use("*", async (_c, next) => {
|
|
17
|
+
await ready;
|
|
18
|
+
await next();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
app.onError((err, c) => {
|
|
22
|
+
if (err instanceof NotFoundError) return c.text(err.message, 404);
|
|
23
|
+
if (err instanceof InvalidRequestError) return c.text(err.message, 400);
|
|
24
|
+
console.error("inboxer:", err);
|
|
25
|
+
return c.text("Internal error", 500);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
app.get("/static/:file", c => {
|
|
29
|
+
const file = ASSETS[c.req.param("file")];
|
|
30
|
+
if (!file) return c.notFound();
|
|
31
|
+
return c.body(file.body, 200, { "Content-Type": file.type, "Cache-Control": "public, max-age=31536000, immutable" });
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// A failure answers 500 so the provider retries; ingest is idempotent.
|
|
35
|
+
app.post("/webhooks/:provider", async c => {
|
|
36
|
+
if (c.req.param("provider") !== mail.provider.name) return c.notFound();
|
|
37
|
+
let events;
|
|
38
|
+
try {
|
|
39
|
+
events = mail.provider.parseWebhook({ headers: c.req.raw.headers, body: await c.req.text() });
|
|
40
|
+
} catch (err) {
|
|
41
|
+
if (err instanceof WebhookSignatureError) return c.text("Invalid signature", 401);
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
44
|
+
for (const event of events) await mail.applyEvent(event);
|
|
45
|
+
return c.json({ ok: true });
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
app.all("/mcp", async c => {
|
|
49
|
+
const token = matchBearer(c.req.header("authorization"), tokens);
|
|
50
|
+
if (!token) return c.text("Unauthorized", 401, { "WWW-Authenticate": "Bearer" });
|
|
51
|
+
return handleMcp(c.req.raw, mail, access, { kind: "agent", name: token.name, scope: token.scope });
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
registerUi(app, mail, access, cfg);
|
|
55
|
+
return app;
|
|
56
|
+
}
|