1- import { type CommandFlags } from '../../core/dispatch.ts' ;
2- import type { DaemonRequest , DaemonResponse } from '../../daemon/types.ts' ;
1+ import type { DaemonRequest , DaemonResponse , SessionReplayControl } from '../../daemon/types.ts' ;
32import { getSnapshotReferenceFrame } from '../../daemon/touch-reference-frame.ts' ;
4- import {
5- batchStepsToSessionActions ,
6- invokeReplayActionBlock ,
7- invokeReplayRetryBlock ,
8- } from '../../replay/control-flow-runtime.ts' ;
3+ import { invokeReplayActionBlock } from '../../replay/control-flow-runtime.ts' ;
94import {
105 captureMaestroRawSnapshot ,
116 errorResponse ,
@@ -24,21 +19,19 @@ const MAESTRO_RUN_FLOW_WHEN_POLICY = {
2419 visiblePollMs : 250 ,
2520} as const ;
2621
27- type MaestroRunFlowWhenCondition =
28- | { ok : true ; mode : string ; selector : string }
29- | { ok : false ; response : DaemonResponse } ;
22+ type MaestroRunFlowWhenCondition = { mode : 'visible' | 'notVisible' ; selector : string } ;
23+
24+ type MaestroRunFlowWhenControl = Extract < SessionReplayControl , { kind : 'maestroRunFlowWhen' } > ;
3025
31- export async function invokeMaestroRunFlowWhen ( params : {
26+ export async function invokeMaestroRunFlowWhenControl ( params : {
3227 baseReq : ReplayBaseRequest ;
33- positionals : string [ ] ;
34- batchSteps : CommandFlags [ 'batchSteps' ] | undefined ;
28+ control : MaestroRunFlowWhenControl ;
3529 line : number ;
3630 step : number ;
3731 invoke : ( req : DaemonRequest ) => Promise < DaemonResponse > ;
3832 invokeReplayAction : MaestroReplayInvoker ;
3933} ) : Promise < DaemonResponse > {
40- const condition = readMaestroRunFlowWhenCondition ( params . positionals ) ;
41- if ( ! condition . ok ) return condition . response ;
34+ const condition = readMaestroRunFlowWhenCondition ( params . control ) ;
4235 const conditionResult = await evaluateMaestroRunFlowWhenCondition ( params , condition ) ;
4336 if ( ! conditionResult . ok ) return conditionResult . response ;
4437 if ( ! conditionResult . matched ) {
@@ -50,43 +43,12 @@ export async function invokeMaestroRunFlowWhen(params: {
5043 return await invokeMaestroRunFlowWhenSteps ( params , condition ) ;
5144}
5245
53- export async function invokeMaestroRetry ( params : {
54- positionals : string [ ] ;
55- batchSteps : CommandFlags [ 'batchSteps' ] | undefined ;
56- line : number ;
57- step : number ;
58- invokeReplayAction : MaestroReplayInvoker ;
59- } ) : Promise < DaemonResponse > {
60- const [ maxRetriesValue = '1' ] = params . positionals ;
61- const maxRetries = Number ( maxRetriesValue ) ;
62- if ( ! Number . isInteger ( maxRetries ) || maxRetries < 0 ) {
63- return errorResponse ( 'INVALID_ARGS' , 'retry.maxRetries must be a non-negative integer.' ) ;
64- }
65-
66- return await invokeReplayRetryBlock ( {
67- actions : batchStepsToSessionActions ( params . batchSteps ) ,
68- maxRetries,
69- line : params . line ,
70- step : params . step ,
71- invokeReplayAction : params . invokeReplayAction ,
72- } ) ;
73- }
74-
75- function readMaestroRunFlowWhenCondition ( positionals : string [ ] ) : MaestroRunFlowWhenCondition {
76- const [ mode , selector ] = positionals ;
77- if ( ( mode !== 'visible' && mode !== 'notVisible' ) || ! selector ) {
78- return {
79- ok : false ,
80- response : errorResponse (
81- 'INVALID_ARGS' ,
82- 'runFlow.when requires visible/notVisible and a selector.' ,
83- ) ,
84- } ;
85- }
46+ function readMaestroRunFlowWhenCondition (
47+ control : MaestroRunFlowWhenControl ,
48+ ) : MaestroRunFlowWhenCondition {
8649 return {
87- ok : true ,
88- mode,
89- selector,
50+ mode : control . mode ,
51+ selector : control . selector ,
9052 } ;
9153}
9254
@@ -95,7 +57,7 @@ async function evaluateMaestroRunFlowWhenCondition(
9557 baseReq : ReplayBaseRequest ;
9658 invoke : ( req : DaemonRequest ) => Promise < DaemonResponse > ;
9759 } ,
98- condition : Extract < MaestroRunFlowWhenCondition , { ok : true } > ,
60+ condition : MaestroRunFlowWhenCondition ,
9961) : Promise < { ok : true ; matched : boolean } | { ok : false ; response : DaemonResponse } > {
10062 if ( condition . mode === 'visible' ) {
10163 return await waitForMaestroRunFlowVisibleCondition ( params , condition ) ;
@@ -118,7 +80,7 @@ async function waitForMaestroRunFlowVisibleCondition(
11880 baseReq : ReplayBaseRequest ;
11981 invoke : ( req : DaemonRequest ) => Promise < DaemonResponse > ;
12082 } ,
121- condition : Extract < MaestroRunFlowWhenCondition , { ok : true } > ,
83+ condition : MaestroRunFlowWhenCondition ,
12284) : Promise < { ok : true ; matched : boolean } | { ok : false ; response : DaemonResponse } > {
12385 // Maestro conditionals commonly guard UI that appears immediately after the
12486 // previous command. Keep this bounded and only for visible; notVisible stays
@@ -162,15 +124,15 @@ function readMaestroRunFlowVisibleCondition(
162124
163125async function invokeMaestroRunFlowWhenSteps (
164126 params : {
165- batchSteps : CommandFlags [ 'batchSteps' ] | undefined ;
127+ control : MaestroRunFlowWhenControl ;
166128 line : number ;
167129 step : number ;
168130 invokeReplayAction : MaestroReplayInvoker ;
169131 } ,
170- condition : Extract < MaestroRunFlowWhenCondition , { ok : true } > ,
132+ condition : MaestroRunFlowWhenCondition ,
171133) : Promise < DaemonResponse > {
172134 const response = await invokeReplayActionBlock ( {
173- actions : batchStepsToSessionActions ( params . batchSteps ) ,
135+ actions : params . control . actions ,
174136 line : params . line ,
175137 step : params . step ,
176138 invokeReplayAction : params . invokeReplayAction ,
0 commit comments