-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from salesforcecli/sh/agent-gen-template
W-17753069 - feat: add agent generate template command
- Loading branch information
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# summary | ||
|
||
Generate an agent template for packaging. | ||
|
||
# description | ||
|
||
Generate agent template metadata to for packaging your agent. | ||
|
||
# flags.agent-api-name.summary | ||
|
||
API name of an existing Bot. | ||
|
||
# flags.output-dir.summary | ||
|
||
Directory to write the agent template. | ||
|
||
# examples | ||
|
||
- Generate an agent template from a Bot API name in your default package dir: | ||
|
||
<%= config.bin %> <%= command.id %> --agent-api-name My_Packaged_Agent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$ref": "#/definitions/AgentGenerateTemplateResult", | ||
"definitions": { | ||
"AgentGenerateTemplateResult": { | ||
"type": "object", | ||
"properties": { | ||
"path": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": ["path"], | ||
"additionalProperties": false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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 { dirname, join, resolve } from 'node:path'; | ||
import { mkdirSync, writeFileSync } from 'node:fs'; | ||
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.generate.template'); | ||
|
||
export type AgentGenerateTemplateResult = { | ||
path: string; | ||
}; | ||
|
||
export default class AgentGenerateTemplate extends SfCommand<AgentGenerateTemplateResult> { | ||
public static readonly summary = messages.getMessage('summary'); | ||
public static readonly description = messages.getMessage('description'); | ||
public static readonly examples = messages.getMessages('examples'); | ||
public static state = 'beta'; | ||
public static readonly requiresProject = true; | ||
|
||
public static readonly flags = { | ||
'target-org': Flags.requiredOrg(), | ||
'api-version': Flags.orgApiVersion(), | ||
'agent-api-name': Flags.string({ | ||
summary: messages.getMessage('flags.agent-api-name.summary'), | ||
required: true, | ||
}), | ||
'output-dir': Flags.directory({ | ||
char: 'd', | ||
exists: true, | ||
summary: messages.getMessage('flags.output-dir.summary'), | ||
}), | ||
}; | ||
|
||
public async run(): Promise<AgentGenerateTemplateResult> { | ||
const { flags } = await this.parse(AgentGenerateTemplate); | ||
|
||
// TODO: look for a Bot with the agent API name | ||
const botName = flags['agent-api-name']; | ||
const outputDir = flags['output-dir'] ? resolve(flags['output-dir']) : this.project?.getDefaultPackage().fullPath; | ||
|
||
const agentTemplateFilePath = join(outputDir as string, 'agentTemplates', `${botName}.agentTemplate-meta.xml`); | ||
mkdirSync(dirname(agentTemplateFilePath), { recursive: true }); | ||
|
||
writeFileSync(agentTemplateFilePath, xmlContent); | ||
|
||
this.log(`\nSaved agent template: ${agentTemplateFilePath}`); | ||
|
||
return { path: agentTemplateFilePath }; | ||
} | ||
} | ||
|
||
const xmlContent = `<?xml version="1.0" encoding="UTF-8"?> | ||
<AgentTemplate xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
</AgentTemplate> | ||
`; |