pi-cloudflare 0.10.1 → 0.11.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.
Files changed (293) hide show
  1. package/README.md +78 -177
  2. package/package.json +7 -42
  3. package/plugin.json +3 -3
  4. package/skills/agents-sdk/SKILL.md +17 -36
  5. package/skills/agents-sdk/references/client-sdk.md +7 -106
  6. package/skills/agents-sdk/references/human-in-the-loop.md +6 -63
  7. package/skills/agents-sdk/references/mcp.md +9 -184
  8. package/skills/agents-sdk/references/queue-retries.md +12 -73
  9. package/skills/agents-sdk/references/server-driven-messages.md +4 -60
  10. package/skills/agents-sdk/references/state-scheduling.md +10 -166
  11. package/skills/agents-sdk/references/streaming-chat.md +11 -193
  12. package/skills/agents-sdk/references/webhooks-push.md +2 -2
  13. package/skills/agents-sdk/references/workflows.md +14 -125
  14. package/skills/cloudflare/SKILL.md +135 -248
  15. package/skills/cloudflare/references/ai-gateway/README.md +17 -165
  16. package/skills/cloudflare/references/ai-gateway/configuration.md +14 -107
  17. package/skills/cloudflare/references/ai-gateway/dynamic-routing.md +12 -79
  18. package/skills/cloudflare/references/ai-gateway/features.md +22 -96
  19. package/skills/cloudflare/references/ai-gateway/sdk-integration.md +17 -112
  20. package/skills/cloudflare/references/ai-gateway/troubleshooting.md +14 -86
  21. package/skills/cloudflare/references/ai-search/README.md +17 -130
  22. package/skills/cloudflare/references/ai-search/api.md +10 -84
  23. package/skills/cloudflare/references/ai-search/configuration.md +16 -88
  24. package/skills/cloudflare/references/ai-search/gotchas.md +13 -81
  25. package/skills/cloudflare/references/ai-search/patterns.md +12 -82
  26. package/skills/cloudflare/references/analytics-engine/api.md +1 -1
  27. package/skills/cloudflare/references/api/README.md +2 -2
  28. package/skills/cloudflare/references/api/configuration.md +1 -1
  29. package/skills/cloudflare/references/bindings/README.md +11 -117
  30. package/skills/cloudflare/references/bindings/api.md +17 -201
  31. package/skills/cloudflare/references/bindings/configuration.md +20 -188
  32. package/skills/cloudflare/references/bindings/gotchas.md +16 -206
  33. package/skills/cloudflare/references/bindings/patterns.md +15 -195
  34. package/skills/cloudflare/references/bot-management/README.md +1 -1
  35. package/skills/cloudflare/references/browser-rendering/README.md +13 -73
  36. package/skills/cloudflare/references/browser-rendering/api.md +9 -105
  37. package/skills/cloudflare/references/browser-rendering/configuration.md +9 -75
  38. package/skills/cloudflare/references/browser-rendering/gotchas.md +12 -85
  39. package/skills/cloudflare/references/browser-rendering/patterns.md +9 -88
  40. package/skills/cloudflare/references/c3/README.md +6 -5
  41. package/skills/cloudflare/references/c3/api.md +3 -4
  42. package/skills/cloudflare/references/c3/patterns.md +4 -6
  43. package/skills/cloudflare/references/cache-reserve/README.md +1 -1
  44. package/skills/cloudflare/references/containers/README.md +15 -77
  45. package/skills/cloudflare/references/containers/api.md +13 -187
  46. package/skills/cloudflare/references/containers/configuration.md +15 -188
  47. package/skills/cloudflare/references/containers/gotchas.md +16 -178
  48. package/skills/cloudflare/references/containers/patterns.md +14 -198
  49. package/skills/cloudflare/references/cron-triggers/README.md +13 -92
  50. package/skills/cloudflare/references/cron-triggers/api.md +11 -191
  51. package/skills/cloudflare/references/cron-triggers/configuration.md +11 -175
  52. package/skills/cloudflare/references/cron-triggers/gotchas.md +13 -195
  53. package/skills/cloudflare/references/cron-triggers/patterns.md +12 -184
  54. package/skills/cloudflare/references/d1/README.md +9 -127
  55. package/skills/cloudflare/references/d1/api.md +16 -194
  56. package/skills/cloudflare/references/d1/configuration.md +16 -189
  57. package/skills/cloudflare/references/d1/gotchas.md +16 -96
  58. package/skills/cloudflare/references/d1/patterns.md +14 -183
  59. package/skills/cloudflare/references/do-storage/README.md +11 -70
  60. package/skills/cloudflare/references/do-storage/api.md +11 -99
  61. package/skills/cloudflare/references/do-storage/configuration.md +11 -107
  62. package/skills/cloudflare/references/do-storage/gotchas.md +12 -147
  63. package/skills/cloudflare/references/do-storage/patterns.md +11 -190
  64. package/skills/cloudflare/references/do-storage/testing.md +8 -178
  65. package/skills/cloudflare/references/email-routing/README.md +14 -84
  66. package/skills/cloudflare/references/email-routing/api.md +10 -192
  67. package/skills/cloudflare/references/email-routing/configuration.md +13 -186
  68. package/skills/cloudflare/references/email-routing/gotchas.md +12 -193
  69. package/skills/cloudflare/references/email-routing/patterns.md +10 -226
  70. package/skills/cloudflare/references/email-workers/README.md +13 -146
  71. package/skills/cloudflare/references/email-workers/api.md +12 -234
  72. package/skills/cloudflare/references/email-workers/configuration.md +14 -110
  73. package/skills/cloudflare/references/email-workers/gotchas.md +15 -125
  74. package/skills/cloudflare/references/email-workers/patterns.md +14 -100
  75. package/skills/cloudflare/references/flagship/README.md +2 -2
  76. package/skills/cloudflare/references/hyperdrive/README.md +17 -72
  77. package/skills/cloudflare/references/hyperdrive/api.md +19 -136
  78. package/skills/cloudflare/references/hyperdrive/configuration.md +27 -159
  79. package/skills/cloudflare/references/hyperdrive/gotchas.md +15 -72
  80. package/skills/cloudflare/references/hyperdrive/patterns.md +12 -187
  81. package/skills/cloudflare/references/images/README.md +9 -58
  82. package/skills/cloudflare/references/images/api.md +13 -96
  83. package/skills/cloudflare/references/images/configuration.md +17 -211
  84. package/skills/cloudflare/references/images/gotchas.md +16 -99
  85. package/skills/cloudflare/references/images/patterns.md +16 -115
  86. package/skills/cloudflare/references/kv/README.md +9 -83
  87. package/skills/cloudflare/references/kv/api.md +12 -154
  88. package/skills/cloudflare/references/kv/configuration.md +11 -139
  89. package/skills/cloudflare/references/kv/gotchas.md +15 -129
  90. package/skills/cloudflare/references/kv/patterns.md +15 -190
  91. package/skills/cloudflare/references/miniflare/README.md +15 -98
  92. package/skills/cloudflare/references/miniflare/api.md +16 -187
  93. package/skills/cloudflare/references/miniflare/configuration.md +12 -169
  94. package/skills/cloudflare/references/miniflare/gotchas.md +15 -160
  95. package/skills/cloudflare/references/miniflare/patterns.md +15 -177
  96. package/skills/cloudflare/references/network-interconnect/README.md +1 -1
  97. package/skills/cloudflare/references/network-interconnect/gotchas.md +1 -1
  98. package/skills/cloudflare/references/network-interconnect/patterns.md +1 -1
  99. package/skills/cloudflare/references/observability/README.md +20 -81
  100. package/skills/cloudflare/references/observability/api.md +20 -164
  101. package/skills/cloudflare/references/observability/configuration.md +18 -164
  102. package/skills/cloudflare/references/observability/gotchas.md +19 -109
  103. package/skills/cloudflare/references/observability/patterns.md +12 -103
  104. package/skills/cloudflare/references/pages/README.md +13 -81
  105. package/skills/cloudflare/references/pages/api.md +10 -201
  106. package/skills/cloudflare/references/pages/configuration.md +16 -201
  107. package/skills/cloudflare/references/pages/gotchas.md +13 -197
  108. package/skills/cloudflare/references/pages/patterns.md +11 -200
  109. package/skills/cloudflare/references/pages-functions/README.md +13 -91
  110. package/skills/cloudflare/references/pages-functions/api.md +10 -140
  111. package/skills/cloudflare/references/pages-functions/configuration.md +11 -119
  112. package/skills/cloudflare/references/pages-functions/gotchas.md +17 -94
  113. package/skills/cloudflare/references/pages-functions/patterns.md +12 -133
  114. package/skills/cloudflare/references/pipelines/README.md +1 -1
  115. package/skills/cloudflare/references/pulumi/README.md +2 -2
  116. package/skills/cloudflare/references/queues/README.md +15 -87
  117. package/skills/cloudflare/references/queues/api.md +10 -200
  118. package/skills/cloudflare/references/queues/configuration.md +18 -142
  119. package/skills/cloudflare/references/queues/gotchas.md +16 -204
  120. package/skills/cloudflare/references/queues/patterns.md +19 -218
  121. package/skills/cloudflare/references/r2/README.md +17 -86
  122. package/skills/cloudflare/references/r2/api.md +14 -198
  123. package/skills/cloudflare/references/r2/configuration.md +17 -163
  124. package/skills/cloudflare/references/r2/gotchas.md +15 -188
  125. package/skills/cloudflare/references/r2/patterns.md +16 -191
  126. package/skills/cloudflare/references/r2-data-catalog/README.md +11 -70
  127. package/skills/cloudflare/references/r2-data-catalog/api.md +14 -89
  128. package/skills/cloudflare/references/r2-data-catalog/configuration.md +15 -96
  129. package/skills/cloudflare/references/r2-data-catalog/gotchas.md +14 -51
  130. package/skills/cloudflare/references/r2-data-catalog/patterns.md +11 -116
  131. package/skills/cloudflare/references/realtime-sfu/README.md +1 -1
  132. package/skills/cloudflare/references/realtimekit/README.md +1 -1
  133. package/skills/cloudflare/references/secrets-store/README.md +14 -66
  134. package/skills/cloudflare/references/secrets-store/api.md +14 -193
  135. package/skills/cloudflare/references/secrets-store/configuration.md +16 -176
  136. package/skills/cloudflare/references/secrets-store/gotchas.md +14 -92
  137. package/skills/cloudflare/references/secrets-store/patterns.md +14 -194
  138. package/skills/cloudflare/references/smart-placement/README.md +2 -2
  139. package/skills/cloudflare/references/static-assets/README.md +15 -59
  140. package/skills/cloudflare/references/static-assets/api.md +12 -195
  141. package/skills/cloudflare/references/static-assets/configuration.md +16 -186
  142. package/skills/cloudflare/references/static-assets/gotchas.md +18 -162
  143. package/skills/cloudflare/references/static-assets/patterns.md +13 -185
  144. package/skills/cloudflare/references/stream/README.md +15 -107
  145. package/skills/cloudflare/references/stream/api-live.md +16 -193
  146. package/skills/cloudflare/references/stream/api.md +19 -197
  147. package/skills/cloudflare/references/stream/configuration.md +16 -139
  148. package/skills/cloudflare/references/stream/gotchas.md +16 -128
  149. package/skills/cloudflare/references/stream/patterns.md +20 -182
  150. package/skills/cloudflare/references/tail-workers/README.md +14 -82
  151. package/skills/cloudflare/references/tail-workers/api.md +10 -197
  152. package/skills/cloudflare/references/tail-workers/configuration.md +13 -174
  153. package/skills/cloudflare/references/tail-workers/gotchas.md +12 -188
  154. package/skills/cloudflare/references/tail-workers/patterns.md +11 -176
  155. package/skills/cloudflare/references/terraform/README.md +2 -2
  156. package/skills/cloudflare/references/tunnel/README.md +13 -122
  157. package/skills/cloudflare/references/tunnel/api.md +11 -190
  158. package/skills/cloudflare/references/tunnel/configuration.md +12 -155
  159. package/skills/cloudflare/references/tunnel/gotchas.md +12 -144
  160. package/skills/cloudflare/references/tunnel/networking.md +12 -166
  161. package/skills/cloudflare/references/tunnel/patterns.md +12 -189
  162. package/skills/cloudflare/references/vectorize/README.md +15 -126
  163. package/skills/cloudflare/references/vectorize/api.md +14 -84
  164. package/skills/cloudflare/references/vectorize/configuration.md +14 -83
  165. package/skills/cloudflare/references/vectorize/gotchas.md +12 -73
  166. package/skills/cloudflare/references/vectorize/patterns.md +17 -83
  167. package/skills/cloudflare/references/waf/README.md +15 -107
  168. package/skills/cloudflare/references/waf/api.md +17 -202
  169. package/skills/cloudflare/references/waf/configuration.md +14 -199
  170. package/skills/cloudflare/references/waf/gotchas.md +15 -200
  171. package/skills/cloudflare/references/waf/patterns.md +13 -193
  172. package/skills/cloudflare/references/workerd/README.md +2 -2
  173. package/skills/cloudflare/references/workers-ai/README.md +14 -187
  174. package/skills/cloudflare/references/workers-ai/api.md +10 -109
  175. package/skills/cloudflare/references/workers-ai/configuration.md +11 -92
  176. package/skills/cloudflare/references/workers-ai/gotchas.md +12 -111
  177. package/skills/cloudflare/references/workers-ai/patterns.md +9 -115
  178. package/skills/cloudflare/references/workers-for-platforms/README.md +3 -3
  179. package/skills/cloudflare/references/workers-vpc/README.md +1 -1
  180. package/skills/cloudflare/references/workflows/README.md +15 -69
  181. package/skills/cloudflare/references/workflows/api.md +12 -213
  182. package/skills/cloudflare/references/workflows/configuration.md +16 -150
  183. package/skills/cloudflare/references/workflows/gotchas.md +17 -88
  184. package/skills/cloudflare/references/workflows/patterns.md +19 -164
  185. package/skills/cloudflare-api-token/SKILL.md +1 -1
  186. package/skills/cloudflare-cf-cli/SKILL.md +44 -13
  187. package/skills/cloudflare-email-service/SKILL.md +6 -36
  188. package/skills/cloudflare-email-service/references/rest-api.md +12 -179
  189. package/skills/cloudflare-email-service/references/sending.md +17 -250
  190. package/skills/cloudflare-one/SKILL.md +4 -2
  191. package/skills/cloudflare-one-migrations/SKILL.md +1 -1
  192. package/skills/cloudflare-token-roll/SKILL.md +2 -5
  193. package/skills/durable-objects/SKILL.md +10 -16
  194. package/skills/durable-objects/references/rules.md +17 -293
  195. package/skills/durable-objects/references/testing.md +16 -257
  196. package/skills/nextjs-on-cloudflare/SKILL.md +33 -0
  197. package/skills/sandbox-migrate-to-next/SKILL.md +2 -2
  198. package/skills/sandbox-next/SKILL.md +3 -2
  199. package/skills/sandbox-next/references/api-quick-ref.md +15 -90
  200. package/skills/sandbox-stable/SKILL.md +1 -1
  201. package/skills/turnstile-spin/SKILL.md +14 -8
  202. package/skills/workers-best-practices/SKILL.md +36 -103
  203. package/skills/workers-best-practices/references/configuration.md +139 -0
  204. package/skills/workers-best-practices/references/platform-apis.md +51 -0
  205. package/skills/workers-best-practices/references/{rules.md → runtime-patterns.md} +9 -134
  206. package/skills/wrangler/SKILL.md +48 -901
  207. package/bin/setup.mjs +0 -119
  208. package/dist/api-token.d.ts +0 -12
  209. package/dist/api-token.d.ts.map +0 -1
  210. package/dist/api-token.js +0 -23
  211. package/dist/api-token.js.map +0 -1
  212. package/dist/auth-flow.d.ts +0 -15
  213. package/dist/auth-flow.d.ts.map +0 -1
  214. package/dist/auth-flow.js +0 -90
  215. package/dist/auth-flow.js.map +0 -1
  216. package/dist/client.d.ts +0 -18
  217. package/dist/client.d.ts.map +0 -1
  218. package/dist/client.js +0 -47
  219. package/dist/client.js.map +0 -1
  220. package/dist/config.d.ts +0 -20
  221. package/dist/config.d.ts.map +0 -1
  222. package/dist/config.js +0 -10
  223. package/dist/config.js.map +0 -1
  224. package/dist/index.d.ts +0 -22
  225. package/dist/index.d.ts.map +0 -1
  226. package/dist/index.js +0 -65
  227. package/dist/index.js.map +0 -1
  228. package/dist/mcp-server.d.ts +0 -2
  229. package/dist/mcp-server.d.ts.map +0 -1
  230. package/dist/mcp-server.js +0 -106
  231. package/dist/mcp-server.js.map +0 -1
  232. package/dist/oauth.d.ts +0 -44
  233. package/dist/oauth.d.ts.map +0 -1
  234. package/dist/oauth.js +0 -135
  235. package/dist/oauth.js.map +0 -1
  236. package/dist/proxy.d.ts +0 -30
  237. package/dist/proxy.d.ts.map +0 -1
  238. package/dist/proxy.js +0 -41
  239. package/dist/proxy.js.map +0 -1
  240. package/dist/result-caps.d.ts +0 -23
  241. package/dist/result-caps.d.ts.map +0 -1
  242. package/dist/result-caps.js +0 -75
  243. package/dist/result-caps.js.map +0 -1
  244. package/dist/runtime.d.ts +0 -72
  245. package/dist/runtime.d.ts.map +0 -1
  246. package/dist/runtime.js +0 -249
  247. package/dist/runtime.js.map +0 -1
  248. package/dist/servers.d.ts +0 -19
  249. package/dist/servers.d.ts.map +0 -1
  250. package/dist/servers.js +0 -40
  251. package/dist/servers.js.map +0 -1
  252. package/dist/token-store.d.ts +0 -32
  253. package/dist/token-store.d.ts.map +0 -1
  254. package/dist/token-store.js +0 -61
  255. package/dist/token-store.js.map +0 -1
  256. package/dist/tool-cache.d.ts +0 -25
  257. package/dist/tool-cache.d.ts.map +0 -1
  258. package/dist/tool-cache.js +0 -43
  259. package/dist/tool-cache.js.map +0 -1
  260. package/mcp.json +0 -15
  261. package/skills/cloudflare/references/agents-sdk/README.md +0 -89
  262. package/skills/cloudflare/references/agents-sdk/api.md +0 -190
  263. package/skills/cloudflare/references/agents-sdk/configuration.md +0 -182
  264. package/skills/cloudflare/references/agents-sdk/gotchas.md +0 -158
  265. package/skills/cloudflare/references/agents-sdk/patterns.md +0 -192
  266. package/skills/cloudflare/references/durable-objects/README.md +0 -185
  267. package/skills/cloudflare/references/durable-objects/api.md +0 -187
  268. package/skills/cloudflare/references/durable-objects/configuration.md +0 -160
  269. package/skills/cloudflare/references/durable-objects/gotchas.md +0 -197
  270. package/skills/cloudflare/references/durable-objects/patterns.md +0 -201
  271. package/skills/cloudflare/references/sandbox/README.md +0 -96
  272. package/skills/cloudflare/references/sandbox/api.md +0 -198
  273. package/skills/cloudflare/references/sandbox/configuration.md +0 -143
  274. package/skills/cloudflare/references/sandbox/gotchas.md +0 -194
  275. package/skills/cloudflare/references/sandbox/patterns.md +0 -201
  276. package/skills/cloudflare/references/turnstile/README.md +0 -99
  277. package/skills/cloudflare/references/turnstile/api.md +0 -240
  278. package/skills/cloudflare/references/turnstile/configuration.md +0 -222
  279. package/skills/cloudflare/references/turnstile/gotchas.md +0 -218
  280. package/skills/cloudflare/references/turnstile/patterns.md +0 -193
  281. package/skills/cloudflare/references/workers/README.md +0 -108
  282. package/skills/cloudflare/references/workers/api.md +0 -195
  283. package/skills/cloudflare/references/workers/configuration.md +0 -185
  284. package/skills/cloudflare/references/workers/frameworks.md +0 -197
  285. package/skills/cloudflare/references/workers/gotchas.md +0 -137
  286. package/skills/cloudflare/references/workers/patterns.md +0 -198
  287. package/skills/cloudflare/references/wrangler/README.md +0 -135
  288. package/skills/cloudflare/references/wrangler/api.md +0 -188
  289. package/skills/cloudflare/references/wrangler/configuration.md +0 -197
  290. package/skills/cloudflare/references/wrangler/gotchas.md +0 -197
  291. package/skills/cloudflare/references/wrangler/patterns.md +0 -209
  292. package/skills/cloudflare-auth-setup/SKILL.md +0 -59
  293. package/skills/workers-best-practices/references/review.md +0 -174
