@@ -9,6 +9,18 @@ import type {
99} from '../../../schema' ;
1010import { LIFECYCLE_TIMEOUT_MAX , LIFECYCLE_TIMEOUT_MIN } from '../../../schema' ;
1111import { getErrorMessage } from '../../errors' ;
12+ import { runCliCommand } from '../../telemetry/cli-command-run.js' ;
13+ import {
14+ AgentType ,
15+ Build ,
16+ Framework ,
17+ Language ,
18+ Memory ,
19+ ModelProvider as ModelProviderEnum ,
20+ NetworkMode as NetworkModeEnum ,
21+ Protocol ,
22+ standardize ,
23+ } from '../../telemetry/schemas/common-shapes.js' ;
1224import { COMMAND_DESCRIPTIONS } from '../../tui/copy' ;
1325import { requireTTY } from '../../tui/guards' ;
1426import { CreateScreen } from '../../tui/screens/create' ;
@@ -79,18 +91,17 @@ async function handleCreateCLI(options: CreateOptions): Promise<void> {
7991 const name = options . name ?? options . projectName ;
8092 const projectName = options . projectName ?? name ;
8193
82- const validation = validateCreateOptions ( options , cwd ) ;
83- if ( ! validation . valid ) {
84- if ( options . json ) {
85- console . log ( JSON . stringify ( { success : false , error : validation . error } ) ) ;
86- } else {
87- console . error ( validation . error ) ;
88- }
89- process . exit ( 1 ) ;
90- }
91-
92- // Handle dry-run mode
94+ // Handle dry-run mode (no telemetry for dry-run)
9395 if ( options . dryRun ) {
96+ const validation = validateCreateOptions ( options , cwd ) ;
97+ if ( ! validation . valid ) {
98+ if ( options . json ) {
99+ console . log ( JSON . stringify ( { success : false , error : validation . error } ) ) ;
100+ } else {
101+ console . error ( validation . error ) ;
102+ }
103+ process . exit ( 1 ) ;
104+ }
94105 const result = getDryRunInfo ( { name : name ! , projectName, cwd, language : options . language } ) ;
95106 if ( options . json ) {
96107 console . log ( JSON . stringify ( result ) ) ;
@@ -103,74 +114,92 @@ async function handleCreateCLI(options: CreateOptions): Promise<void> {
103114 process . exit ( 0 ) ;
104115 }
105116
106- const green = '\x1b[32m' ;
107- const reset = '\x1b[0m' ;
117+ await runCliCommand ( 'create' , ! ! options . json , async ( ) => {
118+ const validation = validateCreateOptions ( options , cwd ) ;
119+ if ( ! validation . valid ) {
120+ throw new Error ( validation . error ) ;
121+ }
122+ const green = '\x1b[32m' ;
123+ const reset = '\x1b[0m' ;
108124
109- // Progress callback for real-time output
110- const onProgress : ProgressCallback | undefined = options . json
111- ? undefined
112- : ( step , status ) => {
113- if ( status === 'done' ) {
114- console . log ( `${ green } [done]${ reset } ${ step } ` ) ;
115- } else if ( status === 'error' ) {
116- console . log ( `\x1b[31m[error]${ reset } ${ step } ` ) ;
117- }
118- // 'start' is silent - we only show when done
119- } ;
125+ // Progress callback for real-time output
126+ const onProgress : ProgressCallback | undefined = options . json
127+ ? undefined
128+ : ( step , status ) => {
129+ if ( status === 'done' ) {
130+ console . log ( `${ green } [done]${ reset } ${ step } ` ) ;
131+ } else if ( status === 'error' ) {
132+ console . log ( `\x1b[31m[error]${ reset } ${ step } ` ) ;
133+ }
134+ // 'start' is silent - we only show when done
135+ } ;
120136
121- // Commander.js --no-agent sets agent=false, not noAgent=true
122- const skipAgent = options . agent === false ;
137+ // Commander.js --no-agent sets agent=false, not noAgent=true
138+ const skipAgent = options . agent === false ;
123139
124- const result = skipAgent
125- ? await createProject ( {
126- name : projectName ! ,
127- cwd,
128- skipGit : options . skipGit ,
129- skipInstall : options . skipInstall ,
130- onProgress,
131- } )
132- : await createProjectWithAgent ( {
133- name : name ! ,
134- projectName,
135- cwd,
136- type : options . type as 'create' | 'import' | undefined ,
137- buildType : ( options . build as BuildType ) ?? 'CodeZip' ,
138- language : ( options . language as TargetLanguage ) ?? ( options . type === 'import' ? 'Python' : undefined ) ,
139- framework : options . framework as SDKFramework | undefined ,
140- modelProvider : options . modelProvider as ModelProvider | undefined ,
141- apiKey : options . apiKey ,
142- memory : ( options . memory as 'none' | 'shortTerm' | 'longAndShortTerm' ) ?? 'none' ,
143- protocol : options . protocol as ProtocolMode | undefined ,
144- agentId : options . agentId ,
145- agentAliasId : options . agentAliasId ,
146- region : options . region ,
147- networkMode : options . networkMode as NetworkMode | undefined ,
148- subnets : parseCommaSeparatedList ( options . subnets ) ,
149- securityGroups : parseCommaSeparatedList ( options . securityGroups ) ,
150- idleTimeout : options . idleTimeout ? Number ( options . idleTimeout ) : undefined ,
151- maxLifetime : options . maxLifetime ? Number ( options . maxLifetime ) : undefined ,
152- sessionStorageMountPath : options . sessionStorageMountPath ,
153- withConfigBundle : options . withConfigBundle ,
154- skipGit : options . skipGit ,
155- skipInstall : options . skipInstall ,
156- skipPythonSetup : options . skipPythonSetup ,
157- onProgress,
158- } ) ;
140+ const result = skipAgent
141+ ? await createProject ( {
142+ name : projectName ! ,
143+ cwd,
144+ skipGit : options . skipGit ,
145+ skipInstall : options . skipInstall ,
146+ onProgress,
147+ } )
148+ : await createProjectWithAgent ( {
149+ name : name ! ,
150+ projectName,
151+ cwd,
152+ type : options . type as 'create' | 'import' | undefined ,
153+ buildType : ( options . build as BuildType ) ?? 'CodeZip' ,
154+ language : ( options . language as TargetLanguage ) ?? ( options . type === 'import' ? 'Python' : undefined ) ,
155+ framework : options . framework as SDKFramework | undefined ,
156+ modelProvider : options . modelProvider as ModelProvider | undefined ,
157+ apiKey : options . apiKey ,
158+ memory : ( options . memory as 'none' | 'shortTerm' | 'longAndShortTerm' ) ?? 'none' ,
159+ protocol : options . protocol as ProtocolMode | undefined ,
160+ agentId : options . agentId ,
161+ agentAliasId : options . agentAliasId ,
162+ region : options . region ,
163+ networkMode : options . networkMode as NetworkMode | undefined ,
164+ subnets : parseCommaSeparatedList ( options . subnets ) ,
165+ securityGroups : parseCommaSeparatedList ( options . securityGroups ) ,
166+ idleTimeout : options . idleTimeout ? Number ( options . idleTimeout ) : undefined ,
167+ maxLifetime : options . maxLifetime ? Number ( options . maxLifetime ) : undefined ,
168+ sessionStorageMountPath : options . sessionStorageMountPath ,
169+ withConfigBundle : options . withConfigBundle ,
170+ skipGit : options . skipGit ,
171+ skipInstall : options . skipInstall ,
172+ skipPythonSetup : options . skipPythonSetup ,
173+ onProgress,
174+ } ) ;
159175
160- if ( options . json ) {
161- console . log ( JSON . stringify ( result ) ) ;
162- } else if ( result . success ) {
163- printCreateSummary ( projectName ! , result . agentName , options . language , options . framework ) ;
164- if ( options . skipInstall ) {
165- console . log (
166- "\nDependency installation was skipped. Run 'npm install' in agentcore/cdk/ and 'uv sync' in your agent directory manually."
167- ) ;
176+ if ( ! result . success ) {
177+ throw new Error ( result . error ) ;
178+ }
179+
180+ if ( options . json ) {
181+ console . log ( JSON . stringify ( result ) ) ;
182+ } else {
183+ printCreateSummary ( projectName ! , result . agentName , options . language , options . framework ) ;
184+ if ( options . skipInstall ) {
185+ console . log (
186+ "\nDependency installation was skipped. Run 'npm install' in agentcore/cdk/ and 'uv sync' in your agent directory manually."
187+ ) ;
188+ }
168189 }
169- } else {
170- console . error ( result . error ) ;
171- }
172190
173- process . exit ( result . success ? 0 : 1 ) ;
191+ return {
192+ language : standardize ( Language , options . language ) ,
193+ framework : standardize ( Framework , options . framework ) ,
194+ model_provider : standardize ( ModelProviderEnum , options . modelProvider ) ,
195+ memory : standardize ( Memory , options . memory ?? 'none' ) ,
196+ protocol : standardize ( Protocol , options . protocol ?? 'http' ) ,
197+ build : standardize ( Build , options . build ?? 'codezip' ) ,
198+ agent_type : standardize ( AgentType , options . type ?? 'create' ) ,
199+ network_mode : standardize ( NetworkModeEnum , options . networkMode ?? 'public' ) ,
200+ has_agent : options . agent !== false ,
201+ } ;
202+ } ) ;
174203}
175204
176205export const registerCreate = ( program : Command ) => {
0 commit comments