@@ -529,9 +529,40 @@ export class WorkflowClient extends BaseClient {
529529 assertRequiredWorkflowOptions ( options ) ;
530530 const compiledOptions = compileWorkflowOptions ( ensureArgs ( options ) ) ;
531531
532- const adaptedInterceptors : WorkflowClientInterceptor [ ] = interceptors . map ( ( i ) =>
533- i . startWithDetails ? i : { ...i , startWithDetails : ( input , next ) => next ( input ) }
534- ) ;
532+ // Adapt legacy `start` interceptors to the new `startWithDetails` interface.
533+ const adaptedInterceptors : WorkflowClientInterceptor [ ] = interceptors . map ( ( i ) => {
534+ // If it already has the new method, or doesn't have the legacy one, no adaptation is needed.
535+ if ( i . startWithDetails || ! i . start ) {
536+ return i ;
537+ }
538+
539+ // This interceptor has a legacy `start` but not `startWithDetails`. We'll adapt it.
540+ return {
541+ ...i ,
542+ startWithDetails : async ( input , next ) : Promise < WorkflowStartOutput > => {
543+ let downstreamOut : WorkflowStartOutput | undefined ;
544+
545+ // Patched `next` for legacy `start` interceptors.
546+ // Captures the full `WorkflowStartOutput` while returning `runId` as a string.
547+ const patchedNext = async ( patchedInput : WorkflowStartInput ) : Promise < string > => {
548+ downstreamOut = await next ( patchedInput ) ;
549+ return downstreamOut . runId ;
550+ } ;
551+
552+ const runIdFromLegacyInterceptor = await i . start ! ( input , patchedNext ) ;
553+
554+ // If the interceptor short-circuited (didn't call `next`), `downstreamOut` will be undefined.
555+ // In that case, we can't have an eager start.
556+ if ( downstreamOut === undefined ) {
557+ return { runId : runIdFromLegacyInterceptor , eagerlyStarted : false } ;
558+ }
559+
560+ // If `next` was called, honor the `runId` from the legacy interceptor but preserve
561+ // the `eagerlyStarted` status from the actual downstream call.
562+ return { ...downstreamOut , runId : runIdFromLegacyInterceptor } ;
563+ } ,
564+ } ;
565+ } ) ;
535566
536567 const startWithDetails = composeInterceptors (
537568 adaptedInterceptors ,
0 commit comments