Skip to content

Commit 5546f2a

Browse files
committed
fix: some mocking around agent creation
1 parent bdb45c2 commit 5546f2a

File tree

5 files changed

+79
-25
lines changed

5 files changed

+79
-25
lines changed

command-snapshot.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,27 @@
33
"alias": [],
44
"command": "agent:create",
55
"flagAliases": [],
6-
"flagChars": ["f", "o", "p"],
7-
"flags": ["api-version", "flags-dir", "json", "planner", "spec", "target-org"],
6+
"flagChars": ["f", "o"],
7+
"flags": ["api-version", "flags-dir", "json", "spec", "target-org"],
88
"plugin": "@salesforce/plugin-agent"
99
},
1010
{
1111
"alias": [],
1212
"command": "agent:create:spec",
1313
"flagAliases": [],
14-
"flagChars": ["d", "o"],
14+
"flagChars": ["d", "n", "o", "t"],
1515
"flags": [
16-
"agent-type",
1716
"api-version",
1817
"company-description",
1918
"company-name",
2019
"company-website",
2120
"flags-dir",
2221
"json",
22+
"name",
2323
"output-dir",
2424
"role",
25-
"target-org"
25+
"target-org",
26+
"type"
2627
],
2728
"plugin": "@salesforce/plugin-agent"
2829
},

messages/agent.create.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,16 @@ Create an Agent from an agent spec.
66

77
Create an Agent from an agent spec. Agent metadata is created in the target org and retrieved to the local project.
88

9-
# flags.planner.summary
10-
11-
The agent planner API name.
12-
139
# flags.spec.summary
1410

1511
The path to an agent spec file.
1612

1713
# flags.spec.description
1814

19-
The agent spec file defines job descriptions for the agent and can be created using the `sf agent create spec` command.
15+
The agent spec file defines job titles and descriptions for the agent and can be created using the `sf agent create spec` command.
2016

2117
# examples
2218

2319
- Create an Agent:
2420

25-
<%= config.bin %> <%= command.id %> --planner MyAgentPlanner --spec ./agent-spec.json
21+
<%= config.bin %> <%= command.id %> --spec ./agent-spec.json

messages/agent.create.spec.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ Create an Agent spec.
44

55
# description
66

7-
Create an Agent spec, which is a list of job descriptions for the agent.
7+
Create an Agent spec, which is a list of job titles and descriptions that the agent performs.
88

9-
# flags.agent-type.summary
9+
# flags.name.summary
10+
11+
The name of the agent to create.
12+
13+
# flags.type.summary
1014

1115
The type of agent to create.
1216

@@ -34,4 +38,4 @@ The location within the project where the agent spec will be written.
3438

3539
- Create an Agent spec in the default location:
3640

37-
<%= config.bin %> <%= command.id %> --agent-type customer-facing --role Support --company-name "Coral Cloud" --company-description "A meaningful description"
41+
<%= config.bin %> <%= command.id %> --type customer_facing --role Support --company-name "Coral Cloud" --company-description "A meaningful description"

src/commands/agent/create.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
99
import { Messages } from '@salesforce/core';
10+
import { Duration, sleep } from '@salesforce/kit';
1011

1112
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
1213
const messages = Messages.loadMessages('@salesforce/plugin-agent', 'agent.create');
@@ -16,7 +17,9 @@ export type AgentCreateResult = {
1617
errorMessage?: string;
1718
};
1819

19-
// This is a POST to /services/data/{api-version}/connect/attach-agent-topics
20+
// There is no API for this yet. It's being planned/built by the Agent Creator team.
21+
// However, we could possibly use:
22+
// /services/data/{api-version}/connect/attach-agent-topics
2023

2124
export default class AgentCreate extends SfCommand<AgentCreateResult> {
2225
public static readonly summary = messages.getMessage('summary');
@@ -32,11 +35,6 @@ export default class AgentCreate extends SfCommand<AgentCreateResult> {
3235
summary: messages.getMessage('flags.spec.summary'),
3336
description: messages.getMessage('flags.spec.description'),
3437
}),
35-
planner: Flags.string({
36-
char: 'p',
37-
required: true,
38-
summary: messages.getMessage('flags.spec.summary'),
39-
}),
4038
};
4139

4240
public async run(): Promise<AgentCreateResult> {
@@ -46,6 +44,9 @@ export default class AgentCreate extends SfCommand<AgentCreateResult> {
4644

4745
// POST to /services/data/{api-version}/connect/attach-agent-topics
4846

47+
// To simulate time spent on the server generating the spec.
48+
await sleep(Duration.seconds(5));
49+
4950
return { isSuccess: true };
5051
}
5152
}

src/commands/agent/create/spec.ts

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,41 @@
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';
89
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
910
import { Messages } from '@salesforce/core';
11+
import { Duration, sleep } from '@salesforce/kit';
1012

1113
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
1214
const messages = Messages.loadMessages('@salesforce/plugin-agent', 'agent.create.spec');
1315

1416
export 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+
2242
export 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

Comments
 (0)