@@ -66,7 +66,6 @@ export default class AgentPreview extends SfCommand<AgentPreviewResult> {
6666 'client-app' : Flags . string ( {
6767 char : 'c' ,
6868 summary : messages . getMessage ( 'flags.client-app.summary' ) ,
69- required : true ,
7069 dependsOn : [ 'target-org' ] ,
7170 } ) ,
7271 'api-name' : Flags . string ( {
@@ -96,11 +95,6 @@ export default class AgentPreview extends SfCommand<AgentPreviewResult> {
9695 username : flags [ 'target-org' ] . getUsername ( ) ,
9796 } ) ;
9897
99- const jwtConn = await Connection . create ( {
100- authInfo,
101- clientApp : flags [ 'client-app' ] ,
102- } ) ;
103-
10498 const agentsQuery = await conn . query < AgentData > (
10599 'SELECT Id, DeveloperName, (SELECT Status FROM BotVersions) FROM BotDefinition WHERE IsDeleted = false'
106100 ) ;
@@ -110,7 +104,7 @@ export default class AgentPreview extends SfCommand<AgentPreviewResult> {
110104 const agentsInOrg = agentsQuery . records ;
111105
112106 let selectedAgent ;
113-
107+ let clientApp = flags [ 'client-app' ] ;
114108 if ( flags [ 'authoring-bundle' ] ) {
115109 const envAgentName = env . getString ( 'SF_DEMO_AGENT' ) ;
116110 const agent = agentsQuery . records . find ( ( a ) => a . DeveloperName === envAgentName ) ;
@@ -122,6 +116,10 @@ export default class AgentPreview extends SfCommand<AgentPreviewResult> {
122116 } `,
123117 DeveloperName : flags [ 'authoring-bundle' ] ,
124118 } ;
119+ clientApp = process . env . SF_DEMO_AGENT_CLIENT_APP ;
120+ if ( ! clientApp ) {
121+ throw new Error ( 'SF_DEMO_AGENT_CLIENT_APP is unset!' ) ;
122+ }
125123 } else if ( apiNameFlag ) {
126124 selectedAgent = agentsInOrg . find ( ( agent ) => agent . DeveloperName === apiNameFlag ) ;
127125 if ( ! selectedAgent ) throw new Error ( `No valid Agents were found with the Api Name ${ apiNameFlag } .` ) ;
@@ -133,6 +131,13 @@ export default class AgentPreview extends SfCommand<AgentPreviewResult> {
133131 } ) ;
134132 }
135133
134+ // eslint-disable-next-line no-console
135+ console . log ( 'clientApp' , clientApp ) ;
136+ const jwtConn = await Connection . create ( {
137+ authInfo,
138+ clientApp,
139+ } ) ;
140+
136141 const outputDir = await resolveOutputDir ( flags [ 'output-dir' ] , flags [ 'apex-debug' ] ) ;
137142 const agentPreview = new Preview ( jwtConn , selectedAgent . Id ) ;
138143 agentPreview . toggleApexDebugMode ( flags [ 'apex-debug' ] ) ;
0 commit comments