Skip to content

Commit

Permalink
fix: agent.create WIP, fix jobSpec agent spec key
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Dec 4, 2024
1 parent 0e65c4c commit cd1944c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
32 changes: 18 additions & 14 deletions src/commands/agent/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import * as fs from 'node:fs';
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';
import { Duration, sleep } from '@salesforce/kit';
import { MultiStageOutput } from '@oclif/multi-stage-output';
import { colorize } from '@oclif/core/ux';
import { Agent, AgentCreateConfig } from '@salesforce/agents';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-agent', 'agent.create');
Expand All @@ -27,6 +28,7 @@ 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 requiresProject = true;
public static state = 'beta';

public static readonly flags = {
Expand Down Expand Up @@ -60,31 +62,33 @@ export default class AgentCreate extends SfCommand<AgentCreateResult> {
});

mso.goto(jsonParsingStage);
await sleep(Duration.milliseconds(200));
const agentConfig = {
...(JSON.parse(fs.readFileSync(flags['job-spec'], 'utf8')) as AgentCreateConfig),
name: flags.name,
};

mso.goto('Generating GenAiPlanner metadata');
await sleep(Duration.milliseconds(200));

// make agent.create emit events so we can update MSO?
mso.goto('Creating agent in org');

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

// To simulate time spent on the server generating the spec.
await sleep(Duration.seconds(5));
const agent = new Agent(flags['target-org'].getConnection(flags['api-version']), this.project!);
const created = await agent.create(agentConfig);

mso.goto('Retrieving agent metadata');
await sleep(Duration.seconds(3));
// await sleep(Duration.seconds(3));

mso.stop();

this.log(
colorize(
'green',
`Successfully created ${flags.name} in ${flags['target-org'].getUsername() ?? 'the target org'}.`
)
created.isSuccess
? colorize(
'green',
`Successfully created ${flags.name} in ${flags['target-org'].getUsername() ?? 'the target org'}.`
)
: colorize('red', `failed to create agent ${flags.name}: ${created.errorMessage ?? ''}`)
);
this.log(`Use ${colorize('dim', `sf org open agent --name ${flags.name}`)} to view the agent in the browser.`);

return { isSuccess: true };
return { isSuccess: created.isSuccess };
}
}
8 changes: 6 additions & 2 deletions src/commands/agent/generate/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import ansis from 'ansis';
import select from '@inquirer/select';
import inquirerInput from '@inquirer/input';
import figures from '@inquirer/figures';
import { Agent, SfAgent } from '@salesforce/agents';
import { Agent, AgentCreateConfig, SfAgent } from '@salesforce/agents';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-agent', 'agent.generate.spec');
Expand Down Expand Up @@ -169,7 +169,11 @@ export default class AgentCreateSpec extends SfCommand<AgentCreateSpecResult> {
const filePath = join(flags['output-dir'], flags['file-name']);
writeFileSync(
filePath,
JSON.stringify({ type, role, companyName, companyDescription, companyWebsite, JobSpec: agentSpec }, null, 4)
JSON.stringify(
{ type, role, companyName, companyDescription, companyWebsite, jobSpec: agentSpec } as AgentCreateConfig,
null,
4
)
);

this.spinner.stop();
Expand Down

0 comments on commit cd1944c

Please sign in to comment.