@@ -11,7 +11,7 @@ import type {
1111 WorkflowsWorkflow ,
1212} from "../generated" ;
1313import type { zWorkflowsListInstancesData } from "../generated/zod.gen" ;
14- import type { RestartFromStep } from "@cloudflare/workflows-shared/src/binding" ;
14+ import type { WorkflowBinding } from "@cloudflare/workflows-shared/src/binding" ;
1515import type { z } from "zod" ;
1616
1717// ============================================================================
@@ -30,16 +30,6 @@ interface DirectoryEntry {
3030 birthtimeMs : number ;
3131}
3232
33- /** Methods on a WorkflowInstance handle (from workflow.get()). */
34- interface WorkflowHandle {
35- pause ( ) : Promise < void > ;
36- resume ( ) : Promise < void > ;
37- restart ( options ?: { from ?: RestartFromStep } ) : Promise < void > ;
38- terminate ( ) : Promise < void > ;
39- sendEvent ( args : { payload : unknown ; type : string } ) : Promise < void > ;
40- status ( ) : Promise < { status : string ; output ?: unknown ; error ?: unknown } > ;
41- }
42-
4333/** RPC methods exposed by the Engine Durable Object. */
4434interface EngineStub {
4535 getInstanceMetadata ( ) : Promise < {
@@ -173,12 +163,15 @@ function getEngineNamespace(
173163 * Get the Workflow proxy binding for a workflow.
174164 * Used for operations that go through the standard Workflow interface (create).
175165 */
176- function getWorkflowBinding ( env : Env , workflowName : string ) : Workflow | null {
166+ function getWorkflowBinding (
167+ env : Env ,
168+ workflowName : string
169+ ) : WorkflowBinding | null {
177170 const info = env . LOCAL_EXPLORER_BINDING_MAP . workflows [ workflowName ] ;
178171 if ( ! info ) {
179172 return null ;
180173 }
181- return env [ info . binding ] as Workflow ;
174+ return env [ info . binding ] as unknown as WorkflowBinding ;
182175}
183176
184177function getLocalWorkflows ( env : Env ) : WorkflowsWorkflow [ ] {
@@ -886,6 +879,14 @@ export async function changeWorkflowInstanceStatus(
886879 ) ;
887880 }
888881
882+ if ( body . rollback !== undefined && action !== "terminate" ) {
883+ return errorResponse (
884+ 400 ,
885+ 10001 ,
886+ "'rollback' is only valid when terminating."
887+ ) ;
888+ }
889+
889890 const handle = await workflow . get ( instanceId ) ;
890891
891892 switch ( action ) {
@@ -904,12 +905,13 @@ export async function changeWorkflowInstanceStatus(
904905 ) ;
905906 }
906907 const opts = body . from ? { from : body . from } : undefined ;
907- // TODO(vaish): remove cast once @cloudflare/workers-types ships restart options
908- await ( handle as unknown as WorkflowHandle ) . restart ( opts ) ;
908+ await handle . restart ( opts ) ;
909909 break ;
910910 }
911911 case "terminate" :
912- await handle . terminate ( ) ;
912+ await handle . terminate (
913+ body . rollback === true ? { rollback : true } : undefined
914+ ) ;
913915 break ;
914916 }
915917
@@ -1044,9 +1046,7 @@ export async function sendWorkflowInstanceEvent(
10441046 // Empty body is fine — payload is optional
10451047 }
10461048
1047- const handle = ( await workflow . get (
1048- instanceId
1049- ) ) as unknown as WorkflowHandle ;
1049+ const handle = await workflow . get ( instanceId ) ;
10501050 await handle . sendEvent ( { payload, type : eventType } ) ;
10511051
10521052 return c . json ( wrapResponse ( { success : true } ) ) ;
0 commit comments