@@ -50,13 +50,14 @@ enum AgentSource {
5050 LOCAL = 'local' ,
5151}
5252
53- type AgentValue =
54- | {
55- Id : string ;
56- DeveloperName : string ;
57- source : AgentSource . ORG ;
58- }
59- | { DeveloperName : string ; source : AgentSource . LOCAL ; path : string } ;
53+ type LocalAgent = { DeveloperName : string ; source : AgentSource . LOCAL ; path : string } ;
54+ type OrgAgent = {
55+ Id : string ;
56+ DeveloperName : string ;
57+ source : AgentSource . ORG ;
58+ } ;
59+
60+ type AgentValue = LocalAgent | OrgAgent ;
6061
6162// https://developer.salesforce.com/docs/einstein/genai/guide/agent-api-get-started.html#prerequisites
6263export const UNSUPPORTED_AGENTS = [ 'Copilot_for_Salesforce' ] ;
@@ -92,43 +93,17 @@ export default class AgentPreview extends SfCommand<AgentPreviewResult> {
9293 summary : messages . getMessage ( 'flags.apex-debug.summary' ) ,
9394 char : 'x' ,
9495 } ) ,
96+ 'mock-actions' : Flags . boolean ( {
97+ summary : messages . getMessage ( 'flags.mock-actions.summary' ) ,
98+ dependsOn : [ 'authoring-bundle' ] ,
99+ } ) ,
95100 } ;
96101
97102 public async run ( ) : Promise < AgentPreviewResult > {
98103 const { flags } = await this . parse ( AgentPreview ) ;
99104
100105 const { 'api-name' : apiNameFlag } = flags ;
101106 const conn = flags [ 'target-org' ] . getConnection ( flags [ 'api-version' ] ) ;
102-
103- const authInfo = await AuthInfo . create ( {
104- username : flags [ 'target-org' ] . getUsername ( ) ,
105- } ) ;
106- // Get client app - check flag first, then auth file, then env var
107- let clientApp = flags [ 'client-app' ] ;
108-
109- if ( ! clientApp ) {
110- const clientApps = getClientAppsFromAuth ( authInfo ) ;
111-
112- if ( clientApps . length === 1 ) {
113- clientApp = clientApps [ 0 ] ;
114- } else if ( clientApps . length > 1 ) {
115- clientApp = await select ( {
116- message : 'Select a client app' ,
117- choices : clientApps . map ( ( app ) => ( { value : app , name : app } ) ) ,
118- } ) ;
119- }
120- }
121-
122- if ( ! clientApp ) {
123- // at this point we should throw an error
124- throw new SfError ( 'No client app found.' ) ;
125- }
126-
127- const jwtConn = await Connection . create ( {
128- authInfo,
129- clientApp,
130- } ) ;
131-
132107 const agentsQuery = await conn . query < AgentData > (
133108 'SELECT Id, DeveloperName, (SELECT Status FROM BotVersions) FROM BotDefinition WHERE IsDeleted = false'
134109 ) ;
@@ -137,7 +112,7 @@ export default class AgentPreview extends SfCommand<AgentPreviewResult> {
137112
138113 const agentsInOrg = agentsQuery . records ;
139114
140- let selectedAgent : AgentValue | undefined ;
115+ let selectedAgent : AgentValue ;
141116
142117 if ( flags [ 'authoring-bundle' ] ) {
143118 const bundlePath = findAuthoringBundle ( this . project ! . getPath ( ) , flags [ 'authoring-bundle' ] ) ;
@@ -147,7 +122,7 @@ export default class AgentPreview extends SfCommand<AgentPreviewResult> {
147122 selectedAgent = {
148123 DeveloperName : flags [ 'authoring-bundle' ] ,
149124 source : AgentSource . LOCAL ,
150- path : bundlePath ,
125+ path : join ( bundlePath , ` ${ flags [ 'authoring-bundle' ] } .agent` ) ,
151126 } ;
152127 } else if ( apiNameFlag ) {
153128 const agent = agentsInOrg . find ( ( a ) => a . DeveloperName === apiNameFlag ) ;
@@ -165,13 +140,42 @@ export default class AgentPreview extends SfCommand<AgentPreviewResult> {
165140 choices : getAgentChoices ( agentsInOrg , this . project ! ) ,
166141 } ) ;
167142 }
143+ const authInfo = await AuthInfo . create ( {
144+ username : flags [ 'target-org' ] . getUsername ( ) ,
145+ } ) ;
146+ // Get client app - check flag first, then auth file, then env var
147+ let clientApp = flags [ 'client-app' ] ;
148+
149+ if ( ! clientApp && selectedAgent ?. source === AgentSource . ORG ) {
150+ const clientApps = getClientAppsFromAuth ( authInfo ) ;
151+
152+ if ( clientApps . length === 1 ) {
153+ clientApp = clientApps [ 0 ] ;
154+ } else if ( clientApps . length > 1 ) {
155+ clientApp = await select ( {
156+ message : 'Select a client app' ,
157+ choices : clientApps . map ( ( app ) => ( { value : app , name : app } ) ) ,
158+ } ) ;
159+ } else {
160+ // at this point we should throw an error
161+ throw new SfError ( 'No client app found.' ) ;
162+ }
163+ }
164+
165+ const jwtConn =
166+ selectedAgent ?. source === AgentSource . ORG
167+ ? await Connection . create ( {
168+ authInfo,
169+ clientApp,
170+ } )
171+ : await Connection . create ( { authInfo } ) ;
168172
169173 const outputDir = await resolveOutputDir ( flags [ 'output-dir' ] , flags [ 'apex-debug' ] ) ;
170174 // Both classes share the same interface for the methods we need
171175 const agentPreview =
172176 selectedAgent . source === AgentSource . ORG
173177 ? new Preview ( jwtConn , selectedAgent . Id )
174- : new AgentSimulate ( jwtConn , selectedAgent . path , true ) ;
178+ : new AgentSimulate ( jwtConn , selectedAgent . path , flags [ 'mock-actions' ] ?? false ) ;
175179
176180 agentPreview . toggleApexDebugMode ( flags [ 'apex-debug' ] ) ;
177181
0 commit comments