44 * Licensed under the BSD 3-Clause license.
55 * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66 */
7-
7+ import { join } from 'node:path' ;
8+ import { writeFileSync } from 'node:fs' ;
89import { SfCommand , Flags } from '@salesforce/sf-plugins-core' ;
910import { Messages } from '@salesforce/core' ;
11+ import { Duration , sleep } from '@salesforce/kit' ;
1012
1113Messages . importMessagesDirectoryFromMetaUrl ( import . meta. url ) ;
1214const messages = Messages . loadMessages ( '@salesforce/plugin-agent' , 'agent.create.spec' ) ;
1315
1416export type AgentCreateSpecResult = {
1517 isSuccess : boolean ;
1618 errorMessage ?: string ;
17- jobSpec ?: string ;
19+ jobSpec ?: string ; // the location of the job spec file
20+ // We probably need more than this in the returned JSON like
21+ // all the parameters used to generate the spec and the spec contents
1822} ;
1923
2024// This is a GET of '/services/data/v62.0/connect/agent-job-spec?agentType...
2125
26+ // Mocked job spec, which is a list of AI generated jobs to be done
27+ const jobSpecContent = [
28+ {
29+ jobTitle : 'My first job title' ,
30+ jobDescription : 'This is what the first job does' ,
31+ } ,
32+ {
33+ jobTitle : 'My second job title' ,
34+ jobDescription : 'This is what the second job does' ,
35+ } ,
36+ {
37+ jobTitle : 'My third job title' ,
38+ jobDescription : 'This is what the third job does' ,
39+ } ,
40+ ] ;
41+
2242export default class AgentCreateSpec extends SfCommand < AgentCreateSpecResult > {
2343 public static readonly summary = messages . getMessage ( 'summary' ) ;
2444 public static readonly description = messages . getMessage ( 'description' ) ;
@@ -27,9 +47,15 @@ export default class AgentCreateSpec extends SfCommand<AgentCreateSpecResult> {
2747 public static readonly flags = {
2848 'target-org' : Flags . requiredOrg ( ) ,
2949 'api-version' : Flags . orgApiVersion ( ) ,
30- 'agent-type' : Flags . string ( {
50+ name : Flags . string ( {
51+ char : 'n' ,
3152 required : true ,
32- summary : messages . getMessage ( 'flags.agent-type.summary' ) ,
53+ summary : messages . getMessage ( 'flags.name.summary' ) ,
54+ } ) ,
55+ type : Flags . string ( {
56+ char : 't' ,
57+ required : true ,
58+ summary : messages . getMessage ( 'flags.type.summary' ) ,
3359 options : [ 'customer_facing' , 'employee_facing' ] ,
3460 } ) ,
3561 role : Flags . string ( {
@@ -58,14 +84,40 @@ export default class AgentCreateSpec extends SfCommand<AgentCreateSpecResult> {
5884 public async run ( ) : Promise < AgentCreateSpecResult > {
5985 const { flags } = await this . parse ( AgentCreateSpec ) ;
6086
61- this . log ( `Creating agent spec in: ${ flags [ 'output-dir' ] } ` ) ;
87+ // We'll need to generate a GenAiPlanner using the name flag and deploy it
88+ // as part of this, at least for now. We won't have to do this with the
89+ // new API being created for us.
90+
91+ this . log ( ) ;
92+ this . styledHeader ( 'Agent Details' ) ;
93+ this . log ( 'Name:' , flags . name ) ;
94+ this . log ( 'Type:' , flags . type ) ;
95+ this . log ( 'Role:' , flags . role ) ;
96+ this . log ( 'Company Name:' , flags [ 'company-name' ] ) ;
97+ this . log ( 'Company Description:' , flags [ 'company-description' ] ) ;
98+ if ( flags [ 'company-website' ] ) {
99+ this . log ( 'Company Website:' , flags [ 'company-website' ] ) ;
100+ }
101+
102+ this . log ( ) ;
103+ this . spinner . start ( 'Creating agent spec' ) ;
104+
105+ // To simulate time spent on the server generating the spec.
106+ await sleep ( Duration . seconds ( 2 ) ) ;
62107
63108 // GET to /services/data/{api-version}/connect/agent-job-spec
64109
65110 // Write a file with the returned job specs
111+ const filePath = join ( flags [ 'output-dir' ] , 'agentSpec.json' ) ;
112+ writeFileSync ( filePath , JSON . stringify ( jobSpecContent , null , 4 ) ) ;
113+
114+ this . spinner . stop ( ) ;
115+
116+ this . log ( `\nSaved agent spec: ${ filePath } ` ) ;
66117
67118 return {
68119 isSuccess : true ,
120+ jobSpec : filePath ,
69121 } ;
70122 }
71123}
0 commit comments