@zabaca/zbc 0.6.1 → 0.7.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/package.json +1 -1
- package/src/commands/add.ts +6 -4
- package/templates/CLAUDE.md +1 -1
- package/templates/apps/inbox/package.json +6 -2
- package/templates/apps/inbox/public/index.html +275 -85
- package/templates/apps/inbox/registry.json +3 -3
- package/templates/apps/inbox/worker/inbox-do.ts +415 -22
- package/templates/apps/inbox/worker/index.ts +241 -69
- package/templates/apps/inbox/worker/mcp.ts +279 -0
- package/templates/apps/inbox/worker/send-op.ts +174 -0
- package/templates/apps/inbox/worker/shared.ts +117 -0
- package/templates/apps/inbox/wrangler.jsonc +17 -4
- package/templates/infra/modules/cloudflare/index.ts +214 -5
- package/templates/infra/modules/r2/index.ts +137 -0
- package/templates/infra/modules/r2/registry.json +8 -0
package/package.json
CHANGED
package/src/commands/add.ts
CHANGED
|
@@ -42,7 +42,7 @@ async function resolveBundledDir(name: string): Promise<string> {
|
|
|
42
42
|
if (await Bun.file(registry).exists()) return dir
|
|
43
43
|
}
|
|
44
44
|
throw new Error(
|
|
45
|
-
`"${name}" not found in built-in registry. Available: cloudflare, cloudflare-email, turso, inbox.`,
|
|
45
|
+
`"${name}" not found in built-in registry. Available: cloudflare, cloudflare-email, r2, turso, inbox.`,
|
|
46
46
|
)
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -159,8 +159,10 @@ async function installApp(
|
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
// 2. Copy the package
|
|
163
|
-
//
|
|
162
|
+
// 2. Copy the package verbatim — app templates are placeholder-free (all
|
|
163
|
+
// per-project identity lives in the instance file: workerName,
|
|
164
|
+
// r2Bindings, workerVars). registry.json stays in the CLI — it's not app
|
|
165
|
+
// code. `vars` kept for future templates; a no-op with no {{}} tokens.
|
|
164
166
|
const { project } = await loadConfig(projectRoot)
|
|
165
167
|
await copyTemplateDir(sourceDir, destDir, {
|
|
166
168
|
vars: { PROJECT_NAME: project },
|
|
@@ -181,7 +183,7 @@ export const addCommand = defineCommand({
|
|
|
181
183
|
args: {
|
|
182
184
|
module: {
|
|
183
185
|
type: 'positional',
|
|
184
|
-
description: 'Module or app name (e.g. turso, cloudflare, cloudflare-email, inbox)',
|
|
186
|
+
description: 'Module or app name (e.g. turso, cloudflare, cloudflare-email, r2, inbox)',
|
|
185
187
|
required: true,
|
|
186
188
|
},
|
|
187
189
|
},
|
package/templates/CLAUDE.md
CHANGED
|
@@ -13,7 +13,7 @@ This project uses [zbc](https://github.com/Zabaca/zbc) for infrastructure scaffo
|
|
|
13
13
|
## Common commands
|
|
14
14
|
|
|
15
15
|
- `bun install` — install dependencies
|
|
16
|
-
- `bunx @zabaca/zbc add <module>` — vendor an infra module (`turso`, `cloudflare`, `cloudflare-email`) or scaffold an app template (`inbox` — an agent-accessible email inbox; auto-vendors its module dependencies)
|
|
16
|
+
- `bunx @zabaca/zbc add <module>` — vendor an infra module (`turso`, `cloudflare`, `cloudflare-email`, `r2`) or scaffold an app template (`inbox` — an agent-accessible email inbox; auto-vendors its module dependencies)
|
|
17
17
|
- `bunx @zabaca/zbc apply <env>` — apply infrastructure for an environment
|
|
18
18
|
- `bunx @zabaca/zbc destroy <env>` — tear down an ephemeral environment
|
|
19
19
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "@
|
|
2
|
+
"name": "@zbc/inbox",
|
|
3
3
|
"version": "0.0.1",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
@@ -9,7 +9,11 @@
|
|
|
9
9
|
"typecheck": "tsc --noEmit"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"
|
|
12
|
+
"@hono/mcp": "^0.3.1",
|
|
13
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
14
|
+
"hono": "^4.12.30",
|
|
15
|
+
"postal-mime": "^2.4.4",
|
|
16
|
+
"zod": "^4.4.3"
|
|
13
17
|
},
|
|
14
18
|
"devDependencies": {
|
|
15
19
|
"@cloudflare/workers-types": "^4.20250101.0",
|
|
@@ -3,59 +3,180 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
-
<title>
|
|
6
|
+
<title>Inbox</title>
|
|
7
7
|
<style>
|
|
8
|
-
|
|
8
|
+
/* Prose design system tokens (mirrored from packages/design-system/src/tokens.css;
|
|
9
|
+
the inbox UI is a self-contained static page, so no Tailwind pipeline). */
|
|
10
|
+
:root {
|
|
11
|
+
color-scheme: light dark;
|
|
12
|
+
--paper-0: #FBFAF7; --paper-1: #F4F2EC; --paper-2: #EAE6DC; --paper-3: #DCD6C7;
|
|
13
|
+
--ink-0: #14140F; --ink-1: #2D2C25; --ink-2: #5A584C; --ink-3: #8A8676; --ink-4: #B8B3A1;
|
|
14
|
+
--accent: #B8410E; --accent-soft: #E8D5C4; --accent-ink: #6B2308;
|
|
15
|
+
--positive: #2F6B3C; --critical: #A8321A;
|
|
16
|
+
--font-display: 'Iowan Old Style', 'Source Serif Pro', Georgia, 'Times New Roman', serif;
|
|
17
|
+
--font-ui: 'Inter Tight', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
|
|
18
|
+
--font-mono: 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;
|
|
19
|
+
--dur-fast: 140ms; --ease: cubic-bezier(0.2, 0.6, 0.2, 1);
|
|
20
|
+
}
|
|
21
|
+
@media (prefers-color-scheme: dark) {
|
|
22
|
+
:root {
|
|
23
|
+
--paper-0: #14130E; --paper-1: #1C1B16; --paper-2: #25241D; --paper-3: #34322A;
|
|
24
|
+
--ink-0: #F2EFE6; --ink-1: #DDD8C9; --ink-2: #A8A290; --ink-3: #75705F; --ink-4: #4A463C;
|
|
25
|
+
--accent: #E26B3A; --accent-soft: #3A2418; --accent-ink: #F0A57E;
|
|
26
|
+
--positive: #6FAE7C; --critical: #E2674F;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
9
30
|
* { box-sizing: border-box; }
|
|
10
|
-
body {
|
|
11
|
-
|
|
12
|
-
|
|
31
|
+
html, body { height: 100%; }
|
|
32
|
+
body {
|
|
33
|
+
margin: 0;
|
|
34
|
+
font: 400 0.9375rem/1.5 var(--font-ui);
|
|
35
|
+
background: var(--paper-0);
|
|
36
|
+
color: var(--ink-1);
|
|
37
|
+
}
|
|
38
|
+
button {
|
|
39
|
+
font: 500 0.8125rem/1 var(--font-ui);
|
|
40
|
+
letter-spacing: 0.04em;
|
|
41
|
+
padding: 0.5rem 0.75rem;
|
|
42
|
+
border: 1px solid var(--ink-4);
|
|
43
|
+
border-radius: 2px;
|
|
44
|
+
background: transparent;
|
|
45
|
+
color: var(--ink-1);
|
|
46
|
+
cursor: pointer;
|
|
47
|
+
transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
|
|
48
|
+
}
|
|
49
|
+
button:hover { background: var(--paper-2); }
|
|
50
|
+
button.primary { background: var(--accent); border-color: var(--accent); color: #FBFAF7; }
|
|
51
|
+
button.primary:hover { filter: brightness(1.08); background: var(--accent); }
|
|
52
|
+
button.danger { color: var(--critical); border-color: var(--critical); }
|
|
53
|
+
|
|
54
|
+
header {
|
|
55
|
+
display: flex; align-items: baseline; gap: 0.75rem;
|
|
56
|
+
padding: 0.75rem 1.5rem;
|
|
57
|
+
border-bottom: 2px solid var(--ink-0);
|
|
58
|
+
background: var(--paper-0);
|
|
59
|
+
}
|
|
60
|
+
header h1 { font: 600 1.375rem/1.1 var(--font-display); letter-spacing: -0.015em; margin: 0; color: var(--ink-0); }
|
|
61
|
+
header .domain { font: 400 0.8125rem/1 var(--font-mono); color: var(--ink-3); }
|
|
13
62
|
header .spacer { flex: 1; }
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
main { display: grid; grid-template-columns: minmax(
|
|
17
|
-
#list { overflow-y: auto; border-right: 1px solid var(--
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
63
|
+
header .actions { display: flex; gap: 0.5rem; align-self: center; }
|
|
64
|
+
|
|
65
|
+
main { display: grid; grid-template-columns: minmax(280px, 400px) 1fr; height: calc(100dvh - 56px); }
|
|
66
|
+
#list { overflow-y: auto; border-right: 1px solid var(--paper-3); background: var(--paper-0); }
|
|
67
|
+
#reader { overflow-y: auto; background: var(--paper-1); }
|
|
68
|
+
|
|
69
|
+
.thread {
|
|
70
|
+
padding: 0.75rem 1.5rem;
|
|
71
|
+
border-bottom: 1px solid var(--paper-3);
|
|
72
|
+
cursor: pointer;
|
|
73
|
+
transition: background var(--dur-fast) var(--ease);
|
|
74
|
+
}
|
|
75
|
+
.thread:hover { background: var(--paper-1); }
|
|
76
|
+
.thread.active { background: var(--paper-2); box-shadow: inset 2px 0 0 var(--accent); }
|
|
77
|
+
.thread .top { display: flex; align-items: baseline; gap: 0.5rem; }
|
|
78
|
+
.thread .who { font-weight: 600; color: var(--ink-0); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
|
|
79
|
+
.thread .when { font-size: 0.75rem; color: var(--ink-3); white-space: nowrap; }
|
|
80
|
+
.thread .subject { display: block; color: var(--ink-1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
81
|
+
.thread .snippet {
|
|
82
|
+
color: var(--ink-3); font-size: 0.8125rem;
|
|
83
|
+
display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
|
|
84
|
+
}
|
|
85
|
+
.badge {
|
|
86
|
+
font-size: 0.6875rem; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase;
|
|
87
|
+
padding: 0.125rem 0.375rem; border-radius: 2px;
|
|
88
|
+
}
|
|
89
|
+
.badge.count { background: var(--paper-2); color: var(--ink-2); }
|
|
90
|
+
.badge.sent { background: var(--accent-soft); color: var(--accent-ink); }
|
|
91
|
+
|
|
92
|
+
/* Conversation view */
|
|
93
|
+
.convo { max-width: 46rem; margin: 0 auto; padding: 1.5rem; }
|
|
94
|
+
.convo-head { display: flex; align-items: baseline; gap: 0.75rem; margin-bottom: 1.5rem; }
|
|
95
|
+
.convo-head h2 { font: 600 1.75rem/1.1 var(--font-display); letter-spacing: -0.015em; color: var(--ink-0); margin: 0; flex: 1; }
|
|
96
|
+
#back { display: none; }
|
|
97
|
+
|
|
98
|
+
.bubble {
|
|
99
|
+
background: var(--paper-0);
|
|
100
|
+
border: 1px solid var(--paper-3);
|
|
101
|
+
border-radius: 2px;
|
|
102
|
+
margin-bottom: 1rem;
|
|
103
|
+
}
|
|
104
|
+
.bubble.outbound { border-left: 2px solid var(--accent); background: var(--paper-1); }
|
|
105
|
+
.bubble .head {
|
|
106
|
+
display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.5rem;
|
|
107
|
+
padding: 0.75rem 1rem; cursor: pointer;
|
|
108
|
+
}
|
|
109
|
+
.bubble .head .who { font-weight: 600; color: var(--ink-0); }
|
|
110
|
+
.bubble .head .arrow { color: var(--ink-3); font-size: 0.8125rem; }
|
|
111
|
+
.bubble .head .when { margin-left: auto; font-size: 0.75rem; color: var(--ink-3); white-space: nowrap; }
|
|
112
|
+
.bubble .body { padding: 0 1rem 1rem; border-top: 1px solid var(--paper-2); padding-top: 0.75rem; }
|
|
113
|
+
.bubble.collapsed .body, .bubble.collapsed .tools { display: none; }
|
|
114
|
+
.bubble.collapsed .head .preview { color: var(--ink-3); font-size: 0.8125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 24rem; }
|
|
115
|
+
.bubble pre { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; margin: 0; color: var(--ink-1); }
|
|
116
|
+
.bubble iframe { width: 100%; min-height: 20rem; border: 1px solid var(--paper-3); border-radius: 2px; background: #fff; }
|
|
117
|
+
.bubble .tools { display: flex; gap: 0.5rem; padding: 0 1rem 0.75rem; }
|
|
118
|
+
.bubble .tools button { font-size: 0.6875rem; padding: 0.25rem 0.5rem; color: var(--ink-2); }
|
|
119
|
+
|
|
120
|
+
.reply-bar { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
|
|
121
|
+
|
|
122
|
+
dialog {
|
|
123
|
+
border: 1px solid var(--paper-3); border-radius: 2px;
|
|
124
|
+
background: var(--paper-0); color: var(--ink-1);
|
|
125
|
+
padding: 1.5rem; width: min(560px, 92vw);
|
|
126
|
+
}
|
|
127
|
+
dialog::backdrop { background: rgba(20, 20, 15, 0.5); }
|
|
128
|
+
dialog h3 { font: 600 1.375rem/1.1 var(--font-display); color: var(--ink-0); margin: 0 0 1rem; }
|
|
129
|
+
form.compose { display: grid; gap: 0.5rem; }
|
|
130
|
+
form.compose input, form.compose textarea {
|
|
131
|
+
font: inherit; padding: 0.5rem 0.625rem;
|
|
132
|
+
border: 1px solid var(--ink-4); border-radius: 2px;
|
|
133
|
+
background: var(--paper-0); color: var(--ink-1); width: 100%;
|
|
134
|
+
}
|
|
135
|
+
form.compose input::placeholder, form.compose textarea::placeholder { color: var(--ink-3); }
|
|
136
|
+
form.compose input:focus, form.compose textarea:focus { outline: none; border-color: var(--accent); }
|
|
137
|
+
form.compose textarea { min-height: 10rem; resize: vertical; }
|
|
138
|
+
.row { display: flex; gap: 0.5rem; justify-content: flex-end; }
|
|
139
|
+
.empty { padding: 4rem 1.5rem; text-align: center; color: var(--ink-3); font: 400 1.125rem/1.5 var(--font-display); font-style: italic; }
|
|
140
|
+
#loadmore { display: block; margin: 0.75rem auto; }
|
|
141
|
+
|
|
142
|
+
/* Mobile: single pane, list <-> conversation */
|
|
143
|
+
@media (max-width: 45rem) {
|
|
144
|
+
main { grid-template-columns: 1fr; }
|
|
145
|
+
#list { border-right: none; }
|
|
146
|
+
main.reading #list { display: none; }
|
|
147
|
+
main:not(.reading) #reader { display: none; }
|
|
148
|
+
#back { display: inline-block; }
|
|
149
|
+
header { padding: 0.625rem 1rem; }
|
|
150
|
+
header .domain { display: none; }
|
|
151
|
+
.thread { padding: 0.75rem 1rem; }
|
|
152
|
+
.convo { padding: 1rem; }
|
|
153
|
+
.bubble .head .preview { max-width: 40vw; }
|
|
154
|
+
}
|
|
37
155
|
</style>
|
|
38
156
|
</head>
|
|
39
157
|
<body>
|
|
40
158
|
<header>
|
|
41
|
-
<h1>
|
|
42
|
-
<span
|
|
159
|
+
<h1>Inbox</h1>
|
|
160
|
+
<span class="domain"></span>
|
|
43
161
|
<span class="spacer"></span>
|
|
44
|
-
<
|
|
45
|
-
|
|
46
|
-
|
|
162
|
+
<div class="actions">
|
|
163
|
+
<button id="compose-btn" class="primary">Compose</button>
|
|
164
|
+
<button id="refresh-btn">Refresh</button>
|
|
165
|
+
<button id="token-btn">Token</button>
|
|
166
|
+
</div>
|
|
47
167
|
</header>
|
|
48
|
-
<main>
|
|
168
|
+
<main id="main">
|
|
49
169
|
<div id="list"><div class="empty">Loading…</div></div>
|
|
50
|
-
<div id="reader"><div class="empty">Select a
|
|
170
|
+
<div id="reader"><div class="empty">Select a conversation</div></div>
|
|
51
171
|
</main>
|
|
52
172
|
|
|
53
173
|
<dialog id="compose">
|
|
174
|
+
<h3 id="compose-title">New message</h3>
|
|
54
175
|
<form class="compose" id="compose-form" method="dialog">
|
|
55
176
|
<input name="to" placeholder="To" required>
|
|
56
|
-
<input name="from" placeholder="From (optional
|
|
177
|
+
<input name="from" placeholder="From (optional, defaults to DEFAULT_FROM)">
|
|
57
178
|
<input name="subject" placeholder="Subject" required>
|
|
58
|
-
<input name="inReplyTo"
|
|
179
|
+
<input name="inReplyTo" type="hidden">
|
|
59
180
|
<textarea name="text" placeholder="Message" required></textarea>
|
|
60
181
|
<div class="row">
|
|
61
182
|
<button type="button" id="compose-cancel">Cancel</button>
|
|
@@ -68,7 +189,7 @@
|
|
|
68
189
|
const $ = (s) => document.querySelector(s)
|
|
69
190
|
let token = localStorage.getItem('inbox_token') || ''
|
|
70
191
|
let cursor = null
|
|
71
|
-
let
|
|
192
|
+
let currentThread = null
|
|
72
193
|
|
|
73
194
|
function askToken(force) {
|
|
74
195
|
if (token && !force) return token
|
|
@@ -88,78 +209,118 @@ async function api(path, opts = {}) {
|
|
|
88
209
|
}
|
|
89
210
|
|
|
90
211
|
const esc = (s) => String(s ?? '').replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c]))
|
|
91
|
-
|
|
212
|
+
function fmtDate(d) {
|
|
213
|
+
const t = new Date(d)
|
|
214
|
+
if (isNaN(t)) return ''
|
|
215
|
+
const sameDay = t.toDateString() === new Date().toDateString()
|
|
216
|
+
return sameDay
|
|
217
|
+
? t.toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' })
|
|
218
|
+
: t.toLocaleDateString([], { month: 'short', day: 'numeric' }) +
|
|
219
|
+
(t.getFullYear() !== new Date().getFullYear() ? ' ' + t.getFullYear() : '')
|
|
220
|
+
}
|
|
92
221
|
|
|
93
222
|
async function loadList(append) {
|
|
94
223
|
askToken(false)
|
|
95
224
|
try {
|
|
96
225
|
const q = append && cursor ? '?cursor=' + encodeURIComponent(cursor) : ''
|
|
97
|
-
const data = await api('/api/
|
|
226
|
+
const data = await api('/api/threads' + q)
|
|
98
227
|
cursor = data.nextCursor
|
|
99
|
-
const html = data.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
<span class="
|
|
104
|
-
|
|
105
|
-
|
|
228
|
+
const html = data.threads.map((t) => {
|
|
229
|
+
const who = t.direction === 'outbound' ? t.to_addr : t.from_addr
|
|
230
|
+
const badges =
|
|
231
|
+
(t.thread_count > 1 ? `<span class="badge count">${t.thread_count}</span>` : '') +
|
|
232
|
+
(t.direction === 'outbound' ? '<span class="badge sent">sent</span>' : '')
|
|
233
|
+
return `
|
|
234
|
+
<div class="thread" data-thread="${esc(t.thread_id)}">
|
|
235
|
+
<div class="top">
|
|
236
|
+
<span class="who">${esc(who)}</span>
|
|
237
|
+
${badges}
|
|
238
|
+
<span class="when">${esc(fmtDate(t.created_at))}</span>
|
|
239
|
+
</div>
|
|
240
|
+
<span class="subject">${esc(t.subject) || '(no subject)'}</span>
|
|
241
|
+
<span class="snippet">${esc(t.snippet)}</span>
|
|
242
|
+
</div>`
|
|
243
|
+
}).join('')
|
|
106
244
|
const more = cursor ? '<button id="loadmore">Load more</button>' : ''
|
|
107
245
|
if (append) { $('#loadmore')?.remove(); $('#list').insertAdjacentHTML('beforeend', html + more) }
|
|
108
246
|
else $('#list').innerHTML = (html || '<div class="empty">No messages yet</div>') + more
|
|
247
|
+
if (currentThread) highlightActive()
|
|
109
248
|
} catch (e) {
|
|
110
249
|
$('#list').innerHTML = '<div class="empty">' + esc(e.message) + '</div>'
|
|
111
250
|
}
|
|
112
251
|
}
|
|
113
252
|
|
|
114
|
-
|
|
115
|
-
document.querySelectorAll('.
|
|
253
|
+
function highlightActive() {
|
|
254
|
+
document.querySelectorAll('.thread').forEach((el) =>
|
|
255
|
+
el.classList.toggle('active', el.dataset.thread === currentThread))
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async function openThread(threadId) {
|
|
259
|
+
currentThread = threadId
|
|
260
|
+
highlightActive()
|
|
261
|
+
$('#main').classList.add('reading')
|
|
116
262
|
$('#reader').innerHTML = '<div class="empty">Loading…</div>'
|
|
117
263
|
try {
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
264
|
+
const { messages } = await api('/api/threads/' + encodeURIComponent(threadId))
|
|
265
|
+
const last = messages[messages.length - 1]
|
|
266
|
+
const bubbles = messages.map((m, i) => {
|
|
267
|
+
const collapsed = messages.length > 1 && i < messages.length - 1
|
|
268
|
+
const out = m.direction === 'outbound'
|
|
269
|
+
return `
|
|
270
|
+
<div class="bubble ${out ? 'outbound' : ''} ${collapsed ? 'collapsed' : ''}" data-id="${esc(m.id)}">
|
|
271
|
+
<div class="head">
|
|
272
|
+
<span class="who">${esc(out ? 'You' : m.from_addr)}</span>
|
|
273
|
+
<span class="arrow">→ ${esc(m.to_addr)}</span>
|
|
274
|
+
${out ? '<span class="badge sent">sent</span>' : ''}
|
|
275
|
+
<span class="preview">${esc(m.snippet)}</span>
|
|
276
|
+
<span class="when">${esc(fmtDate(m.date || m.created_at))}</span>
|
|
277
|
+
</div>
|
|
278
|
+
<div class="body">${m.html_body
|
|
279
|
+
? `<iframe sandbox="" referrerpolicy="no-referrer"></iframe>`
|
|
280
|
+
: `<pre>${esc(m.text_body)}</pre>`}</div>
|
|
281
|
+
<div class="tools">
|
|
282
|
+
${m.r2_key ? `<button class="raw" data-id="${esc(m.id)}">Raw</button>` : ''}
|
|
283
|
+
<button class="del danger" data-id="${esc(m.id)}">Delete</button>
|
|
284
|
+
</div>
|
|
285
|
+
</div>`
|
|
286
|
+
}).join('')
|
|
123
287
|
$('#reader').innerHTML = `
|
|
124
|
-
<div class="
|
|
125
|
-
<
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
<button id="reply-btn">Reply</button>
|
|
129
|
-
<a href="/api/messages/${esc(m.id)}/raw"><button type="button" id="raw-btn">Raw</button></a>
|
|
130
|
-
<button id="delete-btn">Delete</button>
|
|
288
|
+
<div class="convo">
|
|
289
|
+
<div class="convo-head">
|
|
290
|
+
<button id="back">← Back</button>
|
|
291
|
+
<h2>${esc(last.subject) || '(no subject)'}</h2>
|
|
131
292
|
</div>
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
293
|
+
${bubbles}
|
|
294
|
+
<div class="reply-bar">
|
|
295
|
+
<button id="reply-btn" class="primary">Reply</button>
|
|
296
|
+
</div>
|
|
297
|
+
</div>`
|
|
298
|
+
// srcdoc can't be set via innerHTML string safely; bind after render.
|
|
299
|
+
messages.forEach((m) => {
|
|
300
|
+
if (!m.html_body) return
|
|
301
|
+
const frame = document.querySelector(`.bubble[data-id="${CSS.escape(m.id)}"] iframe`)
|
|
302
|
+
if (frame) frame.srcdoc = m.html_body
|
|
139
303
|
})
|
|
140
|
-
$('#
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if (!confirm('Delete this message?')) return
|
|
149
|
-
await api('/api/messages/' + m.id, { method: 'DELETE' })
|
|
150
|
-
$('#reader').innerHTML = '<div class="empty">Deleted</div>'
|
|
151
|
-
loadList()
|
|
152
|
-
}
|
|
304
|
+
$('#back').onclick = () => { $('#main').classList.remove('reading'); currentThread = null; highlightActive() }
|
|
305
|
+
const replyTo = [...messages].reverse().find((m) => m.direction === 'inbound') || last
|
|
306
|
+
$('#reply-btn').onclick = () => openCompose({
|
|
307
|
+
to: replyTo.direction === 'outbound' ? replyTo.to_addr : replyTo.from_addr,
|
|
308
|
+
from: replyTo.direction === 'outbound' ? replyTo.from_addr : replyTo.to_addr,
|
|
309
|
+
subject: (last.subject || '').match(/^re:/i) ? last.subject : 'Re: ' + (last.subject || ''),
|
|
310
|
+
inReplyTo: last.message_id,
|
|
311
|
+
}, 'Reply')
|
|
153
312
|
} catch (e) {
|
|
154
313
|
$('#reader').innerHTML = '<div class="empty">' + esc(e.message) + '</div>'
|
|
155
314
|
}
|
|
156
315
|
}
|
|
157
316
|
|
|
158
|
-
function openCompose(prefill = {}) {
|
|
317
|
+
function openCompose(prefill = {}, title = 'New message') {
|
|
159
318
|
const f = $('#compose-form')
|
|
160
319
|
f.reset()
|
|
320
|
+
$('#compose-title').textContent = title
|
|
161
321
|
for (const [k, v] of Object.entries(prefill)) if (f[k]) f[k].value = v || ''
|
|
162
322
|
$('#compose').showModal()
|
|
323
|
+
f.text.focus()
|
|
163
324
|
}
|
|
164
325
|
|
|
165
326
|
$('#compose-form').addEventListener('submit', async (e) => {
|
|
@@ -168,8 +329,10 @@ $('#compose-form').addEventListener('submit', async (e) => {
|
|
|
168
329
|
const body = Object.fromEntries(['to', 'from', 'subject', 'inReplyTo', 'text']
|
|
169
330
|
.map((k) => [k, f[k].value.trim()]).filter(([, v]) => v))
|
|
170
331
|
try {
|
|
171
|
-
await api('/api/send', { method: 'POST', body: JSON.stringify(body) })
|
|
332
|
+
const r = await api('/api/send', { method: 'POST', body: JSON.stringify(body) })
|
|
172
333
|
$('#compose').close()
|
|
334
|
+
await loadList()
|
|
335
|
+
if (r.threadId) openThread(r.threadId)
|
|
173
336
|
} catch (err) { alert('Send failed: ' + err.message) }
|
|
174
337
|
})
|
|
175
338
|
|
|
@@ -177,10 +340,37 @@ $('#compose-cancel').onclick = () => $('#compose').close()
|
|
|
177
340
|
$('#compose-btn').onclick = () => openCompose()
|
|
178
341
|
$('#refresh-btn').onclick = () => loadList()
|
|
179
342
|
$('#token-btn').onclick = () => { askToken(true); loadList() }
|
|
343
|
+
|
|
180
344
|
$('#list').addEventListener('click', (e) => {
|
|
181
345
|
if (e.target.id === 'loadmore') return loadList(true)
|
|
182
|
-
const
|
|
183
|
-
if (
|
|
346
|
+
const t = e.target.closest('.thread')
|
|
347
|
+
if (t) openThread(t.dataset.thread)
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
$('#reader').addEventListener('click', async (e) => {
|
|
351
|
+
const head = e.target.closest('.bubble .head')
|
|
352
|
+
if (head && !e.target.closest('button')) {
|
|
353
|
+
head.closest('.bubble').classList.toggle('collapsed')
|
|
354
|
+
return
|
|
355
|
+
}
|
|
356
|
+
const raw = e.target.closest('button.raw')
|
|
357
|
+
if (raw) {
|
|
358
|
+
const res = await fetch('/api/messages/' + raw.dataset.id + '/raw', { headers: { authorization: 'Bearer ' + token } })
|
|
359
|
+
const blob = await res.blob()
|
|
360
|
+
const a = Object.assign(document.createElement('a'), { href: URL.createObjectURL(blob), download: raw.dataset.id + '.eml' })
|
|
361
|
+
a.click()
|
|
362
|
+
return
|
|
363
|
+
}
|
|
364
|
+
const del = e.target.closest('button.del')
|
|
365
|
+
if (del) {
|
|
366
|
+
if (!confirm('Delete this message?')) return
|
|
367
|
+
await api('/api/messages/' + del.dataset.id, { method: 'DELETE' })
|
|
368
|
+
const thread = currentThread
|
|
369
|
+
await loadList()
|
|
370
|
+
const stillThere = document.querySelector(`.thread[data-thread="${CSS.escape(thread)}"]`)
|
|
371
|
+
if (stillThere) openThread(thread)
|
|
372
|
+
else { $('#reader').innerHTML = '<div class="empty">Deleted</div>'; $('#main').classList.remove('reading'); currentThread = null }
|
|
373
|
+
}
|
|
184
374
|
})
|
|
185
375
|
|
|
186
376
|
loadList()
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inbox",
|
|
3
3
|
"kind": "app",
|
|
4
|
-
"description": "Agent-accessible email inbox: a Cloudflare Worker that receives routed mail (SQLite DO metadata + R2 raw MIME), sends via Email Sending, and exposes a bearer-authed JSON API
|
|
4
|
+
"description": "Agent-accessible email inbox: a Cloudflare Worker that receives routed mail (SQLite DO metadata + R2 raw MIME), sends via Email Sending, and exposes a bearer-authed JSON API, an MCP server at /mcp (same token), and a minimal web UI",
|
|
5
5
|
"targetDir": "packages/inbox",
|
|
6
|
-
"modules": ["cloudflare-email"],
|
|
6
|
+
"modules": ["cloudflare", "cloudflare-email", "r2"],
|
|
7
7
|
"secrets": ["INBOX_TOKEN", "CLOUDFLARE_API_TOKEN"],
|
|
8
|
-
"instructions": "
|
|
8
|
+
"instructions": "The scaffolded package is generic — all per-project identity (worker name, R2 bucket, default From address) lives in the instance files, not in wrangler.jsonc.\n\nCreate three instance files in packages/infra/environments/<env>/:\n\n // inbox-raw.ts — the R2 bucket for raw MIME\n import { r2Module } from '../../modules/r2'\n export default r2Module.instance({\n name: 'inbox-raw',\n config: { accountId: '<account id>', bucketName: '<project>-inbox-raw' },\n })\n\n // inbox.ts — the worker\n import { cloudflareModule } from '../../modules/cloudflare'\n import inboxRaw from './inbox-raw'\n export default cloudflareModule.instance({\n name: 'inbox',\n imports: [inboxRaw],\n config: {\n workdir: 'packages/inbox',\n accountId: '<account id>',\n workerName: '<project>-inbox',\n workerSecrets: ['INBOX_TOKEN'],\n workerVars: [{ name: 'DEFAULT_FROM', value: 'inbox@mail.<your-domain>' }],\n r2Bindings: [{ binding: 'RAW', from: 'inbox-raw', output: 'bucketName' }],\n },\n })\n\n // email.ts — sending + routing for the domain\n import { cloudflareEmailModule } from '../../modules/cloudflare-email'\n import inbox from './inbox'\n export default cloudflareEmailModule.instance({\n name: 'email',\n imports: [inbox],\n config: {\n accountId: '<account id>', zoneId: '<zone id>', domain: 'mail.<your-domain>',\n enableSending: true, enableRouting: true,\n catchAll: { action: 'worker', workerName: { from: 'inbox', output: 'workerName' } },\n },\n })\n\nAdd INBOX_TOKEN (any long random string, e.g. `openssl rand -hex 32`) to secrets.yaml. CLOUDFLARE_API_TOKEN needs the scopes the cloudflare-email module documents PLUS Account → Workers R2 Storage: Edit (for the r2 module).\n\n`zbc apply <env>` provisions the bucket, deploys the worker, and onboards the domain.\nNote: Cloudflare holds newly onboarded sending domains in a preview sandbox (verified recipients only) for a short period after DNS validates; arbitrary-recipient sending starts working once it drops."
|
|
9
9
|
}
|