Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/commands/agent/generate/authoring-bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { AgentJobSpec, ScriptAgent } from '@salesforce/agents';
import YAML from 'yaml';
import { input as inquirerInput } from '@inquirer/prompts';
import { theme } from '../../../inquirer-theme.js';
import { FlaggablePrompt, promptForFlag, promptForYamlFile } from '../../../flags.js';
import { FlaggablePrompt, promptForFlag, promptForSpecYaml } from '../../../flags.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-agent', 'agent.generate.authoring-bundle');
Expand Down Expand Up @@ -105,7 +105,7 @@ export default class AgentGenerateAuthoringBundle extends SfCommand<AgentGenerat
const { 'output-dir': outputDir } = flags;

// If we don't have a spec yet, prompt for it
const spec = flags.spec ?? (await promptForYamlFile(AgentGenerateAuthoringBundle.FLAGGABLE_PROMPTS['spec']));
const spec = flags.spec ?? (await promptForSpecYaml(AgentGenerateAuthoringBundle.FLAGGABLE_PROMPTS['spec']));

// If we don't have a name yet, prompt for it
const name = flags['name'] ?? (await promptForFlag(AgentGenerateAuthoringBundle.FLAGGABLE_PROMPTS['name']));
Expand Down Expand Up @@ -135,9 +135,10 @@ export default class AgentGenerateAuthoringBundle extends SfCommand<AgentGenerat
const metaXmlPath = join(targetOutputDir, `${bundleApiName}.bundle-meta.xml`);

// Write Agent file
const specContents = YAML.parse(readFileSync(spec, 'utf8')) as AgentJobSpec;
await ScriptAgent.createAuthoringBundle({
agentSpec: { ...specContents, ...{ name, developerName: bundleApiName } },
agentSpec: spec
? { ...(YAML.parse(readFileSync(spec, 'utf8')) as AgentJobSpec), ...{ name, developerName: bundleApiName } }
: undefined,
project: this.project!,
bundleApiName,
});
Expand Down
19 changes: 19 additions & 0 deletions src/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,25 @@ export const promptForFileByExtensions = async (
export const promptForYamlFile = async (flagDef: FlaggablePrompt): Promise<string> =>
promptForFileByExtensions(flagDef, ['.yml', '.yaml']);

export const promptForSpecYaml = async (flagDef: FlaggablePrompt): Promise<string | undefined> => {
const hiddenDirs = await getHiddenDirs();
const dirsToTraverse = [process.cwd()];
const files = traverseForFiles(dirsToTraverse, ['AgentSpec.yml', 'AgentSpec.yaml'], ['node_modules', ...hiddenDirs]);
return autocomplete({
message: flagDef.promptMessage ?? flagDef.message.replace(/\.$/, ''),
// eslint-disable-next-line @typescript-eslint/require-await
source: async (input) => {
const arr = [
...files.map((o) => ({ name: relative(process.cwd(), o), value: o })),
{ name: 'Default Agent Spec', value: undefined },
];

if (!input) return arr;
return arr.filter((o) => o.name.includes(input));
},
});
};

export const promptForFlag = async (flagDef: FlaggablePrompt): Promise<string> => {
const message = flagDef.promptMessage ?? flagDef.message.replace(/\.$/, '');
if (flagDef.options) {
Expand Down
Loading