77import { join , resolve } from 'node:path' ;
88import { existsSync } from 'node:fs' ;
99import { SfCommand , Flags } from '@salesforce/sf-plugins-core' ;
10- import { Lifecycle , Messages , SfError } from '@salesforce/core' ;
11- import { AgentTester , AgentTestCreateLifecycleStages } from '@salesforce/agents' ;
10+ import { Connection , Lifecycle , Messages , SfError } from '@salesforce/core' ;
11+ import { AgentTest , AgentTestCreateLifecycleStages } from '@salesforce/agents' ;
1212import { DeployResult } from '@salesforce/source-deploy-retrieve' ;
1313import { MultiStageOutput } from '@oclif/multi-stage-output' ;
1414import { CLIError } from '@oclif/core/errors' ;
@@ -55,9 +55,9 @@ const FLAGGABLE_PROMPTS = {
5555 } ,
5656} ;
5757
58- async function promptUntilUniqueName ( agentTester : AgentTester , name ?: string | undefined ) : Promise < string | undefined > {
58+ async function promptUntilUniqueName ( connection : Connection , name ?: string | undefined ) : Promise < string | undefined > {
5959 const apiName = name ?? ( await promptForFlag ( FLAGGABLE_PROMPTS [ 'test-api-name' ] ) ) ;
60- const existingDefinitions = await agentTester . list ( ) ;
60+ const existingDefinitions = await AgentTest . list ( connection ) ;
6161 if ( existingDefinitions . some ( ( d ) => d . fullName === apiName ) ) {
6262 const confirmation = await yesNoOrCancel ( {
6363 message : messages . getMessage ( 'prompt.confirm' , [ apiName ] ) ,
@@ -68,7 +68,7 @@ async function promptUntilUniqueName(agentTester: AgentTester, name?: string | u
6868 }
6969
7070 if ( ! confirmation ) {
71- return promptUntilUniqueName ( agentTester ) ;
71+ return promptUntilUniqueName ( connection ) ;
7272 }
7373 }
7474 return apiName ;
@@ -95,6 +95,7 @@ export default class AgentTestCreate extends SfCommand<AgentTestCreateResult> {
9595
9696 public async run ( ) : Promise < AgentTestCreateResult > {
9797 const { flags } = await this . parse ( AgentTestCreate ) ;
98+ const connection = flags [ 'target-org' ] . getConnection ( flags [ 'api-version' ] ) ;
9899
99100 // throw error if --json is used and not all required flags are provided
100101 if ( this . jsonEnabled ( ) ) {
@@ -110,11 +111,9 @@ export default class AgentTestCreate extends SfCommand<AgentTestCreateResult> {
110111 throw messages . createError ( 'error.missingRequiredFlags' , [ 'test-api-name' ] ) ;
111112 }
112113
113- const agentTester = new AgentTester ( flags [ 'target-org' ] . getConnection ( flags [ 'api-version' ] ) ) ;
114-
115114 const apiName = flags [ 'force-overwrite' ]
116115 ? flags [ 'test-api-name' ]
117- : await promptUntilUniqueName ( agentTester , flags [ 'test-api-name' ] ) ;
116+ : await promptUntilUniqueName ( connection , flags [ 'test-api-name' ] ) ;
118117 if ( ! apiName ) {
119118 this . log ( messages . getMessage ( 'info.cancel' ) ) ;
120119 return {
@@ -156,7 +155,7 @@ export default class AgentTestCreate extends SfCommand<AgentTestCreateResult> {
156155 return Promise . resolve ( ) ;
157156 } ) ;
158157
159- const { path, contents } = await agentTester . create ( apiName , spec , {
158+ const { path, contents } = await AgentTest . create ( connection , apiName , spec , {
160159 outputDir : join ( 'force-app' , 'main' , 'default' , 'aiEvaluationDefinitions' ) ,
161160 preview : flags . preview ,
162161 } ) ;
0 commit comments