@@ -1,252 +1,19 @@
1
1
  # Sending Emails — Workers Binding & Agents SDK
2
2
 
3
- Send emails from Cloudflare Workers using the native binding, or from AI agents using the Agents SDK. If your app is NOT on Workers, use the [REST API](rest-api.md) instead.
4
-
5
- ## Workers Binding
6
-
7
- ### Configuration
8
-
9
- ```jsonc
10
- // wrangler.jsonc
11
- {
12
- "send_email": [
13
- { "name": "EMAIL" }
14
- ]
15
- }
16
- ```
17
-
18
- For local development, add `"remote": true` so email sends are proxied to the real service:
19
-
20
- ```jsonc
21
- { "send_email": [{ "name": "EMAIL", "remote": true }] }
22
- ```
23
-
24
- Run `npx wrangler types` to auto-generate the `Env` interface with your `EMAIL` binding. This produces a `worker-configuration.d.ts` with the real `SendEmail`, `EmailAttachment`, `EmailAddress`, and related types from the workerd runtime. Always use these generated types — do not define them manually.
25
-
26
- **Note:** Workers binding uses `email` in the from object (`EmailAddress` type). REST API uses `address`. See [rest-api.md](rest-api.md).
27
-
28
- ## send()
29
-
30
- ```typescript
31
- export default {
32
- async fetch(request: Request, env: Env): Promise<Response> {
33
- const response = await env.EMAIL.send({
34
- to: "user@example.com",
35
- from: { email: "welcome@yourdomain.com", name: "My App" },
36
- subject: "Welcome!",
37
- html: "<h1>Welcome!</h1><p>Thanks for signing up.</p>",
38
- text: "Welcome! Thanks for signing up.",
39
- });
40
- return new Response(`Sent: ${response.messageId}`);
41
- },
42
- } satisfies ExportedHandler<Env>;
43
- ```
44
-
45
- Multiple recipients (max 50 combined to + cc + bcc):
46
-
47
- ```typescript
48
- const response = await env.EMAIL.send({
49
- to: ["user1@example.com", "user2@example.com"],
50
- cc: ["manager@company.com"],
51
- bcc: ["archive@company.com"],
52
- from: { email: "orders@yourdomain.com", name: "Orders" },
53
- replyTo: "support@yourdomain.com",
54
- subject: "Order Confirmation #12345",
55
- html: "<h1>Your order is confirmed</h1>",
56
- text: "Your order is confirmed",
57
- });
58
- ```
59
-
60
- ## Attachments
61
-
62
- **Important:** The Workers binding and REST API handle attachment content differently:
63
- - **Workers binding:** `content` accepts `string | ArrayBuffer | ArrayBufferView`. Strings are treated as **raw content** (not base64). For text files, pass the raw string. For binary files (images, PDFs), pass an `ArrayBuffer`. Note: `ArrayBuffer` does not work with `"remote": true` in local dev — deploy to test binary attachments.
64
- - **REST API:** `content` is always a **base64-encoded string**. See [rest-api.md](rest-api.md).
65
-
66
- ```typescript
67
- // Text file attachment — pass raw string content
68
- const response = await env.EMAIL.send({
69
- to: "customer@example.com",
70
- from: "invoices@yourdomain.com",
71
- subject: "Your Report",
72
- html: "<h1>Report attached</h1>",
73
- text: "Report attached.",
74
- attachments: [{
75
- content: "Name,Amount\nWidget A,100\nWidget B,250", // Raw text, NOT base64
76
- filename: "report.csv",
77
- type: "text/csv",
78
- disposition: "attachment",
79
- }],
80
- });
81
-
82
- // Binary file attachment — use ArrayBuffer
83
- const pdfBytes = await fetchPdfFromSomewhere(); // Returns ArrayBuffer
84
- const response = await env.EMAIL.send({
85
- to: "customer@example.com",
86
- from: "invoices@yourdomain.com",
87
- subject: "Your Invoice",
88
- html: "<h1>Invoice attached</h1>",
89
- text: "Invoice attached.",
90
- attachments: [{
91
- content: pdfBytes,
92
- filename: "invoice-12345.pdf",
93
- type: "application/pdf",
94
- disposition: "attachment",
95
- }],
96
- });
97
-
98
- // Inline image — reference in HTML with cid:<contentId>
99
- const imageBytes = await fetchImageFromSomewhere(); // Returns ArrayBuffer
100
- const response = await env.EMAIL.send({
101
- to: "user@example.com",
102
- from: "marketing@yourdomain.com",
103
- subject: "New Product",
104
- html: '<img src="cid:product-hero" alt="Product" />',
105
- attachments: [{
106
- content: imageBytes,
107
- filename: "product.png",
108
- type: "image/png",
109
- disposition: "inline",
110
- contentId: "product-hero",
111
- }],
112
- });
113
- ```
114
-
115
- Total email size (body + attachments) cannot exceed 25 MiB.
116
-
117
- ## Custom Headers
118
-
119
- Only whitelisted headers allowed. See the [headers reference](https://developers.cloudflare.com/email-service/reference/headers/).
120
-
121
- ```typescript
122
- const response = await env.EMAIL.send({
123
- to: "user@example.com",
124
- from: "notifications@yourdomain.com",
125
- subject: "Your weekly digest",
126
- html: "<h1>Weekly Digest</h1>",
127
- headers: {
128
- "In-Reply-To": "<original-message-id@yourdomain.com>",
129
- "List-Unsubscribe": "<https://yourdomain.com/unsubscribe?id=abc123>",
130
- "List-Unsubscribe-Post": "List-Unsubscribe=One-Click",
131
- "X-Campaign-ID": "weekly-digest-2026-03",
132
- },
133
- });
134
- ```
135
-
136
- ## Legacy EmailMessage API
137
-
138
- The `EmailMessage` API remains supported. Uses raw MIME via `mimetext`:
139
-
140
- ```typescript
141
- import { EmailMessage } from "cloudflare:email";
142
- import { createMimeMessage } from "mimetext";
143
-
144
- const msg = createMimeMessage();
145
- msg.setSender({ name: "Sender", addr: "sender@yourdomain.com" });
146
- msg.setRecipient("recipient@example.com");
147
- msg.setSubject("Hello");
148
- msg.addMessage({ contentType: "text/html", data: "<h1>Hello</h1>" });
149
-
150
- await env.EMAIL.send(new EmailMessage("sender@yourdomain.com", "recipient@example.com", msg.asRaw()));
151
- ```
152
-
153
- Requires `npm install mimetext` and `"nodejs_compat"` in compatibility flags.
154
-
155
- ## Agents SDK Email
156
-
157
- Agents can receive and reply to emails natively via the Agents SDK.
158
-
159
- ```jsonc
160
- // wrangler.jsonc
161
- {
162
- "durable_objects": {
163
- "bindings": [{ "name": "EmailAgent", "class_name": "EmailAgent" }]
164
- },
165
- "migrations": [{ "tag": "v1", "new_sqlite_classes": ["EmailAgent"] }],
166
- "send_email": [{ "name": "EMAIL", "destination_address": "reply@yourdomain.com" }]
167
- }
168
- ```
169
-
170
- ```typescript
171
- import { Agent } from "agents";
172
- import { type AgentEmail } from "agents/email";
173
- import PostalMime from "postal-mime";
174
-
175
- export class EmailAgent extends Agent<Env, State> {
176
- async onEmail(email: AgentEmail) {
177
- const parsed = await PostalMime.parse(await email.getRaw());
178
- await this.replyToEmail(email, {
179
- fromName: "My Agent",
180
- subject: `Re: ${parsed.subject}`,
181
- body: "Thanks for your email! I'll look into this.",
182
- });
183
- }
184
- }
185
- ```
186
-
187
- Route emails to agents with resolvers:
188
-
189
- ```typescript
190
- import { routeAgentEmail } from "agents";
191
- import { createAddressBasedEmailResolver } from "agents/email";
192
-
193
- export default {
194
- async email(message, env) {
195
- await routeAgentEmail(message, env, {
196
- resolver: createAddressBasedEmailResolver("EmailAgent"),
197
- });
198
- },
199
- };
200
- ```
201
-
202
- Resolver types: `createAddressBasedEmailResolver` (recipient → instance name), `createSecureReplyEmailResolver(secret)` (HMAC-signed replies), `createCatchAllEmailResolver("Agent", "default")` (single inbox). Use `isAutoReplyEmail(email.headers)` to skip vacation responders.
203
-
204
- ## Error Handling
205
-
206
- ```typescript
207
- try {
208
- const response = await env.EMAIL.send({ /* ... */ });
209
- } catch (error) {
210
- // error.code is one of the E_* error codes
211
- console.error(`Failed: ${error.code} - ${error.message}`);
212
- }
213
- ```
214
-
215
- These error codes are for the **Workers binding** (thrown as Error objects with `.code` and `.message`). The **REST API** returns standard Cloudflare API numeric error codes instead — see [rest-api.md](rest-api.md).
216
-
217
- | Error Code | What It Means | What to Do |
218
- |------------|---------------|------------|
219
- | `E_VALIDATION_ERROR` | Invalid payload | Check email format, required fields |
220
- | `E_FIELD_MISSING` | Required field missing | Add `to`, `from`, or `subject` |
221
- | `E_TOO_MANY_RECIPIENTS` | Combined to/cc/bcc exceeds 50 | Split into multiple sends |
222
- | `E_SENDER_NOT_VERIFIED` | Domain not onboarded | Run `wrangler email sending enable yourdomain.com` or onboard in Dashboard |
223
- | `E_RECIPIENT_NOT_ALLOWED` | Recipient not in allowed list | Add to `allowed_destination_addresses` |
224
- | `E_RECIPIENT_SUPPRESSED` | Address bounced or reported spam | Remove from your list; check suppression list in Dashboard |
225
- | `E_SENDER_DOMAIN_NOT_AVAILABLE` | Domain not available for sending | Complete domain onboarding |
226
- | `E_CONTENT_TOO_LARGE` | Content exceeds 25 MiB | Reduce attachments or body |
227
- | `E_RATE_LIMIT_EXCEEDED` | Rate limit hit | Retry with exponential backoff |
228
- | `E_DAILY_LIMIT_EXCEEDED` | Daily quota reached | Wait or request limit increase |
229
- | `E_DELIVERY_FAILED` | SMTP delivery failure | Check recipient address, retry if transient |
230
- | `E_INTERNAL_SERVER_ERROR` | Service temporarily unavailable | Retry with exponential backoff |
231
- | `E_HEADER_NOT_ALLOWED` | Header not on whitelist | Use an allowed header; see [headers reference](https://developers.cloudflare.com/email-service/reference/headers/) |
232
- | `E_HEADER_USE_API_FIELD` | Must use API field instead | Set `From`, `To`, etc. via the dedicated API fields, not `headers` |
233
- | `E_HEADER_VALUE_INVALID` | Header value is malformed or empty | Fix the value format (e.g., List-Unsubscribe needs angle-bracket URIs) |
234
- | `E_HEADER_VALUE_TOO_LONG` | Header value exceeds 2,048 bytes | Shorten the header value |
235
- | `E_HEADER_NAME_INVALID` | Invalid header name | Fix characters or keep under 100 bytes |
236
- | `E_HEADERS_TOO_LARGE` | Total headers exceed 16 KB | Reduce number or size of custom headers |
237
- | `E_HEADERS_TOO_MANY` | More than 20 non-X headers | Reduce to 20 or fewer whitelisted headers |
238
-
239
- For `E_RATE_LIMIT_EXCEEDED` and `E_DELIVERY_FAILED`, retry with exponential backoff. For validation errors (`E_VALIDATION_ERROR`, `E_FIELD_MISSING`, `E_SENDER_NOT_VERIFIED`), fix the request — retrying won't help.
240
-
241
- ## Restricted Bindings
242
-
243
- Restrict which `from` addresses a binding can use:
244
-
245
- ```jsonc
246
- {
247
- "send_email": [{
248
- "name": "RESTRICTED_EMAIL",
249
- "allowed_sender_addresses": ["noreply@yourdomain.com", "support@yourdomain.com"]
250
- }]
251
- }
252
- ```
3
+ Prefer the native binding for Workers. For an external application, or when the user explicitly requests HTTP integration, use the [REST API guide](rest-api.md).
4
+
5
+ Read the documentation for the selected task before implementing. Inspect the project's installed Wrangler and Agents SDK versions, configuration, and existing conventions first. Run `wrangler types` through the project's package manager after changing bindings; use its generated types instead of handwritten email interfaces. See [Workers TypeScript](https://developers.cloudflare.com/workers/languages/typescript/) for matching types to the project's compatibility date and flags. Do not upgrade dependencies just to match an example.
6
+
7
+ | Task | Read |
8
+ |------|------|
9
+ | Configure the binding, send a message, or maintain existing MIME-based sending | [Workers API](https://developers.cloudflare.com/email-service/api/send-emails/workers-api/) |
10
+ | Restrict sender or destination addresses | [Configure send bindings](https://developers.cloudflare.com/email-service/configuration/send-bindings/) |
11
+ | Set multiple recipients, CC/BCC, or named addresses | [Specify recipients](https://developers.cloudflare.com/email-service/examples/email-sending/recipients/) |
12
+ | Add files, inline images, or uploaded attachments | [Email attachments](https://developers.cloudflare.com/email-service/examples/email-sending/email-attachments/) |
13
+ | Set custom headers or diagnose header validation | [Email headers](https://developers.cloudflare.com/email-service/reference/headers/) |
14
+ | Check recipient, message-size, or sending quotas | [Limits](https://developers.cloudflare.com/email-service/platform/limits/) |
15
+ | Choose local simulation or remote delivery | [Local email sending](https://developers.cloudflare.com/email-service/local-development/sending/) |
16
+ | Interpret send results and binding errors | [Workers API response and error handling](https://developers.cloudflare.com/email-service/api/send-emails/workers-api/#error-handling) |
17
+ | Send, receive, route, and securely reply from an Agent | [Email agent walkthrough](https://developers.cloudflare.com/agents/examples/email-agent/) |
18
+
19
+ When adapting REST code to a binding, verify address fields, attachment representation, response shape, and errors against the binding docs and generated types. Exercise the relevant success and failure paths using the project's existing checks. Confirm whether the chosen local configuration simulates delivery or sends real mail before testing.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: cloudflare-one
3
- description: "Guides Cloudflare One Zero Trust and SASE work across Access, Gateway, WARP, Tunnel, Cloudflare WAN, DLP, CASB, device posture, and identity. Use when designing, configuring, troubleshooting, or reviewing Cloudflare One deployments. Retrieval-first: use current Cloudflare docs/API schemas instead of embedded product docs."
3
+ description: Design, configure, troubleshoot, or review Cloudflare One Zero Trust and SASE deployments. Use cloudflare-one-migrations for migration planning from other vendors.
4
4
  ---
5
5
 
6
6
  # Cloudflare One
@@ -65,6 +65,8 @@ Use these to avoid jumping straight to configuration. Ask only the prompts relev
65
65
  ## Guardrails
66
66
 
67
67
  - Access controls application authorization; Gateway controls traffic inspection/filtering. Use both when the requirement spans identity-aware app access and network/web security.
68
+ - For new Access deployments, create policies through the reusable policy API (`/access/policies`) and attach them to applications. Do not send inline `policies` in an application create/update request unless the current API documentation explicitly requires an app-scoped policy.
69
+ - Treat an app-scoped policy reported as `reusable: false` as legacy. Migrate existing policies with the documented `make_reusable` endpoint or replace them with reusable policies; do not create new legacy policies. Distinguish legacy policies from the deprecated legacy private-network application type.
68
70
  - Public hostname Access apps can be clientless. Private destination apps require WARP/Device client or another network on-ramp plus routes and DNS resolution. Retrieve [self-hosted private app](https://developers.cloudflare.com/cloudflare-one/access-controls/applications/non-http/self-hosted-private-app/) docs before configuring private destinations.
69
71
  - Cloudflare Tunnel is an off-ramp from a private network to Cloudflare. Cloudflare WAN and Mesh are other off-ramps which can also be on-ramps.
70
72
  - Group-based policies depend on IdP group claims or SCIM. If group sync is missing, do not invent group selectors.
@@ -162,7 +164,7 @@ Use these to avoid jumping straight to configuration. Ask only the prompts relev
162
164
 
163
165
  ## Validation Prompts
164
166
 
165
- - Access: test authorized, unauthorized, posture-failing, service-token, and multi-IdP flows when applicable; inspect logs and policy precedence.
167
+ - Access: test authorized, unauthorized, posture-failing, service-token, and multi-IdP flows when applicable; inspect logs and policy precedence. For new policies, verify they are managed through the reusable policy collection and not returned as `reusable: false` app-scoped policies.
166
168
  - Private network access: verify route lookup, tunnel health, origin reachability, split tunnel behavior, DNS resolution, and end-to-end access from a device client test device.
167
169
  - Gateway: verify rule type, action, traffic expression, precedence/evaluation phase, referenced lists, and Gateway settings before enabling broadly.
168
170
  - TLS/DLP: test Do Not Inspect exceptions and root CA trust before enabling inspection; test DLP with known samples and monitor false positives before blocking.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: cloudflare-one-migrations
3
- description: Plans migrations from Zscaler ZIA/ZPA, Palo Alto, legacy VPN, SWG, or SASE stacks to Cloudflare One. Use for migration assessments, policy mapping, rollout plans, and parity/gap analysis.
3
+ description: Assess and plan migrations from existing VPN, SWG, or SASE platforms to Cloudflare One, including policy mapping, parity gaps, and rollout.
4
4
  ---
5
5
 
6
6
  # Cloudflare One Migrations
@@ -19,15 +19,12 @@ There is no public roll endpoint (`POST /user/tokens/:id/roll` returns `7000 No
19
19
  3. The secret modal (`Token rolled successfully` / `Copy your API token now`) holds the **only copy**. Capture `cfut_...` immediately without printing it in chat or logs.
20
20
  4. Click Done. Verify the token row still shows Active.
21
21
  5. Validate before handoff: `GET /user` (identity), one scoped read per newly relied-upon group (see cloudflare-api-token skill matrix). `GET /user/tokens/:id` confirming policies is safe (never returns the secret).
22
- 6. **Store it through the active host's secret mechanism — never put the literal in repository configuration.**
23
- - **Native Pi:** write `export CLOUDFLARE_API_TOKEN="<secret>"` to `~/.pi/cloudflare-api-token` (mode `0600`); ensure `~/.zshrc` sources it inside the marked idempotent block; set `~/.pi/agent/settings.json` → `pi-cloudflare.apiToken` to the literal reference `${CLOUDFLARE_API_TOKEN}`; preserve every other setting; then verify a fresh shell and one live API read.
24
- - **Agent Plugin:** Agent Plugins 1.0 has no portable secret-reference field. Store the value with the client's own secret/environment facility so the plugin MCP subprocess receives `CLOUDFLARE_API_TOKEN`. Do not write the API token into `${PLUGIN_DATA}` yourself; that directory is reserved here for the package-managed browser OAuth token store. Restart or reload the plugin if the client only snapshots environment at process launch, then verify one live API read.
25
- - **Unknown host:** stop before writing. Ask where that client stores MCP environment secrets; never guess a Pi path.
22
+ 6. **Store it where the tools read it — never put the literal in repository configuration.** Write `export CLOUDFLARE_API_TOKEN="<secret>"` to the environment file the host sources (the estate uses `~/.pi/cloudflare-api-token`, mode `0600`), or export it in the session; then verify one live API read (`cf auth whoami`).
26
23
  7. Destroy temporary copies. Report stored + verified **without printing the secret**.
27
24
 
28
25
  ## What success looks like
29
26
 
30
27
  - Exactly one active token under the expected name (list and check for duplicates — a failed first attempt often leaves one behind).
31
28
  - `modified_on` bumped, old secret rejected (spot-check one call with it only if exposure is suspected; otherwise just rotate wiring).
32
- - The active host can resolve the new token after a fresh MCP/session start and one live scoped read succeeds.
29
+ - A fresh shell resolves the new token and one live scoped read succeeds.
33
30
  - Never retry-loop the confirm dialog. One confirm, one capture.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: durable-objects
3
- description: Create and review Cloudflare Durable Objects. Use when building stateful coordination (chat rooms, multiplayer games, booking systems), implementing RPC methods, SQLite storage, alarms, WebSockets, or reviewing DO code for best practices. Covers Workers integration, wrangler config, and testing with Vitest. Biases towards retrieval from Cloudflare docs over pre-trained knowledge.
3
+ description: Build, debug, or review Cloudflare Durable Objects code for persistent state and coordination.
4
4
  ---
5
5
 
6
6
  # Durable Objects
@@ -17,6 +17,7 @@ Your knowledge of Durable Objects APIs and configuration may be outdated. **Pref
17
17
  | API Reference | https://developers.cloudflare.com/durable-objects/api/ |
18
18
  | Best Practices | https://developers.cloudflare.com/durable-objects/best-practices/ |
19
19
  | Examples | https://developers.cloudflare.com/durable-objects/examples/ |
20
+ | Roles and permissions | https://developers.cloudflare.com/workers/authorization/durable-objects/ |
20
21
 
21
22
  Fetch the relevant doc page when implementing features.
22
23
 
@@ -26,13 +27,13 @@ Fetch the relevant doc page when implementing features.
26
27
  - Implementing RPC methods, alarms, or WebSocket handlers
27
28
  - Reviewing existing DO code for best practices
28
29
  - Configuring wrangler.jsonc/toml for DO bindings and migrations
29
- - Writing tests with `@cloudflare/vitest-pool-workers`
30
+ - Writing tests with Cloudflare’s Vitest integration
30
31
  - Designing sharding strategies and parent-child relationships
31
32
 
32
33
  ## Reference Documentation
33
34
 
34
35
  - `./references/rules.md` - Core rules, storage, concurrency, RPC, alarms
35
- - `./references/testing.md` - Vitest setup, unit/integration tests, alarm testing
36
+ - [Testing reference](./references/testing.md) - Current Vitest documentation, migration choices, and test selection
36
37
  - `./references/workers.md` - Workers handlers, types, wrangler config, observability
37
38
 
38
39
  Search: `blockConcurrencyWhile`, `idFromName`, `getByName`, `setAlarm`, `sql.exec`
@@ -119,6 +120,10 @@ export default {
119
120
  6. **Persist first, cache second** - Always write to storage before updating in-memory state
120
121
  7. **One alarm per DO** - `setAlarm()` replaces any existing alarm
121
122
 
123
+ ## Authorization
124
+
125
+ Durable Objects do not have separate roles or permissions; access follows the Worker that implements them. Retrieve the current [Durable Objects authorization guidance](https://developers.cloudflare.com/workers/authorization/durable-objects/) before granting observability or Data Studio access, and scope the Workers role to the intended Worker or Workers product.
126
+
122
127
  ## Anti-Patterns (NEVER)
123
128
 
124
129
  - Single global DO handling all requests (bottleneck)
@@ -170,17 +175,6 @@ async alarm(): Promise<void> {
170
175
  await this.ctx.storage.deleteAlarm();
171
176
  ```
172
177
 
173
- ## Testing Quick Start
178
+ ## Testing
174
179
 
175
- ```typescript
176
- import { env } from "cloudflare:test";
177
- import { describe, it, expect } from "vitest";
178
-
179
- describe("MyDO", () => {
180
- it("should work", async () => {
181
- const stub = env.MY_DO.getByName("test");
182
- const result = await stub.addItem("test");
183
- expect(result).toBe(1);
184
- });
185
- });
186
- ```
180
+ Read the [testing reference](./references/testing.md) before configuring a suite or writing Durable Object tests. It routes to current setup, APIs, and examples and identifies the behavior to cover.