@@ -34,6 +34,7 @@ const runtimeInputDefinitionSchema = z.preprocess(
3434 . describe ( 'Type of input data' ) ,
3535 required : z . boolean ( ) . default ( true ) . describe ( 'Whether this input is required' ) ,
3636 description : z . string ( ) . optional ( ) . describe ( 'Help text for the input' ) ,
37+ defaultValue : z . unknown ( ) . optional ( ) . describe ( 'Default value to use when input is omitted' ) ,
3738 } ) ,
3839) ;
3940
@@ -143,33 +144,42 @@ const definition = defineComponent({
143144
144145 for ( const inputDef of runtimeInputs ) {
145146 const value = __runtimeData ?. [ inputDef . id ] ;
147+ const hasValue = value !== undefined && value !== null ;
148+ const hasDefaultValue =
149+ Object . prototype . hasOwnProperty . call ( inputDef , 'defaultValue' ) &&
150+ inputDef . defaultValue !== undefined &&
151+ inputDef . defaultValue !== null ;
152+ let outputValue = value ;
153+
154+ if ( ! hasValue && hasDefaultValue ) {
155+ outputValue = inputDef . defaultValue ;
156+ }
146157
147- if ( inputDef . required && ( value === undefined || value === null ) ) {
158+ if ( inputDef . required && outputValue === undefined ) {
148159 throw new ValidationError (
149160 `Required runtime input '${ inputDef . label } ' (${ inputDef . id } ) was not provided` ,
150161 {
151162 fieldErrors : { [ inputDef . id ] : [ 'This field is required' ] } ,
152163 } ,
153164 ) ;
154165 }
155- // Optional text inputs default to empty string so downstream script ports receive
156- // a defined value instead of failing input validation / retrying indefinitely.
157- if (
158- ( value === undefined || value === null ) &&
159- ! inputDef . required &&
160- inputDef . type === 'text'
161- ) {
162- outputs [ inputDef . id ] = '' ;
163- } else {
164- outputs [ inputDef . id ] = value ;
166+
167+ if ( outputValue === undefined && ! inputDef . required ) {
168+ if ( inputDef . type === 'text' ) {
169+ // Optional text inputs default to empty string so downstream script ports receive
170+ // a defined value instead of failing input validation / retrying indefinitely.
171+ outputValue = '' ;
172+ }
165173 }
174+
175+ outputs [ inputDef . id ] = outputValue ;
166176 // Mask secret values in logs
167177 const logValue =
168178 inputDef . type === 'secret'
169179 ? '***'
170- : typeof value === 'object'
171- ? JSON . stringify ( value )
172- : value ;
180+ : typeof outputValue === 'object'
181+ ? JSON . stringify ( outputValue )
182+ : outputValue ;
173183 context . logger . info ( `[EntryPoint] Output '${ inputDef . id } ' = ${ logValue } ` ) ;
174184 }
175185
0 commit comments