55 * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66 */
77import { EOL } from 'node:os' ;
8+ import { join } from 'node:path' ;
9+ import { readFileSync } from 'node:fs' ;
810import { SfCommand , Flags } from '@salesforce/sf-plugins-core' ;
911import { Messages , Lifecycle , SfError } from '@salesforce/core' ;
10- import { Agent } from '@salesforce/agents' ;
12+ import { Agent , findAuthoringBundle } from '@salesforce/agents' ;
1113import { RetrieveResult , RequestStatus } from '@salesforce/source-deploy-retrieve' ;
1214import { ensureArray } from '@salesforce/kit' ;
13- import { findAndReadAfScript } from '../../../utils/afscriptFinder.js' ;
1415
1516Messages . importMessagesDirectoryFromMetaUrl ( import . meta. url ) ;
1617const messages = Messages . loadMessages ( '@salesforce/plugin-agent' , 'agent.publish.authoring-bundle' ) ;
@@ -39,9 +40,11 @@ export default class AgentPublishAuthoringBundle extends SfCommand<AgentPublishA
3940
4041 public async run ( ) : Promise < AgentPublishAuthoringBundleResult > {
4142 const { flags } = await this . parse ( AgentPublishAuthoringBundle ) ;
42- const afScript = findAndReadAfScript ( this . project ! . getPath ( ) , flags [ 'api-name' ] ) ;
43+ // todo: this eslint warning can be removed once published
44+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
45+ const authoringBundleDir = findAuthoringBundle ( this . project ! . getPath ( ) , flags [ 'api-name' ] ) ;
4346
44- if ( ! afScript ) {
47+ if ( ! authoringBundleDir ) {
4548 throw new SfError ( messages . getMessage ( 'error.afscriptNotFound' , [ flags [ 'api-name' ] ] ) , 'AfScriptNotFoundError' , [
4649 messages . getMessage ( 'error.afscriptNotFoundAction' ) ,
4750 ] ) ;
@@ -66,7 +69,10 @@ export default class AgentPublishAuthoringBundle extends SfCommand<AgentPublishA
6669
6770 // First compile the AF script to get the Agent JSON
6871 this . log ( 'Compiling authoring bundle...' ) ;
69- const agentJson = await Agent . compileAfScript ( conn , afScript ) ;
72+ const agentJson = await Agent . compileAfScript (
73+ conn ,
74+ readFileSync ( join ( authoringBundleDir , `${ flags [ 'api-name' ] } .afscript` ) , 'utf8' )
75+ ) ;
7076
7177 // Then publish the Agent JSON to create the agent
7278 this . log ( 'Publishing agent...' ) ;
0 commit comments