Skip to content

Commit

Permalink
fix: add agent create stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
shetzel committed Oct 30, 2024
1 parent 5016ad2 commit 223704b
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 0 deletions.
27 changes: 27 additions & 0 deletions command-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
[
{
"alias": [],
"command": "agent:create",
"flagAliases": [],
"flagChars": ["f", "o", "p"],
"flags": ["api-version", "flags-dir", "json", "planner", "spec", "target-org"],
"plugin": "@salesforce/plugin-agent"
},
{
"alias": [],
"command": "agent:create:spec",
"flagAliases": [],
"flagChars": ["d", "o"],
"flags": [
"agent-type",
"api-version",
"company-description",
"company-name",
"company-website",
"flags-dir",
"json",
"output-dir",
"role",
"target-org"
],
"plugin": "@salesforce/plugin-agent"
},
{
"alias": [],
"command": "agent:run:test",
Expand Down
25 changes: 25 additions & 0 deletions messages/agent.create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# summary

Create an Agent from an agent spec.

# description

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

# flags.planner.summary

The agent planner API name.

# flags.spec.summary

The path to an agent spec file.

# flags.spec.description

The agent spec file defines job descriptions for the agent and can be created using the `sf agent create spec` command.

# examples

- Create an Agent:

<%= config.bin %> <%= command.id %> --planner MyAgentPlanner --spec ./agent-spec.json
37 changes: 37 additions & 0 deletions messages/agent.create.spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# summary

Create an Agent spec.

# description

Create an Agent spec, which is a list of job descriptions for the agent.

# flags.agent-type.summary

The type of agent to create.

# flags.role.summary

The role of the agent.

# flags.company-name.summary

The name of the company.

# flags.company-description.summary

The description of the company, containing details to be used when generating agent job descriptions.

# flags.company-website.summary

The website URL for the company.

# flags.output-dir.summary

The location within the project where the agent spec will be written.

# examples

- Create an Agent spec in the default location:

<%= config.bin %> <%= command.id %> --agent-type customer-facing --role Support --company-name "Coral Cloud" --company-description "A meaningful description"
51 changes: 51 additions & 0 deletions src/commands/agent/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2024, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';

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

export type AgentCreateResult = {
isSuccess: boolean;
errorMessage?: string;
};

// This is a POST to /services/data/{api-version}/connect/attach-agent-topics

export default class AgentCreate extends SfCommand<AgentCreateResult> {
public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessages('examples');

public static readonly flags = {
'target-org': Flags.requiredOrg(),
'api-version': Flags.orgApiVersion(),
spec: Flags.file({
char: 'f',
required: true,
summary: messages.getMessage('flags.spec.summary'),
description: messages.getMessage('flags.spec.description'),
}),
planner: Flags.string({
char: 'p',
required: true,
summary: messages.getMessage('flags.spec.summary'),
}),
};

public async run(): Promise<AgentCreateResult> {
const { flags } = await this.parse(AgentCreate);

this.log(`Creating agent from spec: ${flags.spec}`);

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

return { isSuccess: true };
}
}
71 changes: 71 additions & 0 deletions src/commands/agent/create/spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2024, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';

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

export type AgentCreateSpecResult = {
isSuccess: boolean;
errorMessage?: string;
jobSpec?: string;
};

// This is a GET of '/services/data/v62.0/connect/agent-job-spec?agentType...

export default class AgentCreateSpec extends SfCommand<AgentCreateSpecResult> {
public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessages('examples');

public static readonly flags = {
'target-org': Flags.requiredOrg(),
'api-version': Flags.orgApiVersion(),
'agent-type': Flags.string({
required: true,
summary: messages.getMessage('flags.agent-type.summary'),
options: ['customer_facing', 'employee_facing'],
}),
role: Flags.string({
required: true,
summary: messages.getMessage('flags.role.summary'),
}),
'company-name': Flags.string({
required: true,
summary: messages.getMessage('flags.company-name.summary'),
}),
'company-description': Flags.string({
required: true,
summary: messages.getMessage('flags.company-description.summary'),
}),
'company-website': Flags.string({
summary: messages.getMessage('flags.company-website.summary'),
}),
'output-dir': Flags.directory({
char: 'd',
exists: true,
summary: messages.getMessage('flags.output-dir.summary'),
default: 'config',
}),
};

public async run(): Promise<AgentCreateSpecResult> {
const { flags } = await this.parse(AgentCreateSpec);

this.log(`Creating agent spec in: ${flags['output-dir']}`);

// GET to /services/data/{api-version}/connect/agent-job-spec

// Write a file with the returned job specs

return {
isSuccess: true,
};
}
}

0 comments on commit 223704b

Please sign in to comment.