@@ -34,7 +34,7 @@ import {
3434import { executeImportAgent } from '../operations/agent/import' ;
3535import { setupPythonProject } from '../operations/python' ;
3636import type { RemovalPreview , RemovalResult , SchemaChange } from '../operations/remove/types' ;
37- import { cliCommandRun } from '../telemetry/cli-command-run.js' ;
37+ import { cliCommandRun , withAddTelemetry } from '../telemetry/cli-command-run.js' ;
3838import {
3939 AgentType ,
4040 AuthorizerType ,
@@ -114,37 +114,51 @@ export class AgentPrimitive extends BasePrimitive<AddAgentOptions, RemovableReso
114114 }
115115
116116 async add ( options : AddAgentOptions ) : Promise < AddResult < { agentName : string ; agentPath ?: string } > > {
117- try {
118- const configBaseDir = findConfigRoot ( ) ;
119- if ( ! configBaseDir ) {
120- return { success : false , error : new NoProjectError ( ) . message } ;
121- }
117+ const attrs = {
118+ language : standardize ( Language , options . language ) ,
119+ framework : standardize ( Framework , options . framework ) ,
120+ model_provider : standardize ( ModelProviderEnum , options . modelProvider ) ,
121+ agent_type : standardize ( AgentType , options . type ) ,
122+ build : standardize ( Build , options . buildType ) ,
123+ protocol : standardize ( Protocol , options . protocol ?? 'HTTP' ) ,
124+ network_mode : standardize ( NetworkModeEnum , options . networkMode ?? 'PUBLIC' ) ,
125+ authorizer_type : standardize ( AuthorizerType , options . authorizerType ?? 'NONE' ) ,
126+ memory : standardize ( Memory , options . memory ?? 'none' ) ,
127+ } ;
122128
123- const configIO = new ConfigIO ( { baseDir : configBaseDir } ) ;
129+ return withAddTelemetry ( 'add.agent' , attrs , async ( ) => {
130+ try {
131+ const configBaseDir = findConfigRoot ( ) ;
132+ if ( ! configBaseDir ) {
133+ return { success : false , error : new NoProjectError ( ) . message } ;
134+ }
124135
125- if ( ! configIO . configExists ( 'project' ) ) {
126- return { success : false , error : new NoProjectError ( ) . message } ;
127- }
136+ const configIO = new ConfigIO ( { baseDir : configBaseDir } ) ;
128137
129- const project = await configIO . readProjectSpec ( ) ;
130- const existingAgent = project . runtimes . find ( agent => agent . name === options . name ) ;
131- if ( existingAgent ) {
132- return {
133- success : false ,
134- error : `Agent "${ options . name } " already exists. To update its configuration, edit agentcore/agentcore.json directly.` ,
135- } ;
136- }
138+ if ( ! configIO . configExists ( 'project' ) ) {
139+ return { success : false , error : new NoProjectError ( ) . message } ;
140+ }
137141
138- if ( options . type === 'import' ) {
139- return await this . handleImportPath ( options , configBaseDir ) ;
140- } else if ( options . type === 'byo' ) {
141- return await this . handleByoPath ( options , configIO , configBaseDir ) ;
142- } else {
143- return await this . handleCreatePath ( options , configBaseDir ) ;
142+ const project = await configIO . readProjectSpec ( ) ;
143+ const existingAgent = project . runtimes . find ( agent => agent . name === options . name ) ;
144+ if ( existingAgent ) {
145+ return {
146+ success : false ,
147+ error : `Agent "${ options . name } " already exists. To update its configuration, edit agentcore/agentcore.json directly.` ,
148+ } ;
149+ }
150+
151+ if ( options . type === 'import' ) {
152+ return await this . handleImportPath ( options , configBaseDir ) ;
153+ } else if ( options . type === 'byo' ) {
154+ return await this . handleByoPath ( options , configIO , configBaseDir ) ;
155+ } else {
156+ return await this . handleCreatePath ( options , configBaseDir ) ;
157+ }
158+ } catch ( err ) {
159+ return { success : false , error : getErrorMessage ( err ) } ;
144160 }
145- } catch ( err ) {
146- return { success : false , error : getErrorMessage ( err ) } ;
147- }
161+ } ) ;
148162 }
149163
150164 async remove ( agentName : string ) : Promise < RemovalResult > {
@@ -277,7 +291,7 @@ export class AgentPrimitive extends BasePrimitive<AddAgentOptions, RemovableReso
277291
278292 // Any flag triggers non-interactive CLI mode
279293 if ( cliOptions . name || cliOptions . framework || cliOptions . json ) {
280- await cliCommandRun ( 'add.agent' , ! ! cliOptions . json , async ( ) => {
294+ await cliCommandRun ( ! ! cliOptions . json , async ( ) => {
281295 const validation = validateAddAgentOptions ( cliOptions ) ;
282296 if ( ! validation . valid ) {
283297 throw new Error ( validation . error ) ;
@@ -340,18 +354,6 @@ export class AgentPrimitive extends BasePrimitive<AddAgentOptions, RemovableReso
340354 console . log ( `\x1b[33mNote: ${ VPC_ENDPOINT_WARNING } \x1b[0m` ) ;
341355 }
342356 }
343-
344- return {
345- language : standardize ( Language , cliOptions . language ! ) ,
346- framework : standardize ( Framework , cliOptions . framework ! ) ,
347- model_provider : standardize ( ModelProviderEnum , cliOptions . modelProvider ! ) ,
348- agent_type : standardize ( AgentType , cliOptions . type ?? 'create' ) ,
349- build : standardize ( Build , cliOptions . build ?? 'CodeZip' ) ,
350- protocol : standardize ( Protocol , cliOptions . protocol ?? 'HTTP' ) ,
351- network_mode : standardize ( NetworkModeEnum , cliOptions . networkMode ?? 'PUBLIC' ) ,
352- authorizer_type : standardize ( AuthorizerType , cliOptions . authorizerType ?? 'NONE' ) ,
353- memory : standardize ( Memory , cliOptions . memory ?? 'none' ) ,
354- } ;
355357 } ) ;
356358 } else {
357359 try {
0 commit comments