@@ -28,21 +28,24 @@ function formatFieldDefinitionsName(spec: ResolvedIntentCommandSpec): string {
2828 return `${ spec . className [ 0 ] ?. toLowerCase ( ) ?? '' } ${ spec . className . slice ( 1 ) } Fields`
2929}
3030
31- function formatSchemaFields (
32- fieldSpecs : GeneratedSchemaField [ ] ,
33- spec : ResolvedIntentCommandSpec ,
34- ) : string {
35- return fieldSpecs
31+ function getOptionFields ( spec : ResolvedIntentCommandSpec ) : readonly GeneratedSchemaField [ ] {
32+ if ( spec . execution . kind === 'dynamic-step' ) {
33+ return spec . execution . fields
34+ }
35+
36+ return spec . fieldSpecs
37+ }
38+
39+ function formatSchemaFields ( spec : ResolvedIntentCommandSpec ) : string {
40+ return getOptionFields ( spec )
3641 . map ( ( fieldSpec ) => {
3742 return ` ${ fieldSpec . propertyName } = createIntentOption(${ formatFieldDefinitionsName ( spec ) } .${ fieldSpec . propertyName } )`
3843 } )
3944 . join ( '\n\n' )
4045}
4146
42- function formatFieldDefinitions (
43- fieldSpecs : GeneratedSchemaField [ ] ,
44- spec : ResolvedIntentCommandSpec ,
45- ) : string {
47+ function formatFieldDefinitions ( spec : ResolvedIntentCommandSpec ) : string {
48+ const fieldSpecs = getOptionFields ( spec )
4649 if ( fieldSpecs . length === 0 ) {
4750 return ''
4851 }
@@ -82,14 +85,18 @@ function getCommandDefinitionName(spec: ResolvedIntentCommandSpec): string {
8285}
8386
8487function getBaseClassName ( spec : ResolvedIntentCommandSpec ) : string {
85- if ( spec . input . kind === 'none ' ) {
88+ if ( spec . runnerKind === 'no-input ' ) {
8689 return 'GeneratedNoInputIntentCommand'
8790 }
8891
89- if ( spec . input . defaultSingleAssembly ) {
92+ if ( spec . runnerKind === 'bundled' ) {
9093 return 'GeneratedBundledFileIntentCommand'
9194 }
9295
96+ if ( spec . runnerKind === 'watchable' ) {
97+ return 'GeneratedWatchableFileIntentCommand'
98+ }
99+
93100 return 'GeneratedStandardFileIntentCommand'
94101}
95102
@@ -120,6 +127,29 @@ function formatIntentDefinition(spec: ResolvedIntentCommandSpec): string {
120127} as const`
121128 }
122129
130+ if ( spec . execution . kind === 'dynamic-step' ) {
131+ const commandLabelLine =
132+ spec . input . kind === 'local-files'
133+ ? `\n commandLabel: ${ JSON . stringify ( spec . commandLabel ) } ,`
134+ : ''
135+ const inputPolicyLine =
136+ spec . input . kind === 'local-files'
137+ ? `\n inputPolicy: ${ JSON . stringify ( spec . input . inputPolicy , null , 4 ) . replaceAll ( '\n' , '\n ' ) } ,`
138+ : ''
139+ const outputMode =
140+ spec . outputMode == null ? '' : `\n outputMode: ${ JSON . stringify ( spec . outputMode ) } ,`
141+
142+ return `const ${ getCommandDefinitionName ( spec ) } = {${ commandLabelLine } ${ inputPolicyLine } ${ outputMode }
143+ outputDescription: ${ JSON . stringify ( spec . outputDescription ) } ,
144+ execution: {
145+ kind: 'dynamic-step',
146+ handler: ${ JSON . stringify ( spec . execution . handler ) } ,
147+ fields: Object.values(${ formatFieldDefinitionsName ( spec ) } ),
148+ resultStepName: ${ JSON . stringify ( spec . execution . resultStepName ) } ,
149+ },
150+ } as const`
151+ }
152+
123153 const outputMode =
124154 spec . outputMode == null ? '' : `\n outputMode: ${ JSON . stringify ( spec . outputMode ) } ,`
125155 return `const ${ getCommandDefinitionName ( spec ) } = {
@@ -134,7 +164,7 @@ function formatIntentDefinition(spec: ResolvedIntentCommandSpec): string {
134164}
135165
136166function generateClass ( spec : ResolvedIntentCommandSpec ) : string {
137- const schemaFields = formatSchemaFields ( spec . fieldSpecs , spec )
167+ const schemaFields = formatSchemaFields ( spec )
138168 const baseClassName = getBaseClassName ( spec )
139169
140170 return `
@@ -159,7 +189,7 @@ ${schemaFields}
159189
160190function generateFile ( specs : ResolvedIntentCommandSpec [ ] ) : string {
161191 const fieldDefinitions = specs
162- . map ( ( spec ) => formatFieldDefinitions ( spec . fieldSpecs , spec ) )
192+ . map ( ( spec ) => formatFieldDefinitions ( spec ) )
163193 . filter ( ( definition ) => definition . length > 0 )
164194 const commandDefinitions = specs . map ( formatIntentDefinition )
165195 const commandClasses = specs . map ( generateClass )
@@ -176,6 +206,7 @@ import {
176206 GeneratedBundledFileIntentCommand,
177207 GeneratedNoInputIntentCommand,
178208 GeneratedStandardFileIntentCommand,
209+ GeneratedWatchableFileIntentCommand,
179210} from '../intentRuntime.ts'
180211${ fieldDefinitions . join ( '\n\n' ) }
181212${ commandDefinitions . join ( '\n\n' ) }
0 commit comments