Skip to content

Commit 642e0df

Browse files
Merge pull request #296 from salesforcecli/wr/refactor
Wr/refactor @W-20812411@
2 parents f910243 + 24fb2a8 commit 642e0df

19 files changed

Lines changed: 322 additions & 564 deletions

File tree

README.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,6 @@ USAGE
513513
[--authoring-bundle <value>] [-d <value>] [-x] [--use-live-actions]
514514
515515
FLAGS
516-
-c, --client-app=<value> Name of the linked client app to use for the connection to the published and active
517-
agent.
518516
-d, --output-dir=<value> Directory where conversation transcripts are saved.
519517
-n, --api-name=<value> API name of the published and active agent you want to interact with.
520518
-o, --target-org=<value> (required) Username or alias of the target org. Not required if the `target-org`
@@ -560,14 +558,6 @@ DESCRIPTION
560558
the files are saved to the "./temp/agent-preview" directory. Specify a new default directory with the --output-dir
561559
flag.
562560
563-
NOTE: You can also use this command to connect to a published and active agent, which are labeled "(Published)" if you
564-
let this command provide the list of agents to preview. That use case, however, requires additional security and
565-
configuration in both your org and your DX project. The examples in this help are for previewing an agent from its
566-
Agent Script file in your DX project and require only simple authorization of your org, such as with the "org login
567-
web" command. The --client-app and --api-name flags are used only for previewing published and active agents, they
568-
don't apply to Agent Script agents. See "Connect to a Published Agent" in the "Agentforce Developer Guide" for
569-
complete documentation: https://developer.salesforce.com/docs/einstein/genai/guide/agent-dx-preview.html.
570-
571561
EXAMPLES
572562
Preview an agent in simulated mode by choosing from a list of authoring bundles provided by the command; use the org
573563
with alias "my-dev-org":

