Skip to content

Commit c63acb7

Browse files
chore: move types to library
1 parent f4794fd commit c63acb7

File tree

2 files changed

+27
-67
lines changed

2 files changed

+27
-67
lines changed

src/commands/agent/preview.ts

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ import { AuthInfo, Connection, Lifecycle, Messages, SfError } from '@salesforce/
2222
import React from 'react';
2323
import { render } from 'ink';
2424
import { env } from '@salesforce/kit';
25-
import { AgentPreview as Preview, AgentSimulate, findAuthoringBundle } from '@salesforce/agents';
25+
import {
26+
AgentPreview as Preview,
27+
AgentSimulate,
28+
findAuthoringBundle,
29+
AgentSource,
30+
ScriptAgent,
31+
PublishedAgent,
32+
} from '@salesforce/agents';
2633
import { select, confirm, input } from '@inquirer/prompts';
2734
import { AgentPreviewReact } from '../../components/agent-preview-react.js';
2835

@@ -45,20 +52,6 @@ type Choice<Value> = {
4552
disabled?: boolean | string;
4653
};
4754

48-
enum AgentSource {
49-
PUBLISHED = 'published',
50-
SCRIPT = 'script',
51-
}
52-
53-
type ScriptAgent = { DeveloperName: string; source: AgentSource.SCRIPT; path: string };
54-
type PublishedAgent = {
55-
Id: string;
56-
DeveloperName: string;
57-
source: AgentSource.PUBLISHED;
58-
};
59-
60-
type AgentValue = ScriptAgent | PublishedAgent;
61-
6255
// https://developer.salesforce.com/docs/einstein/genai/guide/agent-api-get-started.html#prerequisites
6356
export const UNSUPPORTED_AGENTS = ['Copilot_for_Salesforce'];
6457

@@ -116,7 +109,7 @@ export default class AgentPreview extends SfCommand<AgentPreviewResult> {
116109
)
117110
).records;
118111

119-
let selectedAgent: AgentValue;
112+
let selectedAgent: ScriptAgent | PublishedAgent;
120113

121114
if (flags['authoring-bundle']) {
122115
// user specified --authoring-bundle, we'll find the script and use it
@@ -141,7 +134,7 @@ export default class AgentPreview extends SfCommand<AgentPreviewResult> {
141134
};
142135
if (!selectedAgent) throw new Error(`No valid Agents were found with the Api Name ${apiNameFlag}.`);
143136
} else {
144-
selectedAgent = await select({
137+
selectedAgent = await select<ScriptAgent | PublishedAgent>({
145138
message: 'Select an agent',
146139
choices: this.getAgentChoices(agentsInOrg),
147140
});
@@ -205,8 +198,8 @@ export default class AgentPreview extends SfCommand<AgentPreviewResult> {
205198
await instance.waitUntilExit();
206199
}
207200

208-
private getAgentChoices(agents: AgentData[]): Array<Choice<AgentValue>> {
209-
const choices: Array<Choice<AgentValue>> = [];
201+
private getAgentChoices(agents: AgentData[]): Array<Choice<ScriptAgent | PublishedAgent>> {
202+
const choices: Array<Choice<ScriptAgent | PublishedAgent>> = [];
210203

211204
// Add org agents
212205
for (const agent of agents) {

test/commands/agent/preview/index.test.ts

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
agentIsUnsupported,
2424
agentIsInactive,
2525
validateAgent,
26-
getAgentChoices,
2726
} from '../../../../src/commands/agent/preview.js';
2827

2928
// TODO - pull in error messages
@@ -140,55 +139,23 @@ describe('Agent Preview', () => {
140139
});
141140
});
142141

143-
describe('gets agent choices', () => {
144-
it('returns agent choices', () => {
145-
const agents: AgentData[] = [
146-
{
147-
Id: 'OXx1234567890',
148-
DeveloperName: 'some_agent',
149-
BotVersions: {
150-
records: [{ Status: 'Active' }],
151-
},
152-
},
153-
{
154-
Id: 'OXx1234567891',
155-
DeveloperName: UNSUPPORTED_AGENTS[0],
156-
BotVersions: {
157-
records: [{ Status: 'Active' }],
158-
},
159-
},
160-
{
161-
Id: 'OXx1234567892',
162-
DeveloperName: 'inactive_agent',
163-
BotVersions: {
164-
records: [{ Status: 'Inactive' }],
165-
},
166-
},
167-
];
168-
169-
const choices = getAgentChoices(agents);
170-
expect(choices).to.have.lengthOf(3);
142+
describe('agent source types', () => {
143+
it('should support script agent source type', () => {
144+
const scriptAgent = {
145+
DeveloperName: 'test-agent',
146+
source: 'script' as const,
147+
path: '/path/to/agent.agent',
148+
};
149+
expect(scriptAgent.source).to.equal('script');
150+
});
171151

172-
expect(choices[0].name).to.equal('some_agent');
173-
expect(choices[0].value).to.deep.equal({
152+
it('should support published agent source type', () => {
153+
const publishedAgent = {
174154
Id: 'OXx1234567890',
175-
DeveloperName: 'some_agent',
176-
});
177-
expect(choices[0].disabled).to.equal(false);
178-
179-
expect(choices[1].name).to.equal(UNSUPPORTED_AGENTS[0]);
180-
expect(choices[1].value).to.deep.equal({
181-
Id: 'OXx1234567891',
182-
DeveloperName: UNSUPPORTED_AGENTS[0],
183-
});
184-
expect(choices[1].disabled).to.equal('(Not Supported)');
185-
186-
expect(choices[2].name).to.equal('inactive_agent');
187-
expect(choices[2].value).to.deep.equal({
188-
Id: 'OXx1234567892',
189-
DeveloperName: 'inactive_agent',
190-
});
191-
expect(choices[2].disabled).to.equal('(Inactive)');
155+
DeveloperName: 'test-agent',
156+
source: 'published' as const,
157+
};
158+
expect(publishedAgent.source).to.equal('published');
192159
});
193160
});
194161
});

0 commit comments

Comments
 (0)