@@ -9,19 +9,17 @@ import { mkdir, writeFile } from 'node:fs/promises';
99import { SfCommand } from '@salesforce/sf-plugins-core' ;
1010import { Messages } from '@salesforce/core' ;
1111import input from '@inquirer/input' ;
12- import select from '@inquirer/select' ;
1312import confirm from '@inquirer/confirm' ;
1413import { theme } from '../../../inquirer-theme.js' ;
1514
1615Messages . importMessagesDirectoryFromMetaUrl ( import . meta. url ) ;
1716const messages = Messages . loadMessages ( '@salesforce/plugin-agent' , 'agent.generate.testset' ) ;
1817
19- type ExpectationType = 'topic_sequence_match' | 'action_sequence_match' | 'bot_response_rating' ;
20-
2118export type TestSetInputs = {
2219 utterance : string ;
23- expectationType : ExpectationType ;
24- expectedValue : string ;
20+ actionSequenceExpectedValue : string ;
21+ botRatingExpectedValue : string ;
22+ topicSequenceExpectedValue : string ;
2523} ;
2624
2725async function promptForTestCase ( ) : Promise < TestSetInputs > {
@@ -31,21 +29,33 @@ async function promptForTestCase(): Promise<TestSetInputs> {
3129 theme,
3230 } ) ;
3331
34- const expectationType = await select < ExpectationType > ( {
35- message : 'What type of expectation would you like to test for the utterance?' ,
36- choices : [ 'topic_sequence_match' , 'action_sequence_match' , 'bot_response_rating' ] ,
32+ const topicSequenceExpectedValue = await input ( {
33+ message : 'What is the expected value for the topic expectation?' ,
34+ validate : ( d : string ) : boolean | string => {
35+ if ( ! d . length ) {
36+ return 'expected value cannot be empty' ;
37+ }
38+ return true ;
39+ } ,
3740 theme,
3841 } ) ;
3942
40- const expectedValue = await input ( {
41- message : 'What is the expected value for the expectation?' ,
43+ const actionSequenceExpectedValue = await input ( {
44+ message : 'What is the expected value for the action expectation?' ,
4245 validate : ( d : string ) : boolean | string => {
4346 if ( ! d . length ) {
4447 return 'expected value cannot be empty' ;
4548 }
49+ return true ;
50+ } ,
51+ theme,
52+ } ) ;
4653
47- if ( expectationType === 'action_sequence_match' ) {
48- return d . split ( ',' ) . length > 1 || 'expected value must be a comma-separated list of actions' ;
54+ const botRatingExpectedValue = await input ( {
55+ message : 'What is the expected value for the bot rating expectation?' ,
56+ validate : ( d : string ) : boolean | string => {
57+ if ( ! d . length ) {
58+ return 'expected value cannot be empty' ;
4959 }
5060
5161 return true ;
@@ -55,31 +65,36 @@ async function promptForTestCase(): Promise<TestSetInputs> {
5565
5666 return {
5767 utterance,
58- expectationType,
59- expectedValue,
68+ actionSequenceExpectedValue,
69+ botRatingExpectedValue,
70+ topicSequenceExpectedValue,
6071 } ;
6172}
6273
6374export function constructTestSetXML ( testCases : TestSetInputs [ ] ) : string {
6475 const tab = ' ' ;
6576 let xml = `<?xml version="1.0" encoding="UTF-8"?>\n<AiEvaluationTestSet>\n${ tab } <subjectType>AGENT</subjectType>\n` ;
6677 testCases . forEach ( ( testCase , i ) => {
67- const expectedValue =
68- testCase . expectationType === 'action_sequence_match'
69- ? `[${ testCase . expectedValue
70- . split ( ',' )
71- . map ( ( v ) => `"${ v } "` )
72- . join ( ',' ) } ]`
73- : testCase . expectedValue ;
7478 xml += ` <testCase>
7579 <number>${ i + 1 } </number>
7680 <inputs>
7781 <utterance>${ testCase . utterance } </utterance>
7882 </inputs>
7983 <expectations>
8084 <expectation>
81- <name>${ testCase . expectationType } </name>
82- <expectedValue>${ expectedValue } </expectedValue>
85+ <name>topic_sequence_match</name>
86+ <expectedValue>${ testCase . topicSequenceExpectedValue } </expectedValue>
87+ </expectation>
88+ <expectation>
89+ <name>action_sequence_match</name>
90+ <expectedValue>${ `[${ testCase . actionSequenceExpectedValue
91+ . split ( ',' )
92+ . map ( ( v ) => `"${ v } "` )
93+ . join ( ',' ) } ]`} </expectedValue>
94+ </expectation>
95+ <expectation>
96+ <name>bot_response_rating</name>
97+ <expectedValue>${ testCase . botRatingExpectedValue } </expectedValue>
8398 </expectation>
8499 </expectations>
85100 </testCase>\n` ;
0 commit comments