migrating-to-workflow-sdk
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMigrating to the Workflow SDK
迁移至Workflow SDK
Use this skill when converting an existing orchestration system to the Workflow SDK.
当你需要将现有编排系统转换为Workflow SDK时,可使用本指南。
Intake
前期准备
- Identify the source system:
- Temporal
- Inngest
- Trigger.dev
- AWS Step Functions
- Identify the target runtime:
- Managed hosting -> keep examples focused on ,
start(), hooks/webhooks, and route handlers.getRun() - Self-hosted -> also read and explicitly say the workflow/step code can stay the same, but deployment still needs a
references/runtime-targets.mdimplementation and startup bootstrap.World
- Managed hosting -> keep examples focused on
- Extract the source constructs:
- entrypoint
- waits / timers
- external callbacks / approvals
- retries / failure handling
- child workflows / fan-out
- progress streaming
- external side effects
- 识别源系统:
- Temporal
- Inngest
- Trigger.dev
- AWS Step Functions
- 识别目标运行时:
- 托管部署 -> 示例重点关注、
start()、钩子/webhooks以及路由处理器。getRun() - 自托管 -> 同时阅读,并明确说明工作流/步骤代码可保持不变,但部署仍需实现
references/runtime-targets.md并完成启动引导。World
- 托管部署 -> 示例重点关注
- 提取源系统构造:
- 入口点
- 等待/计时器
- 外部回调/审批
- 重试/故障处理
- 子工作流/扇出
- 进度流
- 外部副作用
Default migration rules
默认迁移规则
- Put orchestration in functions.
"use workflow" - Put side effects, SDK calls, DB calls, HTTP calls, and stream I/O in functions.
"use step" - Use only in workflow context.
sleep() - For Signals, , and
step.waitForEvent(), choose exactly one resume surface:.waitForTaskToken- ->
resume/internal+createHook()when the app resumes from server-side code with a deterministic business token.resumeHook() - ->
resume/url/defaultwhen the external system needs a generated callback URL and the defaultcreateWebhook()response is fine.202 Accepted - ->
resume/url/manualonly when the prompt explicitly requires a custom response body, status, or headers.createWebhook({ respondWith: 'manual' }) - If a callback-URL prompt does not specify response semantics, default to and make the assumption explicit in
resume/url/default.## Open Questions
- Never pair with
createWebhook(), and never passresumeHook()totoken:.createWebhook() - Wrap and
start()insidegetRun()functions for child runs."use step" - Use as the idempotency key for external writes.
getStepMetadata().stepId - Use in workflow context to obtain the stream, but interact with it (write, close) only inside
getWritable()functions."use step" - Prefer rollback stacks for multi-step compensation.
- Choose app-boundary syntax in this order:
- If the prompt explicitly asks for framework-agnostic app-boundary code, use plain /
Requesteven when a framework like Hono is named.Response - Otherwise, if the target framework is named, shape app-boundary examples to that framework.
- Otherwise, keep examples framework-agnostic with /
Request. Do not default to Next.js-only route signatures unless Next.js is explicitly named.Response
- If the prompt explicitly asks for framework-agnostic app-boundary code, use plain
Fast memory aid:
- Callback URL + default ack ->
createWebhook()- Callback URL + custom ack ->
createWebhook({ respondWith: 'manual' })- Deterministic server-side resume ->
+createHook()resumeHook()
- 将编排逻辑放在函数中。
"use workflow" - 将副作用、SDK调用、数据库调用、HTTP调用以及流I/O放在函数中。
"use step" - 仅在工作流上下文中使用。
sleep() - 对于Signals、以及
step.waitForEvent(),精确选择一种恢复方式:.waitForTaskToken- -> 当应用从服务器端代码通过确定性业务令牌恢复时,使用
resume/internal+createHook()。resumeHook() - -> 当外部系统需要生成的回调URL且默认
resume/url/default响应即可时,使用202 Accepted。createWebhook() - -> 仅当明确要求自定义响应体、状态码或请求头时,使用
resume/url/manual。createWebhook({ respondWith: 'manual' }) - 如果回调URL需求未指定响应语义,默认使用并在
resume/url/default中明确说明该假设。## 待确认问题
- 切勿将与
createWebhook()配对使用,也不要向resumeHook()传递createWebhook()参数。token: - 对于子工作流运行,将和
start()包裹在getRun()函数中。"use step" - 使用作为外部写入的幂等键。
getStepMetadata().stepId - 在工作流上下文中使用获取流,但仅在
getWritable()函数中进行流交互(写入、关闭)。"use step" - 优先使用回滚栈处理多步骤补偿操作。
- 按以下顺序选择应用边界语法:
- 如果明确要求框架无关的应用边界代码,即使提到了Hono等框架,也使用原生/
Request。Response - 否则,如果指定了目标框架,调整应用边界示例以适配该框架语法。
- 否则,保持示例为框架无关的/
Request格式。除非明确指定Next.js,否则不要默认使用Next.js专属的路由签名。Response
- 如果明确要求框架无关的应用边界代码,即使提到了Hono等框架,也使用原生
快速记忆口诀:
- 回调URL + 默认响应 ->
createWebhook()- 回调URL + 自定义响应 ->
createWebhook({ respondWith: 'manual' })- 确定性服务器端恢复 ->
+createHook()resumeHook()
Fast-path router
快速路径路由
Load when the source pauses for Signals, , or .
references/resume-routing.mdstep.waitForEvent().waitForTaskTokenFast defaults:
- callback URL only ->
resume/url/default - callback URL + explicit custom response ->
resume/url/manual - deterministic server-side resume ->
resume/internal - self-hosted -> add
runtime/self-hosted - named framework -> add
boundary/named-framework - explicit framework-agnostic request -> add
boundary/framework-agnostic
Before drafting , write the selected route keys in .
## Migrated Code## Migration Plan当源系统因Signals、或暂停时,参考。
step.waitForEvent().waitForTaskTokenreferences/resume-routing.md快速默认规则:
- 仅需回调URL ->
resume/url/default - 回调URL + 明确自定义响应 ->
resume/url/manual - 确定性服务器端恢复 ->
resume/internal - 自托管 -> 添加
runtime/self-hosted - 指定框架 -> 添加
boundary/named-framework - 明确要求框架无关请求 -> 添加
boundary/framework-agnostic
在编写之前,将选定的路由键写入。
## 迁移后代码## 迁移计划Source references
源系统参考文档
- Temporal ->
references/temporal.md - Inngest ->
references/inngest.md - Trigger.dev ->
references/trigger-dev.md - AWS Step Functions ->
references/aws-step-functions.md
- Temporal ->
references/temporal.md - Inngest ->
references/inngest.md - Trigger.dev ->
references/trigger-dev.md - AWS Step Functions ->
references/aws-step-functions.md
Shared references
通用参考文档
- — reusable code templates for hooks, child workflows, idempotency, streaming, and rollback.
references/shared-patterns.md - — Managed vs custom
references/runtime-targets.mdguidance.World - — route-key selection, obligations, and exact
references/resume-routing.mdshape.## Migration Plan - — canonical retry mechanics:
references/retries.md,stepFn.maxRetries,RetryableError({ retryAfter }).FatalError
- — 钩子、子工作流、幂等性、流处理和回滚的可复用代码模板。
references/shared-patterns.md - — 托管部署与自定义
references/runtime-targets.md的指导说明。World - — 路由键选择、规范要求以及
references/resume-routing.md的标准格式。## 迁移计划 - — 标准重试机制:
references/retries.md、stepFn.maxRetries、RetryableError({ retryAfter })。FatalError
Required output shape
要求的输出格式
Return the migration in this structure:
md
undefined请按以下结构返回迁移结果:
md
undefinedMigration Plan
迁移计划
Source -> Target Mapping
源系统 -> 目标系统映射
Migrated Code
迁移后代码
App Boundary / Resume Endpoints
应用边界 / 恢复端点
Verification Checklist
验证检查清单
Open Questions
待确认问题
undefinedundefinedVerification checklist
验证检查清单
Fail the draft if any of these are true:
- omits
## Migration PlanRoute keys - omits
## Migration PlanWhy these route keys - lists route keys that do not match the prompt
## Migration Plan - lists required code obligations that do not match the selected route keys
## Migration Plan - Source-framework primitives remain in the migrated code
- Side effects remain in workflow context
- appears inside a step
sleep() - Stream interaction (,
getWriter(),write()) appears inside a workflow functionclose() - Child workflows call /
start()directly from workflow contextgetRun() - External writes omit idempotency keys
- Hooks/webhooks are missing where the source used signals, waitForEvent, or task tokens
- A callback-URL flow uses +
createHook()instead ofresumeHook()createWebhook() - A or
resume/url/defaultmigration invents a user-authored callback route orresume/url/manualwrapper whenresumeWebhook()should be the only resume surfacewebhook.url - is given a custom
createWebhook()or paired withtokenresumeHook()
Validation note:
- Reading webhook request data in workflow context is allowed. Only is step-only.
request.respondWith()
Additional fail conditions:
- output omits
resume/internalin app-boundary coderesumeHook() - output omits a deterministic business token
resume/internal - output emits
resume/internalorcreateWebhook()webhook.url - output does not pass
resume/url/defaultto the external systemwebhook.url - output emits
resume/url/default,resumeHook(), orrespondWith: 'manual'without a custom-response requirement in the promptRequestWithResponse - output invents a user-authored callback route or
resume/url/defaultwrapper whenresumeWebhook()is the intended resume surfacewebhook.url - output does not pass
resume/url/manualto the external systemwebhook.url - output omits
resume/url/manualorRequestWithResponseawait request.respondWith(...) - output calls
resume/url/manualoutside arequest.respondWith(...)function"use step" - output invents a user-authored callback route or
resume/url/manualwrapper whenresumeWebhook()is the intended resume surfacewebhook.url - is paired with
createWebhook()resumeHook() - self-hosted output omits ,
World extends Queue, Streamer, Storage, or the explicit note that the workflow and step code can stay the same while the app still needs a customstartWorkflowWorld()World - named-framework output mixes framework syntax with plain /
Requestapp-boundary code without a framework-agnostic overrideResponse
For concrete passing code, load:
- ->
references/shared-patterns.md## Generated callback URL (default response) - ->
references/shared-patterns.md## Generated callback URL (manual response) - ->
references/runtime-targets.md## Self-hosted output block - ->
references/aws-step-functions.md## Combined recipe: callback URL on self-hosted Hono
如果存在以下任意情况,则草稿不通过:
- 遗漏
## 迁移计划Route keys - 遗漏
## 迁移计划Why these route keys - 列出的路由键与需求不匹配
## 迁移计划 - 列出的代码规范要求与选定的路由键不匹配
## 迁移计划 - 迁移后代码中仍保留源系统框架的原生语法
- 副作用仍存在于工作流上下文中
- 出现在step函数中
sleep() - 流交互(、
getWriter()、write())出现在工作流函数中close() - 子工作流直接在工作流上下文中调用/
start()getRun() - 外部写入未使用幂等键
- 当源系统使用signals、waitForEvent或任务令牌时,未添加钩子/webhooks
- 回调URL流使用+
createHook()而非resumeHook()createWebhook() - 或
resume/url/default迁移中自行编写了回调路由或resume/url/manual包装器,而正确方式应为使用resumeWebhook()作为恢复入口webhook.url - 被传递了自定义
createWebhook()或与token配对使用resumeHook()
额外不通过条件:
- 输出在应用边界代码中遗漏
resume/internalresumeHook() - 输出遗漏确定性业务令牌
resume/internal - 输出包含
resume/internal或createWebhook()webhook.url - 输出未将
resume/url/default传递给外部系统webhook.url - 输出包含
resume/url/default、resumeHook()或respondWith: 'manual',但需求中未要求自定义响应RequestWithResponse - 迁移中自行编写了回调路由或
resume/url/default包装器,而正确方式应为使用resumeWebhook()作为恢复入口webhook.url - 输出未将
resume/url/manual传递给外部系统webhook.url - 输出遗漏
resume/url/manual或RequestWithResponseawait request.respondWith(...) - 输出在
resume/url/manual函数外部调用"use step"request.respondWith(...) - 迁移中自行编写了回调路由或
resume/url/manual包装器,而正确方式应为使用resumeWebhook()作为恢复入口webhook.url - 与
createWebhook()配对使用resumeHook() - 自托管输出遗漏、
World extends Queue, Streamer, Storage或明确说明工作流和step代码可保持不变但仍需自定义startWorkflowWorld()的注释World - 指定框架的输出混合了框架语法与原生/
Request应用边界代码,且无框架无关的覆盖说明Response
如需参考符合要求的代码,请查看:
- ->
references/shared-patterns.md## 生成的回调URL(默认响应) - ->
references/shared-patterns.md## 生成的回调URL(手动响应) - ->
references/runtime-targets.md## 自托管输出代码块 - ->
references/aws-step-functions.md## 组合方案:自托管Hono上的回调URL
Sample prompt
示例需求
Migrate this Inngest workflow to the Workflow SDK.
It uses step.waitForEvent() with a timeout and step.realtime.publish().Expected response shape:
md
undefined将此Inngest工作流迁移至Workflow SDK。
它使用了带超时的step.waitForEvent()和step.realtime.publish()。预期响应格式:
md
undefinedMigration Plan
迁移计划
Source -> Target Mapping
源系统 -> 目标系统映射
Migrated Code
迁移后代码
App Boundary / Resume Endpoints
应用边界 / 恢复端点
Verification Checklist
验证检查清单
Open Questions
待确认问题
undefinedundefinedExample references
示例参考
Load a worked example only when the prompt needs concrete code:
- ->
references/shared-patterns.md## Named-framework internal resume example (Hono) - ->
references/shared-patterns.md## Generated callback URL (default response) - ->
references/shared-patterns.md## Generated callback URL (manual response) - ->
references/runtime-targets.md## Self-hosted output block - ->
references/aws-step-functions.md## Combined recipe: callback URL on self-hosted Hono
Reject these counterexamples:
- or
resume/url/default+ user-authored callback route whenresume/url/manualis the intended resume surfacewebhook.url - paired with
createWebhook()resumeHook() - named-framework app-boundary output mixed with plain /
Requestwithout a framework-agnostic overrideResponse
仅当需求需要具体代码时,才加载以下示例:
- ->
references/shared-patterns.md## 指定框架的内部恢复示例(Hono) - ->
references/shared-patterns.md## 生成的回调URL(默认响应) - ->
references/shared-patterns.md## 生成的回调URL(手动响应) - ->
references/runtime-targets.md## 自托管输出代码块 - ->
references/aws-step-functions.md## 组合方案:自托管Hono上的回调URL
以下反例需避免:
- 或
resume/url/default+ 自行编写的回调路由(正确方式应为使用resume/url/manual作为恢复入口)webhook.url - 与
createWebhook()配对使用resumeHook() - 指定框架的应用边界输出混合了框架语法与原生/
Request,且无框架无关的覆盖说明Response