Skip to content

Commit 1404caf

Browse files
authored
Merge pull request #15 from salesforcecli/sh/use-agents-lib
fix: use agents library
2 parents 4f9dd7c + d66ff89 commit 1404caf

File tree

1 file changed

+15
-35
lines changed

1 file changed

+15
-35
lines changed

src/commands/agent/generate/spec.ts

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
import { join } from 'node:path';
88
import { writeFileSync } from 'node:fs';
99
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
10-
import { Messages } from '@salesforce/core';
11-
import { Duration, sleep } from '@salesforce/kit';
10+
import { Messages, SfProject } from '@salesforce/core';
1211
import { Interfaces } from '@oclif/core';
1312
import ansis from 'ansis';
1413
import select from '@inquirer/select';
1514
import inquirerInput from '@inquirer/input';
1615
import figures from '@inquirer/figures';
16+
import { Agent, SfAgent } from '@salesforce/agents';
1717

1818
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
1919
const messages = Messages.loadMessages('@salesforce/plugin-agent', 'agent.create.spec');
@@ -26,24 +26,6 @@ export type AgentCreateSpecResult = {
2626
// all the parameters used to generate the spec and the spec contents
2727
};
2828

29-
// This is a GET of '/services/data/v62.0/connect/agent-job-spec?agentType...
30-
31-
// Mocked job spec, which is a list of AI generated jobs to be done
32-
const jobSpecContent = [
33-
{
34-
jobTitle: 'My first job title',
35-
jobDescription: 'This is what the first job does',
36-
},
37-
{
38-
jobTitle: 'My second job title',
39-
jobDescription: 'This is what the second job does',
40-
},
41-
{
42-
jobTitle: 'My third job title',
43-
jobDescription: 'This is what the third job does',
44-
},
45-
];
46-
4729
type FlaggablePrompt = {
4830
message: string;
4931
options?: readonly string[] | string[];
@@ -130,6 +112,7 @@ export default class AgentCreateSpec extends SfCommand<AgentCreateSpecResult> {
130112
public static readonly summary = messages.getMessage('summary');
131113
public static readonly description = messages.getMessage('description');
132114
public static readonly examples = messages.getMessages('examples');
115+
public static readonly requiresProject = true;
133116

134117
public static readonly flags = {
135118
'target-org': Flags.requiredOrg(),
@@ -146,10 +129,6 @@ export default class AgentCreateSpec extends SfCommand<AgentCreateSpecResult> {
146129
public async run(): Promise<AgentCreateSpecResult> {
147130
const { flags } = await this.parse(AgentCreateSpec);
148131

149-
// We'll need to generate a GenAiPlanner using the name flag and deploy it
150-
// as part of this, at least for now. We won't have to do this with the
151-
// new API being created for us.
152-
153132
// throw error if --json is used and not all required flags are provided
154133
if (this.jsonEnabled()) {
155134
const missingFlags = Object.entries(FLAGGABLE_PROMPTS)
@@ -163,24 +142,25 @@ export default class AgentCreateSpec extends SfCommand<AgentCreateSpecResult> {
163142

164143
this.log();
165144
this.styledHeader('Agent Details');
166-
await this.getFlagOrPrompt(flags.name, FLAGGABLE_PROMPTS.name);
167-
await this.getFlagOrPrompt(flags.type, FLAGGABLE_PROMPTS.type);
168-
await this.getFlagOrPrompt(flags.role, FLAGGABLE_PROMPTS.role);
169-
await this.getFlagOrPrompt(flags['company-name'], FLAGGABLE_PROMPTS['company-name']);
170-
await this.getFlagOrPrompt(flags['company-description'], FLAGGABLE_PROMPTS['company-description']);
171-
await this.getFlagOrPrompt(flags['company-website'], FLAGGABLE_PROMPTS['company-website']);
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';
147+
const role = await this.getFlagOrPrompt(flags.role, FLAGGABLE_PROMPTS.role);
148+
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 companyWebsite = await this.getFlagOrPrompt(flags['company-website'], FLAGGABLE_PROMPTS['company-website']);
172151

173152
this.log();
174153
this.spinner.start('Creating agent spec');
175154

176-
// To simulate time spent on the server generating the spec.
177-
await sleep(Duration.seconds(2));
178-
179-
// GET to /services/data/{api-version}/connect/agent-job-spec
155+
const connection = flags['target-org'].getConnection(flags['api-version']);
156+
const agent = new Agent(connection, this.project as SfProject) as SfAgent;
157+
const agentSpec = await agent.createSpec({
158+
name, type, role, companyName, companyDescription, companyWebsite
159+
});
180160

181161
// Write a file with the returned job specs
182162
const filePath = join(flags['output-dir'], 'agentSpec.json');
183-
writeFileSync(filePath, JSON.stringify(jobSpecContent, null, 4));
163+
writeFileSync(filePath, JSON.stringify(agentSpec, null, 4));
184164

185165
this.spinner.stop();
186166

0 commit comments

Comments
 (0)