Skip to content

Commit 2a3ff52

Browse files
chore: move to using agent methods
1 parent 8785482 commit 2a3ff52

File tree

3 files changed

+22
-53
lines changed

3 files changed

+22
-53
lines changed

src/commands/agent/publish/authoring-bundle.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77
import { EOL } from 'node:os';
8+
import { join } from 'node:path';
9+
import { readFileSync } from 'node:fs';
810
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
911
import { Messages, Lifecycle, SfError } from '@salesforce/core';
10-
import { Agent } from '@salesforce/agents';
12+
import { Agent, findAuthoringBundle } from '@salesforce/agents';
1113
import { RetrieveResult, RequestStatus } from '@salesforce/source-deploy-retrieve';
1214
import { ensureArray } from '@salesforce/kit';
13-
import { findAndReadAfScript } from '../../../utils/afscriptFinder.js';
1415

1516
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
1617
const messages = Messages.loadMessages('@salesforce/plugin-agent', 'agent.publish.authoring-bundle');
@@ -39,9 +40,11 @@ export default class AgentPublishAuthoringBundle extends SfCommand<AgentPublishA
3940

4041
public async run(): Promise<AgentPublishAuthoringBundleResult> {
4142
const { flags } = await this.parse(AgentPublishAuthoringBundle);
42-
const afScript = findAndReadAfScript(this.project!.getPath(), flags['api-name']);
43+
// todo: this eslint warning can be removed once published
44+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
45+
const authoringBundleDir = findAuthoringBundle(this.project!.getPath(), flags['api-name']);
4346

44-
if (!afScript) {
47+
if (!authoringBundleDir) {
4548
throw new SfError(messages.getMessage('error.afscriptNotFound', [flags['api-name']]), 'AfScriptNotFoundError', [
4649
messages.getMessage('error.afscriptNotFoundAction'),
4750
]);
@@ -66,7 +69,10 @@ export default class AgentPublishAuthoringBundle extends SfCommand<AgentPublishA
6669

6770
// First compile the AF script to get the Agent JSON
6871
this.log('Compiling authoring bundle...');
69-
const agentJson = await Agent.compileAfScript(conn, afScript);
72+
const agentJson = await Agent.compileAfScript(
73+
conn,
74+
readFileSync(join(authoringBundleDir, `${flags['api-name']}.afscript`), 'utf8')
75+
);
7076

7177
// Then publish the Agent JSON to create the agent
7278
this.log('Publishing agent...');

src/commands/agent/validate/authoring-bundle.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
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+
import { readFileSync } from 'node:fs';
8+
import { join } from 'node:path';
79
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
810
import { Messages, SfError } from '@salesforce/core';
9-
import { Agent } from '@salesforce/agents';
10-
import { findAndReadAfScript } from '../../../utils/afscriptFinder.js';
11+
import { Agent, findAuthoringBundle } from '@salesforce/agents';
1112

1213
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
1314
const messages = Messages.loadMessages('@salesforce/plugin-agent', 'agent.validate.authoring-bundle');
@@ -34,9 +35,10 @@ export default class AgentValidateAuthoringBundle extends SfCommand<AgentValidat
3435

3536
public async run(): Promise<AgentValidateAuthoringBundleResult> {
3637
const { flags } = await this.parse(AgentValidateAuthoringBundle);
37-
const afScript = findAndReadAfScript(this.project!.getPath(), flags['api-name']);
38-
39-
if (!afScript) {
38+
// todo: this eslint warning can be removed once published
39+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
40+
const authoringBundleDir = findAuthoringBundle(this.project!.getPath(), flags['api-name']);
41+
if (!authoringBundleDir) {
4042
throw new SfError(messages.getMessage('error.afscriptNotFound', [flags['api-name']]), 'AfScriptNotFoundError', [
4143
messages.getMessage('error.afscriptNotFoundAction'),
4244
]);
@@ -46,7 +48,10 @@ export default class AgentValidateAuthoringBundle extends SfCommand<AgentValidat
4648
const targetOrg = flags['target-org'];
4749
const conn = targetOrg.getConnection(flags['api-version']);
4850
// Call Agent.compileAfScript() API
49-
await Agent.compileAfScript(conn, afScript);
51+
await Agent.compileAfScript(
52+
conn,
53+
readFileSync(join(authoringBundleDir, `${flags['api-name']}.afscript`), 'utf8')
54+
);
5055
this.log('Successfully compiled');
5156
return {
5257
success: true,

src/utils/afscriptFinder.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)