@@ -19,7 +19,6 @@ import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
1919import { Messages , SfError } from '@salesforce/core' ;
2020import { MultiStageOutput } from '@oclif/multi-stage-output' ;
2121import { Agent , findAuthoringBundle } from '@salesforce/agents' ;
22- import { Duration , sleep } from '@salesforce/kit' ;
2322import { colorize } from '@oclif/core/ux' ;
2423import { FlaggablePrompt , promptForAgentFiles } from '../../../flags.js' ;
2524
@@ -99,29 +98,24 @@ export default class AgentValidateAuthoringBundle extends SfCommand<AgentValidat
9998 ] ,
10099 } ) ;
101100
102- try {
103- mso . skipTo ( 'Validating Authoring Bundle' ) ;
104- const targetOrg = flags [ 'target-org' ] ;
105- const conn = targetOrg . getConnection ( flags [ 'api-version' ] ) ;
106- // Call Agent.compileAgent() API
107- await sleep ( Duration . seconds ( 2 ) ) ;
108- await Agent . compileAgent ( conn , readFileSync ( join ( authoringBundleDir , `${ apiName } .agent` ) , 'utf8' ) ) ;
109- mso . updateData ( { status : 'COMPLETED' } ) ;
110- mso . stop ( 'completed' ) ;
111- return {
112- success : true ,
113- } ;
114- } catch ( error ) {
101+ mso . skipTo ( 'Validating Authoring Bundle' ) ;
102+ const targetOrg = flags [ 'target-org' ] ;
103+ const conn = targetOrg . getConnection ( flags [ 'api-version' ] ) ;
104+ const result = await Agent . compileAgentScript (
105+ conn ,
106+ readFileSync ( join ( authoringBundleDir , `${ apiName } .agent` ) , 'utf8' )
107+ ) ;
108+ mso . updateData ( { status : 'COMPLETED' } ) ;
109+ mso . stop ( 'completed' ) ;
110+ if ( result . status === 'failure' ) {
115111 // Handle validation errors
116- const err = SfError . wrap ( error ) ;
117112 let count = 0 ;
118- const formattedError = err . message
119- . split ( '\n' )
120- . map ( ( line ) => {
113+ const formattedError = result . errors
114+ . map ( ( e ) => {
121115 count += 1 ;
122- const type = line . split ( ':' ) [ 0 ] ;
123- const rest = line . substring ( line . indexOf ( ':' ) ) . trim ( ) ;
124- return `- ${ colorize ( 'red' , type ) } ${ rest } `;
116+ return `- ${ colorize ( 'red' , e . errorType ) } ${ e . description } : ${ e . lineStart } : ${ e . colStart } / ${ e . lineEnd } : ${
117+ e . colEnd
118+ } `;
125119 } )
126120 . join ( '\n' ) ;
127121
@@ -131,7 +125,11 @@ export default class AgentValidateAuthoringBundle extends SfCommand<AgentValidat
131125 this . log ( messages . getMessage ( 'error.compilationFailed' , [ formattedError ] ) ) ;
132126 return {
133127 success : false ,
134- errors : err . message . split ( '\n' ) ,
128+ errors : [ formattedError ] ,
129+ } ;
130+ } else {
131+ return {
132+ success : true ,
135133 } ;
136134 }
137135 }
0 commit comments