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,218 +1,17 @@
1
1
  # Workflow APIs
2
2
 
3
- ## Step APIs
3
+ Fetch the documentation for the operation before writing code; use its current signatures and serialization rules.
4
4
 
5
- ```typescript
6
- // step.do()
7
- const result = await step.do('step name', async () => { /* logic */ });
8
- const result = await step.do('step name', { retries, timeout }, async () => {});
5
+ | Task | Documentation |
6
+ | --- | --- |
7
+ | Implement steps; create, batch, inspect, pause, resume, restart, or terminate instances; check parameter and return types | [Workers API](https://developers.cloudflare.com/workflows/build/workers-api/) |
8
+ | Access a step's name, occurrence, retry attempt, and resolved configuration | [Step context](https://developers.cloudflare.com/workflows/build/step-context/) |
9
+ | Configure retries, backoff, timeouts, non-retryable failures, or relative/absolute sleeps | [Sleeping and retrying](https://developers.cloudflare.com/workflows/build/sleeping-and-retrying/) |
10
+ | Pass initial parameters, wait for an external event, or send an event to an instance | [Events and parameters](https://developers.cloudflare.com/workflows/build/events-and-parameters/) |
11
+ | Start instances from a Worker or another Workflow, or schedule execution | [Trigger Workflows](https://developers.cloudflare.com/workflows/build/trigger-workflows/) |
12
+ | Trigger and manage instances from the command line | [Wrangler commands](https://developers.cloudflare.com/workflows/reference/wrangler-commands/) |
13
+ | Manage Workflows over HTTP, including authentication and request bodies | [Workflows REST API](https://developers.cloudflare.com/api/resources/workflows/methods/list/) |
9
14
 
10
- // step.sleep()
11
- await step.sleep('description', '1 hour');
12
- await step.sleep('description', 5000); // ms
15
+ Decide whether input is available at creation or must arrive later as an event. Starting a child instance does not establish that it has completed; choose how the parent will observe completion. Check current instance ID retention and creation semantics before designing duplicate-trigger handling.
13
16
 
14
- // step.sleepUntil()
15
- await step.sleepUntil('description', Date.parse('2024-12-31'));
16
-
17
- // step.waitForEvent()
18
- const data = await step.waitForEvent<PayloadType>('wait', {type: 'webhook-type', timeout: '24h'});
19
- try { const event = await step.waitForEvent('wait', { type: 'approval', timeout: '1h' }); } catch (e) { /* Timeout */ }
20
- ```
21
-
22
- ## WorkflowStepContext
23
-
24
- The `WorkflowStepContext` is passed as the first argument to the `step.do()` callback. It provides runtime information about the current step execution.
25
-
26
- ```typescript
27
- type WorkflowStepContext = {
28
- step: {
29
- name: string; // Step name as passed to step.do()
30
- count: number; // How many times step.do() called with this name in current run (1-indexed)
31
- };
32
- attempt: number; // Current attempt number (1-indexed): 1 = first try, 2 = first retry, etc.
33
- config: WorkflowStepConfig; // Resolved config for this step, including runtime defaults
34
- };
35
- ```
36
-
37
- **Use cases:**
38
- ```typescript
39
- // Adjust behavior based on retry attempt
40
- await step.do('call api', { retries: { limit: 3, delay: '5 seconds', backoff: 'exponential' } }, async (ctx) => {
41
- if (ctx.attempt > 1) console.log(`Retry attempt ${ctx.attempt} for step "${ctx.step.name}"`);
42
- const res = await fetch('https://api.example.com/data');
43
- if (!res.ok) throw new Error(`API failed (attempt ${ctx.attempt})`);
44
- return res.json();
45
- });
46
-
47
- ```
48
-
49
- ## Instance Management
50
-
51
- ```typescript
52
- // Create single
53
- const instance = await env.MY_WORKFLOW.create({id: crypto.randomUUID(), params: { userId: 'user123' }}); // id optional, auto-generated if omitted; throws if ID already exists within retention period
54
-
55
- // Create with custom retention (check docs for default per plan)
56
- const instance = await env.MY_WORKFLOW.create({
57
- id: crypto.randomUUID(),
58
- params: { userId: 'user123' },
59
- retention: '30 days' // Override default retention period
60
- });
61
-
62
- // Batch (max 100, idempotent: skips existing IDs)
63
- const instances = await env.MY_WORKFLOW.createBatch([{id: 'user1', params: {name: 'John'}}, {id: 'user2', params: {name: 'Jane'}}]);
64
-
65
- // Get & Status
66
- const instance = await env.MY_WORKFLOW.get('instance-id');
67
- const status = await instance.status(); // {status: 'queued' | 'running' | 'paused' | 'errored' | 'terminated' | 'complete' | 'waiting' | 'waitingForPause' | 'unknown', error?, output?}
68
-
69
- // Control
70
- await instance.pause(); await instance.resume(); await instance.terminate(); await instance.restart();
71
-
72
- // Send Events
73
- await instance.sendEvent({type: 'approval', payload: { approved: true }}); // Must match waitForEvent type
74
- ```
75
-
76
- ## Triggering Workflows
77
-
78
- ```typescript
79
- // From Worker
80
- export default { async fetch(req, env) { const instance = await env.MY_WORKFLOW.create({id: crypto.randomUUID(), params: { userId: 'user123' }}); return Response.json({ id: instance.id }); }};
81
-
82
- // From Queue
83
- export default { async queue(batch, env) { for (const msg of batch.messages) { await env.MY_WORKFLOW.create({id: `job-${msg.id}`, params: msg.body}); } }};
84
-
85
- // From Cron
86
- export default { async scheduled(event, env) { await env.CLEANUP_WORKFLOW.create({id: `cleanup-${Date.now()}`, params: { timestamp: event.scheduledTime }}); }};
87
-
88
- // From Another Workflow (non-blocking)
89
- export class ParentWorkflow extends WorkflowEntrypoint<Env, Params> {
90
- async run(event, step) {
91
- const child = await step.do('start child', async () => await this.env.CHILD_WORKFLOW.create({id: `child-${event.instanceId}`, params: {}}));
92
- }
93
- }
94
- ```
95
-
96
- ## Error Handling
97
-
98
- ```typescript
99
- import { NonRetryableError } from 'cloudflare:workflows';
100
-
101
- // NonRetryableError
102
- await step.do('validate', async () => {
103
- if (!event.payload.paymentMethod) throw new NonRetryableError('Payment method required');
104
- const res = await fetch('https://api.example.com/charge', { method: 'POST' });
105
- if (res.status === 401) throw new NonRetryableError('Invalid credentials'); // Don't retry
106
- if (!res.ok) throw new Error('Retryable failure'); // Will retry
107
- return res.json();
108
- });
109
-
110
- // Catching Errors
111
- try { await step.do('risky op', async () => { throw new NonRetryableError('Failed'); }); } catch (e) { await step.do('cleanup', async () => {}); }
112
-
113
- // Idempotency
114
- await step.do('charge', async () => {
115
- const sub = await fetch(`https://api/subscriptions/${id}`).then(r => r.json());
116
- if (sub.charged) return sub; // Already done
117
- return await fetch(`https://api/subscriptions/${id}`, {method: 'POST', body: JSON.stringify({ amount: 10.0 })}).then(r => r.json());
118
- });
119
- ```
120
-
121
- ## Type Constraints
122
-
123
- Params and step returns must be `Rpc.Serializable<T>`:
124
-
125
- ```typescript
126
- // ✅ Valid types
127
- type ValidParams = {
128
- userId: string;
129
- count: number;
130
- tags: string[];
131
- metadata: Record<string, unknown>;
132
- };
133
-
134
- // ❌ Invalid types
135
- type InvalidParams = {
136
- callback: () => void; // Functions not serializable
137
- symbol: symbol; // Symbols not serializable
138
- circular: any; // Circular references not allowed
139
- };
140
-
141
- // Step returns follow same rules
142
- const result = await step.do('fetch', async () => {
143
- return { userId: '123', data: [1, 2, 3] }; // ✅ Plain object
144
- });
145
-
146
- // ✅ ReadableStream<Uint8Array> for large binary output (bypasses non-stream step result size limit)
147
- const stream = await step.do('read from R2', async () => {
148
- const obj = await this.env.BUCKET.get('large-file.csv');
149
- return obj.body; // Return the ReadableStream directly
150
- });
151
- ```
152
-
153
- ## Sleep & Scheduling
154
-
155
- ```typescript
156
- // Relative
157
- await step.sleep('wait 1 hour', '1 hour');
158
- await step.sleep('wait 30 days', '30 days');
159
- await step.sleep('wait 5s', 5000); // ms
160
-
161
- // Absolute
162
- await step.sleepUntil('launch date', Date.parse('24 Oct 2024 13:00:00 UTC'));
163
- await step.sleepUntil('deadline', new Date('2024-12-31T23:59:59Z'));
164
- ```
165
-
166
- Units: second, minute, hour, day, week, month, year.
167
- Sleeping instances don't count toward concurrency.
168
-
169
- ## Parameters
170
-
171
- **Pass from Worker:**
172
- ```typescript
173
- const instance = await env.MY_WORKFLOW.create({
174
- id: crypto.randomUUID(),
175
- params: { userId: 'user123', email: 'user@example.com' }
176
- });
177
- ```
178
-
179
- **Access in Workflow:**
180
- ```typescript
181
- async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
182
- const userId = event.payload.userId;
183
- const instanceId = event.instanceId;
184
- const createdAt = event.timestamp;
185
- }
186
- ```
187
-
188
- **CLI Trigger:**
189
- ```bash
190
- npx wrangler workflows trigger my-workflow '{"userId":"user123"}'
191
- ```
192
-
193
- ## Wrangler CLI
194
-
195
- ```bash
196
- npm create cloudflare@latest my-workflow -- --template "cloudflare/workflows-starter"
197
- npx wrangler deploy
198
- npx wrangler workflows list
199
- npx wrangler workflows trigger my-workflow '{"userId":"user123"}'
200
- npx wrangler workflows instances list my-workflow
201
- npx wrangler workflows instances describe my-workflow instance-id
202
- npx wrangler workflows instances pause/resume/terminate my-workflow instance-id
203
- ```
204
-
205
- ## REST API
206
-
207
- ```bash
208
- # Create
209
- curl -X POST "https://api.cloudflare.com/client/v4/accounts/{account_id}/workflows/{workflow_name}/instances" -H "Authorization: Bearer {token}" -d '{"id":"custom-id","params":{"userId":"user123"}}'
210
-
211
- # Status
212
- curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/workflows/{workflow_name}/instances/{instance_id}/status" -H "Authorization: Bearer {token}"
213
-
214
- # Send Event
215
- curl -X POST "https://api.cloudflare.com/client/v4/accounts/{account_id}/workflows/{workflow_name}/instances/{instance_id}/events" -H "Authorization: Bearer {token}" -d '{"type":"approval","payload":{"approved":true}}'
216
- ```
217
-
218
- See: [configuration.md](./configuration.md), [patterns.md](./patterns.md)
17
+ See [configuration.md](./configuration.md) and [patterns.md](./patterns.md).
@@ -1,152 +1,18 @@
1
1
  # Workflow Configuration
2
2
 
3
- ## wrangler.jsonc Setup
4
-
5
- ```jsonc
6
- {
7
- "name": "my-worker",
8
- "main": "src/index.ts",
9
- "compatibility_date": "2025-01-01", // Minimum 2024-10-22 required for Workflows bindings
10
- "observability": {
11
- "enabled": true // Enables Workflows dashboard + structured logs
12
- },
13
- "workflows": [
14
- {
15
- "name": "my-workflow", // Workflow name
16
- "binding": "MY_WORKFLOW", // Env binding
17
- "class_name": "MyWorkflow", // TS class name
18
- // "script_name": "other-worker" // For cross-script calls
19
- // "limits": { "steps": 25000 } // Optional: max steps per instance (check docs for default/max per plan)
20
- }
21
- ],
22
- "limits": {
23
- "cpu_ms": 300000 // Check docs for default and max CPU time per plan
24
- }
25
- }
26
- ```
27
-
28
- ## Step Configuration
29
-
30
- ```typescript
31
- // Basic step
32
- const data = await step.do('step name', async () => ({ result: 'value' }));
33
-
34
- // With retry config
35
- await step.do('api call', {
36
- retries: {
37
- limit: 10, // Accepts number or Infinity
38
- delay: '10 seconds', // Accepts number (ms) or duration string
39
- backoff: 'exponential' // constant | linear | exponential
40
- },
41
- timeout: '30 minutes' // Per-attempt timeout
42
- }, async () => {
43
- const res = await fetch('https://api.example.com/data');
44
- if (!res.ok) throw new Error('Failed');
45
- return res.json();
46
- });
47
- ```
48
-
49
- ### Parallel Steps
50
- ```typescript
51
- const [user, settings] = await Promise.all([
52
- step.do('fetch user', async () => this.env.KV.get(`user:${id}`)),
53
- step.do('fetch settings', async () => this.env.KV.get(`settings:${id}`))
54
- ]);
55
- ```
56
-
57
- ### Conditional Steps
58
- ```typescript
59
- const config = await step.do('fetch config', async () =>
60
- this.env.KV.get('flags', { type: 'json' })
61
- );
62
-
63
- // ✅ Deterministic (based on step output)
64
- if (config.enableEmail) {
65
- await step.do('send email', async () => sendEmail());
66
- }
67
-
68
- // ❌ Non-deterministic (Date.now outside step)
69
- if (Date.now() > deadline) { /* BAD */ }
70
- ```
71
-
72
- ### Dynamic Steps (Loops)
73
- ```typescript
74
- const files = await step.do('list files', async () =>
75
- this.env.BUCKET.list()
76
- );
77
-
78
- for (const file of files.objects) {
79
- await step.do(`process ${file.key}`, async () => {
80
- const obj = await this.env.BUCKET.get(file.key);
81
- return processData(await obj.arrayBuffer());
82
- });
83
- }
84
- ```
85
-
86
- ## Multiple Workflows
87
-
88
- ```jsonc
89
- {
90
- "workflows": [
91
- {"name": "user-onboarding", "binding": "USER_ONBOARDING", "class_name": "UserOnboarding"},
92
- {"name": "data-processing", "binding": "DATA_PROCESSING", "class_name": "DataProcessing"}
93
- ]
94
- }
95
- ```
96
-
97
- Each class extends `WorkflowEntrypoint` with its own `Params` type.
98
-
99
- ## Cross-Script Bindings
100
-
101
- Worker A defines workflow. Worker B calls it by adding `script_name`:
102
-
103
- ```jsonc
104
- // Worker B (caller)
105
- {
106
- "workflows": [{
107
- "name": "billing-workflow",
108
- "binding": "BILLING",
109
- "script_name": "billing-worker" // Points to Worker A
110
- }]
111
- }
112
- ```
113
-
114
- ## Bindings
115
-
116
- Workflows access Cloudflare bindings via `this.env`:
117
-
118
- ```typescript
119
- type Env = {
120
- MY_WORKFLOW: Workflow;
121
- KV: KVNamespace;
122
- DB: D1Database;
123
- BUCKET: R2Bucket;
124
- AI: Ai;
125
- VECTORIZE: VectorizeIndex;
126
- };
127
-
128
- await step.do('use bindings', async () => {
129
- const kv = await this.env.KV.get('key');
130
- const db = await this.env.DB.prepare('SELECT * FROM users').first();
131
- const file = await this.env.BUCKET.get('file.txt');
132
- const ai = await this.env.AI.run('@cf/meta/llama-2-7b-chat-int8', { prompt: 'Hi' });
133
- });
134
- ```
135
-
136
- ## Pages Functions Binding
137
-
138
- Pages Functions can trigger Workflows via service bindings:
139
-
140
- ```typescript
141
- // functions/_middleware.ts
142
- export const onRequest: PagesFunction<Env> = async ({ env, request }) => {
143
- const instance = await env.MY_WORKFLOW.create({
144
- params: { url: request.url }
145
- });
146
- return new Response(`Started ${instance.id}`);
147
- };
148
- ```
149
-
150
- Configure in wrangler.jsonc under `service_bindings`.
151
-
152
- See: [api.md](./api.md), [patterns.md](./patterns.md)
3
+ Use the current guides for configuration fields and setup commands; check the project's installed Wrangler version and generated binding types before adapting an existing project.
4
+
5
+ | Task | Documentation |
6
+ | --- | --- |
7
+ | Scaffold and deploy a Workflow class with its binding | [Build your first Workflow](https://developers.cloudflare.com/workflows/get-started/guide/) |
8
+ | Configure one or more Workflows, including a binding to a Workflow in another Worker | [Wrangler Workflows configuration](https://developers.cloudflare.com/workers/wrangler/configuration/#workflows) |
9
+ | Configure storage, AI, and other resources used by steps | [Workers bindings](https://developers.cloudflare.com/workers/runtime-apis/bindings/) |
10
+ | Choose step retry, backoff, timeout, and sleep behavior | [Sleeping and retrying](https://developers.cloudflare.com/workflows/build/sleeping-and-retrying/) |
11
+ | Schedule instances or trigger them from another Worker | [Trigger Workflows](https://developers.cloudflare.com/workflows/build/trigger-workflows/) |
12
+ | Trigger a Workflow from Pages Functions | [Call Workflows from Pages](https://developers.cloudflare.com/workflows/build/call-workflows-from-pages/) |
13
+ | Develop and inspect instances locally | [Local development](https://developers.cloudflare.com/workflows/build/local-development/) |
14
+ | Set resource budgets and inspect execution | [Limits](https://developers.cloudflare.com/workflows/reference/limits/) and [metrics and analytics](https://developers.cloudflare.com/workflows/observability/metrics-analytics/) |
15
+
16
+ Distinguish the Worker that defines the Workflow from callers that trigger it. For Pages, follow the documented intermediary Worker/service-binding approach. A step's elapsed-time timeout and the Worker's active CPU budget address different failure modes; configure them based on the actual failure.
17
+
18
+ See [api.md](./api.md), [patterns.md](./patterns.md), and [gotchas.md](./gotchas.md).
@@ -1,90 +1,19 @@
1
1
  # Gotchas & Debugging
2
2
 
3
- ## Common Errors
4
-
5
- ### "Step Timeout"
6
-
7
- **Cause:** Step execution exceeding the default or configured timeout
8
- **Solution:** Set custom timeout with `step.do('long operation', {timeout: '30 minutes'}, async () => {...})` or increase CPU limit via `limits.cpu_ms` in wrangler.jsonc
9
-
10
- ### "waitForEvent Timeout"
11
-
12
- **Cause:** Event not received within timeout period (check docs for default/max)
13
- **Solution:** Wrap in try-catch to handle timeout gracefully and proceed with default behavior
14
-
15
- ### "Non-Deterministic Step Names"
16
-
17
- **Cause:** Using dynamic values like `Date.now()` in step names causes replay issues
18
- **Solution:** Use deterministic values like `event.instanceId` for step names
19
-
20
- ### "State Lost in Variables"
21
-
22
- **Cause:** Using module-level or local variables to store state which is lost on hibernation
23
- **Solution:** Return values from `step.do()` which are automatically persisted: `const total = await step.do('step 1', async () => 10)`
24
-
25
- ### "Non-Deterministic Conditionals"
26
-
27
- **Cause:** Using non-deterministic logic (like `Date.now()`) outside steps in conditionals
28
- **Solution:** Move non-deterministic operations inside steps: `const isLate = await step.do('check', async () => Date.now() > deadline)`
29
-
30
- ### "Large Step Returns Exceeding Limit"
31
-
32
- **Cause:** Returning data exceeding the per-step return size limit
33
- **Solution:** Store large data in R2 and return only reference: `{ key: 'r2-object-key' }`. Alternatively, return a `ReadableStream<Uint8Array>` for large binary output
34
-
35
- ### "Step Exceeded CPU Limit But Ran for a Short Time"
36
-
37
- **Cause:** Confusion between CPU time (active compute) and wall-clock time (includes I/O waits)
38
- **Solution:** Network requests, database queries, and sleeps don't count toward CPU. The CPU limit refers to active processing time only
39
-
40
- ### "Idempotency Violation"
41
-
42
- **Cause:** Step operations not idempotent, causing duplicate charges or actions on retry
43
- **Solution:** Check if operation already completed before executing (e.g., check if customer already charged)
44
-
45
- ### "Instance ID Collision"
46
-
47
- **Cause:** Reusing instance IDs causing conflicts
48
- **Solution:** Use unique IDs with timestamp: `await env.MY_WORKFLOW.create({ id: \`${userId}-${Date.now()}\`, params: {} })`
49
-
50
- ### "Instance Data Disappeared After Completion"
51
-
52
- **Cause:** Completed/errored instances are automatically deleted after the retention period (differs by plan)
53
- **Solution:** Export critical data to KV/R2/D1 before workflow completes
54
-
55
- ### "Missing await on step.do"
56
-
57
- **Cause:** Forgetting to await step.do() causing fire-and-forget behavior
58
- **Solution:** Always await step operations: `await step.do('task', ...)`
59
-
60
- ### "Provided event type is invalid"
61
-
62
- **Cause:** Using unsupported characters in `waitForEvent` type (e.g. `.`)
63
- **Solution:** Type only supports letters, digits, `-`, and `_`. Pattern: `^[a-zA-Z0-9_][a-zA-Z0-9-_]*$`
64
-
65
- ## Limits & Pricing
66
-
67
- Limits and pricing change over time. **Always fetch the latest values** from the official docs before citing specific numbers:
68
-
69
- - **Limits:** https://developers.cloudflare.com/workflows/reference/limits/
70
- - **Pricing:** https://developers.cloudflare.com/workflows/reference/pricing/
71
-
72
- Key areas to check: CPU time per step, max steps per workflow, concurrent instance limits, step return size, event payload size, instance creation rate, subrequest limits, state retention period, and name/ID length constraints.
73
-
74
- **Behavioral notes** (stable, not subject to number changes):
75
- - `step.sleep()` and `step.waitForEvent()` don't count toward the max steps limit
76
- - Instances in `waiting` state (sleeping, waiting for event, waiting for retry) don't count toward the concurrent instance limit
77
- - CPU time is active processing only — network I/O, DB queries, and sleeps are wall-clock time, not CPU time
78
- - `waitForEvent` type and workflow/instance names follow pattern `^[a-zA-Z0-9_][a-zA-Z0-9-_]*$`
79
-
80
- ## References
81
-
82
- - [Official Docs](https://developers.cloudflare.com/workflows/)
83
- - [Get Started Guide](https://developers.cloudflare.com/workflows/get-started/guide/)
84
- - [Workers API](https://developers.cloudflare.com/workflows/build/workers-api/)
85
- - [REST API](https://developers.cloudflare.com/api/resources/workflows/)
86
- - [Examples](https://developers.cloudflare.com/workflows/examples/)
87
- - [Limits](https://developers.cloudflare.com/workflows/reference/limits/)
88
- - [Pricing](https://developers.cloudflare.com/workflows/reference/pricing/)
89
-
90
- See: [README.md](./README.md), [configuration.md](./configuration.md), [api.md](./api.md), [patterns.md](./patterns.md)
3
+ Start with the failing instance and step, then fetch the relevant guide before changing code or resource limits.
4
+
5
+ | Symptom or question | What to check |
6
+ | --- | --- |
7
+ | Step timeout or repeated failure | [Sleeping and retrying](https://developers.cloudflare.com/workflows/build/sleeping-and-retrying/) for per-attempt timeout, retry policy, and non-retryable failures |
8
+ | CPU exhaustion despite a short run | [Limits](https://developers.cloudflare.com/workflows/reference/limits/) for active CPU budgets; increasing an elapsed-time timeout does not increase CPU capacity |
9
+ | Missing event or event timeout | [Events and parameters](https://developers.cloudflare.com/workflows/build/events-and-parameters/) for instance targeting, event type/payload requirements, and timeout handling |
10
+ | State disappears or branches change after resuming | [Rules of Workflows](https://developers.cloudflare.com/workflows/build/rules-of-workflows/) for persisted step returns, deterministic names and conditionals, and awaited operations |
11
+ | Duplicate charge, write, or notification | Review the destination's idempotency guarantees and [step design](./patterns.md#design-decisions); retries can repeat an external operation even when its previous attempt committed |
12
+ | Instance ID collision or unexpected batch result | [Workers API](https://developers.cloudflare.com/workflows/build/workers-api/) for creation semantics, plus [limits](https://developers.cloudflare.com/workflows/reference/limits/) for retention |
13
+ | Oversized results, queued instances, or missing historical data | [Limits](https://developers.cloudflare.com/workflows/reference/limits/) for return/event sizes, concurrency, creation rates, and retention; export required long-term results before expiry |
14
+ | Local-only failure or failing introspection test | [Local development](https://developers.cloudflare.com/workflows/build/local-development/) and [Workflow test APIs](https://developers.cloudflare.com/workers/testing/vitest-integration/test-apis/#workflows) |
15
+ | Inspect execution and cost | [Metrics and analytics](https://developers.cloudflare.com/workflows/observability/metrics-analytics/), [Wrangler commands](https://developers.cloudflare.com/workflows/reference/wrangler-commands/), and [pricing](https://developers.cloudflare.com/workflows/reference/pricing/) |
16
+
17
+ CPU time measures active computation; waiting for network or storage I/O is elapsed time. Event waits, sleeps, and retry delays also have their own documented behavior. Check the current limits page for how these states affect concurrency and step accounting rather than treating every wait as active execution.
18
+
19
+ See [README.md](./README.md), [configuration.md](./configuration.md), [api.md](./api.md), and [patterns.md](./patterns.md).