@@ -94,6 +94,14 @@ export default class AgentPreview extends SfCommand<AgentPreviewResult> {
9494 const authInfo = await AuthInfo . create ( {
9595 username : flags [ 'target-org' ] . getUsername ( ) ,
9696 } ) ;
97+ if ( ! ( flags [ 'client-app' ] ?? env . getString ( 'SF_DEMO_AGENT_CLIENT_APP' ) ) ) {
98+ throw new SfError ( 'SF_DEMO_AGENT_CLIENT_APP is unset!' ) ;
99+ }
100+
101+ const jwtConn = await Connection . create ( {
102+ authInfo,
103+ clientApp : env . getString ( 'SF_DEMO_AGENT_CLIENT_APP' ) ?? flags [ 'client-app' ] ,
104+ } ) ;
97105
98106 const agentsQuery = await conn . query < AgentData > (
99107 'SELECT Id, DeveloperName, (SELECT Status FROM BotVersions) FROM BotDefinition WHERE IsDeleted = false'
@@ -104,7 +112,7 @@ export default class AgentPreview extends SfCommand<AgentPreviewResult> {
104112 const agentsInOrg = agentsQuery . records ;
105113
106114 let selectedAgent ;
107- let clientApp = flags [ 'client-app' ] ;
115+
108116 if ( flags [ 'authoring-bundle' ] ) {
109117 const envAgentName = env . getString ( 'SF_DEMO_AGENT' ) ;
110118 const agent = agentsQuery . records . find ( ( a ) => a . DeveloperName === envAgentName ) ;
@@ -116,10 +124,6 @@ export default class AgentPreview extends SfCommand<AgentPreviewResult> {
116124 } `,
117125 DeveloperName : flags [ 'authoring-bundle' ] ,
118126 } ;
119- clientApp = process . env . SF_DEMO_AGENT_CLIENT_APP ;
120- if ( ! clientApp ) {
121- throw new Error ( 'SF_DEMO_AGENT_CLIENT_APP is unset!' ) ;
122- }
123127 } else if ( apiNameFlag ) {
124128 selectedAgent = agentsInOrg . find ( ( agent ) => agent . DeveloperName === apiNameFlag ) ;
125129 if ( ! selectedAgent ) throw new Error ( `No valid Agents were found with the Api Name ${ apiNameFlag } .` ) ;
@@ -131,11 +135,6 @@ export default class AgentPreview extends SfCommand<AgentPreviewResult> {
131135 } ) ;
132136 }
133137
134- const jwtConn = await Connection . create ( {
135- authInfo,
136- clientApp,
137- } ) ;
138-
139138 const outputDir = await resolveOutputDir ( flags [ 'output-dir' ] , flags [ 'apex-debug' ] ) ;
140139 const agentPreview = new Preview ( jwtConn , selectedAgent . Id ) ;
141140 agentPreview . toggleApexDebugMode ( flags [ 'apex-debug' ] ) ;
0 commit comments