@@ -13,10 +13,11 @@ import ansis from 'ansis';
1313import select from '@inquirer/select' ;
1414import inquirerInput from '@inquirer/input' ;
1515import figures from '@inquirer/figures' ;
16+ // eslint-disable-next-line import/no-extraneous-dependencies
1617import { Agent , SfAgent } from '@salesforce/agents' ;
1718
1819Messages . importMessagesDirectoryFromMetaUrl ( import . meta. url ) ;
19- const messages = Messages . loadMessages ( '@salesforce/plugin-agent' , 'agent.create .spec' ) ;
20+ const messages = Messages . loadMessages ( '@salesforce/plugin-agent' , 'agent.generate .spec' ) ;
2021
2122export type AgentCreateSpecResult = {
2223 isSuccess : boolean ;
@@ -40,12 +41,6 @@ type FlagsOfPrompts<T extends Record<string, FlaggablePrompt>> = Record<
4041> ;
4142
4243const FLAGGABLE_PROMPTS = {
43- name : {
44- message : messages . getMessage ( 'flags.name.summary' ) ,
45- validate : ( d : string ) : boolean | string => d . length > 0 || 'Name cannot be empty' ,
46- char : 'n' ,
47- required : true ,
48- } ,
4944 type : {
5045 message : messages . getMessage ( 'flags.type.summary' ) ,
5146 validate : ( d : string ) : boolean | string => d . length > 0 || 'Type cannot be empty' ,
@@ -124,6 +119,11 @@ export default class AgentCreateSpec extends SfCommand<AgentCreateSpecResult> {
124119 summary : messages . getMessage ( 'flags.output-dir.summary' ) ,
125120 default : 'config' ,
126121 } ) ,
122+ 'file-name' : Flags . string ( {
123+ char : 'f' ,
124+ summary : messages . getMessage ( 'flags.file-name.summary' ) ,
125+ default : 'agentSpec.json' ,
126+ } ) ,
127127 } ;
128128
129129 public async run ( ) : Promise < AgentCreateSpecResult > {
@@ -142,11 +142,15 @@ export default class AgentCreateSpec extends SfCommand<AgentCreateSpecResult> {
142142
143143 this . log ( ) ;
144144 this . styledHeader ( 'Agent Details' ) ;
145- const name = await this . getFlagOrPrompt ( flags . name , FLAGGABLE_PROMPTS . name ) ;
146- const type = await this . getFlagOrPrompt ( flags . type , FLAGGABLE_PROMPTS . type ) as 'customer_facing' | 'employee_facing' ;
145+ const type = ( await this . getFlagOrPrompt ( flags . type , FLAGGABLE_PROMPTS . type ) ) as
146+ | 'customer_facing'
147+ | 'employee_facing' ;
147148 const role = await this . getFlagOrPrompt ( flags . role , FLAGGABLE_PROMPTS . role ) ;
148149 const companyName = await this . getFlagOrPrompt ( flags [ 'company-name' ] , FLAGGABLE_PROMPTS [ 'company-name' ] ) ;
149- const companyDescription = await this . getFlagOrPrompt ( flags [ 'company-description' ] , FLAGGABLE_PROMPTS [ 'company-description' ] ) ;
150+ const companyDescription = await this . getFlagOrPrompt (
151+ flags [ 'company-description' ] ,
152+ FLAGGABLE_PROMPTS [ 'company-description' ]
153+ ) ;
150154 const companyWebsite = await this . getFlagOrPrompt ( flags [ 'company-website' ] , FLAGGABLE_PROMPTS [ 'company-website' ] ) ;
151155
152156 this . log ( ) ;
@@ -155,11 +159,16 @@ export default class AgentCreateSpec extends SfCommand<AgentCreateSpecResult> {
155159 const connection = flags [ 'target-org' ] . getConnection ( flags [ 'api-version' ] ) ;
156160 const agent = new Agent ( connection , this . project as SfProject ) as SfAgent ;
157161 const agentSpec = await agent . createSpec ( {
158- name, type, role, companyName, companyDescription, companyWebsite
162+ name : flags [ 'file-name' ] . split ( '.json' ) [ 0 ] ,
163+ type,
164+ role,
165+ companyName,
166+ companyDescription,
167+ companyWebsite,
159168 } ) ;
160169
161170 // Write a file with the returned job specs
162- const filePath = join ( flags [ 'output-dir' ] , 'agentSpec.json' ) ;
171+ const filePath = join ( flags [ 'output-dir' ] , flags [ 'file-name' ] ) ;
163172 writeFileSync ( filePath , JSON . stringify ( agentSpec , null , 4 ) ) ;
164173
165174 this . spinner . stop ( ) ;
0 commit comments