command-snapshot.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,12 @@
7979
"alias": [],
8080
"command": "agent:preview",
8181
"flagAliases": [],
82-
"flagChars": ["c", "d", "n", "o", "x"],
82+
"flagChars": ["d", "n", "o", "x"],
8383
"flags": [
8484
"apex-debug",
8585
"api-name",
8686
"api-version",
8787
"authoring-bundle",
88-
"client-app",
8988
"flags-dir",
9089
"output-dir",
9190
"target-org",

messages/agent.preview.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ The interface is simple: in the "Start typing..." prompt, enter a statement, que
1717

1818
When the session concludes, the command asks if you want to save the API responses and chat transcripts. By default, the files are saved to the "./temp/agent-preview" directory. Specify a new default directory with the --output-dir flag.
1919

20-
NOTE: You can also use this command to connect to a published and active agent, which are labeled "(Published)" if you let this command provide the list of agents to preview. That use case, however, requires additional security and configuration in both your org and your DX project. The examples in this help are for previewing an agent from its Agent Script file in your DX project and require only simple authorization of your org, such as with the "org login web" command. The --client-app and --api-name flags are used only for previewing published and active agents, they don't apply to Agent Script agents. See "Connect to a Published Agent" in the "Agentforce Developer Guide" for complete documentation: https://developer.salesforce.com/docs/einstein/genai/guide/agent-dx-preview.html.
21-
2220
# flags.api-name.summary
2321

2422
API name of the published and active agent you want to interact with.
@@ -27,10 +25,6 @@ API name of the published and active agent you want to interact with.
2725

2826
API name of the authoring bundle metadata component that contains the agent's Agent Script file.
2927

30-
# flags.client-app.summary
31-
32-
Name of the linked client app to use for the connection to the published and active agent.
33-
3428
# flags.output-dir.summary
3529

3630
Directory where conversation transcripts are saved.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"@inquirer/prompts": "^7.10.1",
1010
"@oclif/core": "^4",
1111
"@oclif/multi-stage-output": "^0.8.29",
12-
"@salesforce/agents": "^0.20.0",
12+
"@salesforce/agents": "^0.21.1",
1313
"@salesforce/core": "^8.24.3",
1414
"@salesforce/kit": "^3.2.3",
1515
"@salesforce/sf-plugins-core": "^12.2.6",

src/agentActivation.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { Connection, Messages, Org, SfError } from '@salesforce/core';
18-
import { Agent, type BotMetadata } from '@salesforce/agents';
17+
import { Messages, Org, SfError, SfProject } from '@salesforce/core';
18+
import { Agent, type BotMetadata, ProductionAgent } from '@salesforce/agents';
1919
import { select } from '@inquirer/prompts';
2020

2121
type Choice<Value> = {
@@ -67,16 +67,15 @@ export const getAgentChoices = (agents: BotMetadata[], status: 'Active' | 'Inact
6767
});
6868

6969
export const getAgentForActivation = async (config: {
70-
conn: Connection;
7170
targetOrg: Org;
7271
status: 'Active' | 'Inactive';
7372
apiNameFlag?: string;
74-
}): Promise<Agent> => {
75-
const { conn, targetOrg, status, apiNameFlag } = config;
73+
}): Promise<ProductionAgent> => {
74+
const { targetOrg, status, apiNameFlag } = config;
7675

7776
let agentsInOrg: BotMetadata[] = [];
7877
try {
79-
agentsInOrg = await Agent.listRemote(conn);
78+
agentsInOrg = await Agent.listRemote(targetOrg.getConnection());
8079
} catch (error) {
8180
throw SfError.create({
8281
message: 'Error listing agents in org',
@@ -105,5 +104,9 @@ export const getAgentForActivation = async (config: {
105104
selectedAgent = agentsInOrg.find((agent) => agent.DeveloperName === agentChoice.DeveloperName);
106105
}
107106

108-
return new Agent({ connection: conn, nameOrId: selectedAgent!.Id });
107+
return Agent.init({
108+
connection: targetOrg.getConnection(),
109+
apiNameOrId: selectedAgent!.Id,
110+
project: SfProject.getInstance(),
111+
});
109112
};

src/commands/agent/activate.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,12 @@ export default class AgentActivate extends SfCommand<void> {
3939

4040
const apiNameFlag = flags['api-name'];
4141
const targetOrg = flags['target-org'];
42-
const conn = targetOrg.getConnection(flags['api-version']);
4342

4443
if (!apiNameFlag && this.jsonEnabled()) {
4544
throw messages.createError('error.missingRequiredFlags', ['api-name']);
4645
}
4746

48-
const agent = await getAgentForActivation({ conn, targetOrg, status: 'Active', apiNameFlag });
47+
const agent = await getAgentForActivation({ targetOrg, status: 'Active', apiNameFlag });
4948
await agent.activate();
5049
const agentName = (await agent.getBotMetadata()).DeveloperName;
5150

src/commands/agent/deactivate.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,12 @@ export default class AgentDeactivate extends SfCommand<void> {
3939

4040
const apiNameFlag = flags['api-name'];
4141
const targetOrg = flags['target-org'];
42-
const conn = targetOrg.getConnection(flags['api-version']);
4342

4443
if (!apiNameFlag && this.jsonEnabled()) {
4544
throw messages.createError('error.missingRequiredFlags', ['api-name']);
4645
}
4746

48-
const agent = await getAgentForActivation({ conn, targetOrg, status: 'Inactive', apiNameFlag });
47+
const agent = await getAgentForActivation({ targetOrg, status: 'Inactive', apiNameFlag });
4948
await agent.deactivate();
5049
const agentName = (await agent.getBotMetadata()).DeveloperName;
5150

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { join, resolve } from 'node:path';
1818
import { readFileSync, existsSync } from 'node:fs';
1919
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
2020
import { generateApiName, Messages, SfError } from '@salesforce/core';
21-
import { Agent, AgentJobSpec } from '@salesforce/agents';
21+
import { AgentJobSpec, ScriptAgent } from '@salesforce/agents';
2222
import YAML from 'yaml';
2323
import { input as inquirerInput } from '@inquirer/prompts';
2424
import { theme } from '../../../inquirer-theme.js';
@@ -102,7 +102,7 @@ export default class AgentGenerateAuthoringBundle extends SfCommand<AgentGenerat
102102

103103
public async run(): Promise<AgentGenerateAuthoringBundleResult> {
104104
const { flags } = await this.parse(AgentGenerateAuthoringBundle);
105-
const { 'output-dir': outputDir, 'target-org': targetOrg } = flags;
105+
const { 'output-dir': outputDir } = flags;
106106

107107
// If we don't have a spec yet, prompt for it
108108
const spec = flags.spec ?? (await promptForYamlFile(AgentGenerateAuthoringBundle.FLAGGABLE_PROMPTS['spec']));
@@ -135,10 +135,8 @@ export default class AgentGenerateAuthoringBundle extends SfCommand<AgentGenerat
135135
const metaXmlPath = join(targetOutputDir, `${bundleApiName}.bundle-meta.xml`);
136136

137137
// Write Agent file
138-
const conn = targetOrg.getConnection(flags['api-version']);
139138
const specContents = YAML.parse(readFileSync(spec, 'utf8')) as AgentJobSpec;
140-
await Agent.createAuthoringBundle({
141-
connection: conn,
139+
await ScriptAgent.createAuthoringBundle({
142140
agentSpec: { ...specContents, ...{ name, developerName: bundleApiName } },
143141
project: this.project!,
144142
bundleApiName,

0 commit comments

Comments
 (0)