@salesforce/agents 0.14.5 → 0.14.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,114 @@
1
+ import { Connection } from '@salesforce/core';
2
+ import { DeployResult } from '@salesforce/source-deploy-retrieve';
3
+ import { type AvailableDefinition, type AgentTestConfig, type AiEvaluationDefinition, type TestSpec } from './types.js';
4
+ /**
5
+ * Events emitted during agent test creation for consumers to listen to and keep track of progress.
6
+ */
7
+ export declare const AgentTestCreateLifecycleStages: {
8
+ CreatingLocalMetadata: string;
9
+ Waiting: string;
10
+ DeployingMetadata: string;
11
+ Done: string;
12
+ };
13
+ /**
14
+ * A client side representation of an agent test (AiEvaluationDefinition) within an org.
15
+ * Also provides utilities such as creating and listing agent tests, and converting between
16
+ * agent test spec and AiEvaluationDefinition.
17
+ *
18
+ * **Examples**
19
+ *
20
+ * Create a new instance from an agent test spec:
21
+ *
22
+ * `const agentTest = new AgentTest({ specPath: path/to/specfile });`
23
+ *
24
+ * Get the metadata content of an agent test:
25
+ *
26
+ * `const metadataContent = await agentTest.getMetadata();`
27
+ *
28
+ * Write the metadata content to a file:
29
+ *
30
+ * `await agentTest.writeMetadata('path/to/metadataFile');`
31
+ */
32
+ export declare class AgentTest {
33
+ private config;
34
+ private specData?;
35
+ private data?;
36
+ /**
37
+ * Create an AgentTest based on one of:
38
+ *
39
+ * 1. AiEvaluationDefinition API name.
40
+ * 2. Path to a local AiEvaluationDefinition metadata file.
41
+ * 3. Path to a local agent test spec file.
42
+ * 4. Agent test spec data.
43
+ *
44
+ * @param config AgentTestConfig
45
+ */
46
+ constructor(config: AgentTestConfig);
47
+ /**
48
+ * List the AiEvaluationDefinitions available in the org.
49
+ */
50
+ static list(connection: Connection): Promise<AvailableDefinition[]>;
51
+ /**
52
+ * Creates and deploys an AiEvaluationDefinition from a specification file.
53
+ *
54
+ * @param connection - Connection to the org where the agent test will be created.
55
+ * @param apiName - The API name of the AiEvaluationDefinition to create
56
+ * @param specFilePath - The path to the specification file to create the definition from
57
+ * @param options - Configuration options for creating the definition
58
+ * @param options.outputDir - The directory where the AiEvaluationDefinition file will be written
59
+ * @param options.preview - If true, writes the AiEvaluationDefinition file to <api-name>-preview-<timestamp>.xml in the current working directory and does not deploy it
60
+ *
61
+ * @returns Promise containing:
62
+ * - path: The filesystem path to the created AiEvaluationDefinition file
63
+ * - contents: The AiEvaluationDefinition contents as a string
64
+ * - deployResult: The deployment result (if not in preview mode)
65
+ *
66
+ * @throws {SfError} When deployment fails
67
+ */
68
+ static create(connection: Connection, apiName: string, specFilePath: string, options: {
69
+ outputDir: string;
70
+ preview?: boolean;
71
+ }): Promise<{
72
+ path: string;
73
+ contents: string;
74
+ deployResult?: DeployResult;
75
+ }>;
76
+ /**
77
+ * Get the specification for this agent test.
78
+ *
79
+ * Returns the test spec data if already generated. Otherwise it will generate the spec by:
80
+ *
81
+ * 1. Read from an existing local spec file.
82
+ * 2. Read from an existing local AiEvaluationDefinition metadata file and convert it.
83
+ * 3. Use the provided org connection to read the remote AiEvaluationDefinition metadata.
84
+ *
85
+ * @param connection Org connection to use if this AgentTest only has an AiEvaluationDefinition API name.
86
+ * @returns Promise<TestSpec>
87
+ */
88
+ getTestSpec(connection?: Connection): Promise<TestSpec>;
89
+ /**
90
+ * Get the metadata content for this agent test.
91
+ *
92
+ * Returns the AiEvaluationDefinition metadata if already generated. Otherwise it will get it by:
93
+ *
94
+ * 1. Read from an existing local AiEvaluationDefinition metadata file.
95
+ * 2. Read from an existing local spec file and convert it.
96
+ * 3. Use the provided org connection to read the remote AiEvaluationDefinition metadata.
97
+ *
98
+ * @param connection Org connection to use if this AgentTest only has an AiEvaluationDefinition API name.
99
+ * @returns Promise<TestSpec>
100
+ */
101
+ getMetadata(connection?: Connection): Promise<AiEvaluationDefinition>;
102
+ /**
103
+ * Write a test specification file in YAML format.
104
+ *
105
+ * @param outputFile The file path where the YAML test spec should be written.
106
+ */
107
+ writeTestSpec(outputFile: string): Promise<void>;
108
+ /**
109
+ * Write AiEvaluationDefinition metadata file.
110
+ *
111
+ * @param outputFile The file path where the metadata file should be written.
112
+ */
113
+ writeMetadata(outputFile: string): Promise<void>;
114
+ }
@@ -0,0 +1,332 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2024, salesforce.com, inc.
4
+ * All rights reserved.
5
+ * Licensed under the BSD 3-Clause license.
6
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.AgentTest = exports.AgentTestCreateLifecycleStages = void 0;
10
+ const promises_1 = require("node:fs/promises");
11
+ const node_path_1 = require("node:path");
12
+ const core_1 = require("@salesforce/core");
13
+ const kit_1 = require("@salesforce/kit");
14
+ const source_deploy_retrieve_1 = require("@salesforce/source-deploy-retrieve");
15
+ const yaml_1 = require("yaml");
16
+ const fast_xml_parser_1 = require("fast-xml-parser");
17
+ ;
18
+ const messages = new core_1.Messages('@salesforce/agents', 'agentTest', new Map([["invalidAgentTestConfig", "Must provide one of: [ name, mdPath, specPath, specData ] when instantiating an AgentTest."], ["missingConnection", "Must provide an org connection to get agent test data based on an AiEvaluationDefinition API name."], ["missingTestSpecData", "The agent test is missing the required data to provide a test spec."]]));
19
+ /**
20
+ * Events emitted during agent test creation for consumers to listen to and keep track of progress.
21
+ */
22
+ exports.AgentTestCreateLifecycleStages = {
23
+ CreatingLocalMetadata: 'Creating Local Metadata',
24
+ Waiting: 'Waiting for the org to respond',
25
+ DeployingMetadata: 'Deploying Metadata',
26
+ Done: 'Done',
27
+ };
28
+ /**
29
+ * A client side representation of an agent test (AiEvaluationDefinition) within an org.
30
+ * Also provides utilities such as creating and listing agent tests, and converting between
31
+ * agent test spec and AiEvaluationDefinition.
32
+ *
33
+ * **Examples**
34
+ *
35
+ * Create a new instance from an agent test spec:
36
+ *
37
+ * `const agentTest = new AgentTest({ specPath: path/to/specfile });`
38
+ *
39
+ * Get the metadata content of an agent test:
40
+ *
41
+ * `const metadataContent = await agentTest.getMetadata();`
42
+ *
43
+ * Write the metadata content to a file:
44
+ *
45
+ * `await agentTest.writeMetadata('path/to/metadataFile');`
46
+ */
47
+ class AgentTest {
48
+ config;
49
+ specData;
50
+ data;
51
+ /**
52
+ * Create an AgentTest based on one of:
53
+ *
54
+ * 1. AiEvaluationDefinition API name.
55
+ * 2. Path to a local AiEvaluationDefinition metadata file.
56
+ * 3. Path to a local agent test spec file.
57
+ * 4. Agent test spec data.
58
+ *
59
+ * @param config AgentTestConfig
60
+ */
61
+ constructor(config) {
62
+ this.config = config;
63
+ const { name, mdPath, specPath, specData } = config;
64
+ if (!name && !mdPath && !specPath && !specData) {
65
+ throw messages.createError('invalidAgentTestConfig');
66
+ }
67
+ if (specData) {
68
+ this.specData = specData;
69
+ }
70
+ }
71
+ /**
72
+ * List the AiEvaluationDefinitions available in the org.
73
+ */
74
+ static async list(connection) {
75
+ return connection.metadata.list({ type: 'AiEvaluationDefinition' });
76
+ }
77
+ /**
78
+ * Creates and deploys an AiEvaluationDefinition from a specification file.
79
+ *
80
+ * @param connection - Connection to the org where the agent test will be created.
81
+ * @param apiName - The API name of the AiEvaluationDefinition to create
82
+ * @param specFilePath - The path to the specification file to create the definition from
83
+ * @param options - Configuration options for creating the definition
84
+ * @param options.outputDir - The directory where the AiEvaluationDefinition file will be written
85
+ * @param options.preview - If true, writes the AiEvaluationDefinition file to <api-name>-preview-<timestamp>.xml in the current working directory and does not deploy it
86
+ *
87
+ * @returns Promise containing:
88
+ * - path: The filesystem path to the created AiEvaluationDefinition file
89
+ * - contents: The AiEvaluationDefinition contents as a string
90
+ * - deployResult: The deployment result (if not in preview mode)
91
+ *
92
+ * @throws {SfError} When deployment fails
93
+ */
94
+ static async create(connection, apiName, specFilePath, options) {
95
+ const agentTestSpec = (0, yaml_1.parse)(await (0, promises_1.readFile)(specFilePath, 'utf-8'));
96
+ const lifecycle = core_1.Lifecycle.getInstance();
97
+ await lifecycle.emit(exports.AgentTestCreateLifecycleStages.CreatingLocalMetadata, {});
98
+ const preview = options.preview ?? false;
99
+ // outputDir is overridden if preview is true
100
+ const outputDir = preview ? process.cwd() : options.outputDir;
101
+ const filename = preview
102
+ ? `${apiName}-preview-${new Date().toISOString()}.xml`
103
+ : `${apiName}.aiEvaluationDefinition-meta.xml`;
104
+ const definitionPath = (0, node_path_1.join)(outputDir, filename);
105
+ const xml = buildMetadataXml(convertToMetadata(agentTestSpec));
106
+ await (0, promises_1.mkdir)(outputDir, { recursive: true });
107
+ await (0, promises_1.writeFile)(definitionPath, xml);
108
+ if (preview) {
109
+ return { path: definitionPath, contents: xml };
110
+ }
111
+ const cs = await source_deploy_retrieve_1.ComponentSetBuilder.build({ sourcepath: [definitionPath] });
112
+ const deploy = await cs.deploy({ usernameOrConnection: connection });
113
+ deploy.onUpdate((status) => {
114
+ if (status.status === source_deploy_retrieve_1.RequestStatus.Pending) {
115
+ void lifecycle.emit(exports.AgentTestCreateLifecycleStages.Waiting, status);
116
+ }
117
+ else {
118
+ void lifecycle.emit(exports.AgentTestCreateLifecycleStages.DeployingMetadata, status);
119
+ }
120
+ });
121
+ deploy.onFinish((result) => {
122
+ // small deploys like this, 1 file, can happen without an 'update' event being fired
123
+ // onFinish, emit the update, and then the done event to create proper output
124
+ void lifecycle.emit(exports.AgentTestCreateLifecycleStages.DeployingMetadata, result);
125
+ void lifecycle.emit(exports.AgentTestCreateLifecycleStages.Done, result);
126
+ });
127
+ const result = await deploy.pollStatus({ timeout: kit_1.Duration.minutes(10_000), frequency: kit_1.Duration.seconds(1) });
128
+ if (!result.response.success) {
129
+ throw new core_1.SfError(result.response.errorMessage ?? `Unable to deploy ${result.response.id}`);
130
+ }
131
+ return { path: definitionPath, contents: xml, deployResult: result };
132
+ }
133
+ /**
134
+ * Get the specification for this agent test.
135
+ *
136
+ * Returns the test spec data if already generated. Otherwise it will generate the spec by:
137
+ *
138
+ * 1. Read from an existing local spec file.
139
+ * 2. Read from an existing local AiEvaluationDefinition metadata file and convert it.
140
+ * 3. Use the provided org connection to read the remote AiEvaluationDefinition metadata.
141
+ *
142
+ * @param connection Org connection to use if this AgentTest only has an AiEvaluationDefinition API name.
143
+ * @returns Promise<TestSpec>
144
+ */
145
+ async getTestSpec(connection) {
146
+ if (this.specData) {
147
+ return this.specData;
148
+ }
149
+ if (this.data) {
150
+ this.specData = convertToSpec(this.data);
151
+ return this.specData;
152
+ }
153
+ if (this.config.specPath) {
154
+ this.specData = (0, yaml_1.parse)(await (0, promises_1.readFile)(this.config.specPath, 'utf-8'));
155
+ return this.specData;
156
+ }
157
+ if (this.config.mdPath) {
158
+ this.data = await parseAgentTestXml(this.config.mdPath);
159
+ this.specData = convertToSpec(this.data);
160
+ return this.specData;
161
+ }
162
+ // read from the server if we have a connection and an API name only
163
+ if (this.config.name) {
164
+ if (connection) {
165
+ // @ts-expect-error jsForce types don't know about AiEvaluationDefinition yet
166
+ this.data = (await connection.metadata.read('AiEvaluationDefinition', this.config.name));
167
+ this.specData = convertToSpec(this.data);
168
+ return this.specData;
169
+ }
170
+ else {
171
+ throw messages.createError('missingConnection');
172
+ }
173
+ }
174
+ throw messages.createError('missingTestSpecData');
175
+ }
176
+ /**
177
+ * Get the metadata content for this agent test.
178
+ *
179
+ * Returns the AiEvaluationDefinition metadata if already generated. Otherwise it will get it by:
180
+ *
181
+ * 1. Read from an existing local AiEvaluationDefinition metadata file.
182
+ * 2. Read from an existing local spec file and convert it.
183
+ * 3. Use the provided org connection to read the remote AiEvaluationDefinition metadata.
184
+ *
185
+ * @param connection Org connection to use if this AgentTest only has an AiEvaluationDefinition API name.
186
+ * @returns Promise<TestSpec>
187
+ */
188
+ async getMetadata(connection) {
189
+ if (this.data) {
190
+ return this.data;
191
+ }
192
+ if (this.specData) {
193
+ this.data = convertToMetadata(this.specData);
194
+ return this.data;
195
+ }
196
+ if (this.config.mdPath) {
197
+ this.data = await parseAgentTestXml(this.config.mdPath);
198
+ return this.data;
199
+ }
200
+ if (this.config.specPath) {
201
+ this.specData = (0, yaml_1.parse)(await (0, promises_1.readFile)(this.config.specPath, 'utf-8'));
202
+ this.data = convertToMetadata(this.specData);
203
+ return this.data;
204
+ }
205
+ // read from the server if we have a connection and an API name only
206
+ if (this.config.name) {
207
+ if (connection) {
208
+ // @ts-expect-error jsForce types don't know about AiEvaluationDefinition yet
209
+ this.data = (await connection.metadata.read('AiEvaluationDefinition', this.config.name));
210
+ return this.data;
211
+ }
212
+ else {
213
+ throw messages.createError('missingConnection');
214
+ }
215
+ }
216
+ throw messages.createError('missingTestSpecData');
217
+ }
218
+ /**
219
+ * Write a test specification file in YAML format.
220
+ *
221
+ * @param outputFile The file path where the YAML test spec should be written.
222
+ */
223
+ async writeTestSpec(outputFile) {
224
+ const spec = await this.getTestSpec();
225
+ // strip out undefined values and empty strings
226
+ const clean = Object.entries(spec).reduce((acc, [key, value]) => {
227
+ if (value !== undefined && value !== '')
228
+ return { ...acc, [key]: value };
229
+ return acc;
230
+ }, {});
231
+ const yml = (0, yaml_1.stringify)(clean, undefined, {
232
+ minContentWidth: 0,
233
+ lineWidth: 0,
234
+ });
235
+ await (0, promises_1.mkdir)((0, node_path_1.dirname)(outputFile), { recursive: true });
236
+ await (0, promises_1.writeFile)(outputFile, yml);
237
+ }
238
+ /**
239
+ * Write AiEvaluationDefinition metadata file.
240
+ *
241
+ * @param outputFile The file path where the metadata file should be written.
242
+ */
243
+ async writeMetadata(outputFile) {
244
+ const xml = buildMetadataXml(await this.getMetadata());
245
+ await (0, promises_1.mkdir)((0, node_path_1.dirname)(outputFile), { recursive: true });
246
+ await (0, promises_1.writeFile)(outputFile, xml);
247
+ }
248
+ }
249
+ exports.AgentTest = AgentTest;
250
+ // Convert AiEvaluationDefinition metadata XML content to a YAML test spec object.
251
+ const convertToSpec = (data) => ({
252
+ name: data.name,
253
+ description: data.description,
254
+ subjectType: data.subjectType,
255
+ subjectName: data.subjectName,
256
+ subjectVersion: data.subjectVersion,
257
+ testCases: (0, kit_1.ensureArray)(data.testCase).map((tc) => {
258
+ const expectations = (0, kit_1.ensureArray)(tc.expectation);
259
+ return {
260
+ utterance: tc.inputs.utterance,
261
+ // TODO: remove old names once removed in 258 (topic_sequence_match, action_sequence_match, bot_response_rating)
262
+ expectedTopic: expectations.find((e) => e.name === 'topic_sequence_match' || e.name === 'topic_assertion')
263
+ ?.expectedValue,
264
+ expectedActions: transformStringToArray(expectations.find((e) => e.name === 'action_sequence_match' || e.name === 'actions_assertion')?.expectedValue),
265
+ expectedOutcome: expectations.find((e) => e.name === 'bot_response_rating' || e.name === 'output_validation')
266
+ ?.expectedValue,
267
+ };
268
+ }),
269
+ });
270
+ // Convert a YAML test spec object to AiEvaluationDefinition metadata XML content.
271
+ const convertToMetadata = (spec) => ({
272
+ ...(spec.description && { description: spec.description }),
273
+ name: spec.name,
274
+ subjectName: spec.subjectName,
275
+ subjectType: spec.subjectType,
276
+ ...(spec.subjectVersion && { subjectVersion: spec.subjectVersion }),
277
+ testCase: spec.testCases.map((tc) => ({
278
+ expectation: [
279
+ {
280
+ expectedValue: tc.expectedTopic,
281
+ name: 'topic_sequence_match',
282
+ },
283
+ {
284
+ expectedValue: `[${(tc.expectedActions ?? []).map((v) => `"${v}"`).join(',')}]`,
285
+ name: 'action_sequence_match',
286
+ },
287
+ {
288
+ expectedValue: tc.expectedOutcome,
289
+ name: 'bot_response_rating',
290
+ },
291
+ ],
292
+ inputs: {
293
+ utterance: tc.utterance,
294
+ },
295
+ number: spec.testCases.indexOf(tc) + 1,
296
+ })),
297
+ });
298
+ function transformStringToArray(str) {
299
+ try {
300
+ if (!str)
301
+ return [];
302
+ // Remove any whitespace and ensure proper JSON format
303
+ const cleaned = str.replace(/\s+/g, '');
304
+ return JSON.parse(cleaned);
305
+ }
306
+ catch {
307
+ return [];
308
+ }
309
+ }
310
+ const parseAgentTestXml = async (mdPath) => {
311
+ const xml = await (0, promises_1.readFile)(mdPath, 'utf-8');
312
+ const parser = new fast_xml_parser_1.XMLParser();
313
+ const xmlContent = parser.parse(xml);
314
+ return xmlContent.AiEvaluationDefinition;
315
+ };
316
+ const buildMetadataXml = (data) => {
317
+ const aiEvalXml = {
318
+ AiEvaluationDefinition: {
319
+ $xmlns: 'http://soap.sforce.com/2006/04/metadata',
320
+ ...data,
321
+ },
322
+ };
323
+ const builder = new fast_xml_parser_1.XMLBuilder({
324
+ format: true,
325
+ attributeNamePrefix: '$',
326
+ indentBy: ' ',
327
+ ignoreAttributes: false,
328
+ });
329
+ const xml = builder.build(aiEvalXml);
330
+ return `<?xml version="1.0" encoding="UTF-8"?>\n${xml}`;
331
+ };
332
+ //# sourceMappingURL=agentTest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agentTest.js","sourceRoot":"","sources":["../src/agentTest.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,+CAA8D;AAC9D,yCAA0C;AAC1C,2CAA4E;AAC5E,yCAAwD;AACxD,+EAAsG;AACtG,+BAAwC;AACxC,qDAAwD;;AAIxD,MAAM,QAAQ,OAAG,eAAQ,CAAc,oBAAoB,EAAE,WAAW,mWAAC,CAAC;AAE1E;;GAEG;AACU,QAAA,8BAA8B,GAAG;IAC5C,qBAAqB,EAAE,yBAAyB;IAChD,OAAO,EAAE,gCAAgC;IACzC,iBAAiB,EAAE,oBAAoB;IACvC,IAAI,EAAE,MAAM;CACb,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAa,SAAS;IAcO;IAbnB,QAAQ,CAAY;IACpB,IAAI,CAA0B;IAEtC;;;;;;;;;OASG;IACH,YAA2B,MAAuB;QAAvB,WAAM,GAAN,MAAM,CAAiB;QAChD,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;QAEpD,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC/C,MAAM,QAAQ,CAAC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AC;CACJ,CAAC,CAAC;AAEH,SAAS,sBAAsB,CAAC,GAAuB;IACrD,IAAI,CAAC;QACH,IAAI,CAAC,GAAG;YAAE,OAAO,EAAE,CAAC;QACpB,sDAAsD;QACtD,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACxC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAa,CAAC;IACzC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAKD,MAAM,iBAAiB,GAAG,KAAK,EAAE,MAAc,EAAmC,EAAE;IAClF,MAAM,GAAG,GAAG,MAAM,IAAA,mBAAQ,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC5C,MAAM,MAAM,GAAG,IAAI,2BAAS,EAAE,CAAC;IAC/B,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAA8B,CAAC;IAClE,OAAO,UAAU,CAAC,sBAAsB,CAAC;AAC3C,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAAG,CAAC,IAA4B,EAAU,EAAE;IAChE,MAAM,SAAS,GAAG;QAChB,sBAAsB,EAAE;YACtB,MAAM,EAAE,yCAAyC;YACjD,GAAG,IAAI;SACR;KACF,CAAC;IAEF,MAAM,OAAO,GAAG,IAAI,4BAAU,CAAC;QAC7B,MAAM,EAAE,IAAI;QACZ,mBAAmB,EAAE,GAAG;QACxB,QAAQ,EAAE,MAAM;QAChB,gBAAgB,EAAE,KAAK;KACxB,CAAC,CAAC;IAEH,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,SAAS,CAAW,CAAC;IAE/C,OAAO,2CAA2C,GAAG,EAAE,CAAC;AAC1D,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { type AgentTestResultsResponse } from './types.js';
2
+ /**
3
+ * Convert the raw, detailed test results to another format.
4
+ *
5
+ * @param results The detailed results from a test run.
6
+ * @param format The desired format. One of: json, junit, or tap.
7
+ * @returns
8
+ */
9
+ export declare function convertTestResultsToFormat(results: AgentTestResultsResponse, format: 'json' | 'junit' | 'tap'): Promise<string>;
10
+ export declare function humanFriendlyName(name: string): string;
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2024, salesforce.com, inc.
4
+ * All rights reserved.
5
+ * Licensed under the BSD 3-Clause license.
6
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.convertTestResultsToFormat = convertTestResultsToFormat;
10
+ exports.humanFriendlyName = humanFriendlyName;
11
+ const fast_xml_parser_1 = require("fast-xml-parser");
12
+ /**
13
+ * Convert the raw, detailed test results to another format.
14
+ *
15
+ * @param results The detailed results from a test run.
16
+ * @param format The desired format. One of: json, junit, or tap.
17
+ * @returns
18
+ */
19
+ async function convertTestResultsToFormat(results, format) {
20
+ switch (format) {
21
+ case 'json':
22
+ return jsonFormat(results);
23
+ case 'junit':
24
+ return junitFormat(results);
25
+ case 'tap':
26
+ return tapFormat(results);
27
+ default:
28
+ throw new Error(`Unsupported format: ${format}`);
29
+ }
30
+ }
31
+ async function jsonFormat(results) {
32
+ return Promise.resolve(JSON.stringify(results, null, 2));
33
+ }
34
+ async function junitFormat(results) {
35
+ const builder = new fast_xml_parser_1.XMLBuilder({
36
+ format: true,
37
+ attributeNamePrefix: '$',
38
+ ignoreAttributes: false,
39
+ });
40
+ const testCount = results.testCases.length;
41
+ const failureCount = results.testCases.filter((tc) => ['error', 'completed'].includes(tc.status.toLowerCase()) && tc.testResults.some((r) => r.result === 'FAILURE')).length;
42
+ const time = results.testCases.reduce((acc, tc) => {
43
+ if (tc.endTime && tc.startTime) {
44
+ return acc + new Date(tc.endTime).getTime() - new Date(tc.startTime).getTime();
45
+ }
46
+ return acc;
47
+ }, 0);
48
+ const suites = builder.build({
49
+ testsuites: {
50
+ $name: results.subjectName,
51
+ $tests: testCount,
52
+ $failures: failureCount,
53
+ $time: time,
54
+ property: [
55
+ { $name: 'status', $value: results.status },
56
+ { $name: 'start-time', $value: results.startTime },
57
+ { $name: 'end-time', $value: results.endTime },
58
+ ],
59
+ testsuite: results.testCases.map((testCase) => {
60
+ const testCaseTime = testCase.endTime
61
+ ? new Date(testCase.endTime).getTime() - new Date(testCase.startTime).getTime()
62
+ : 0;
63
+ return {
64
+ $name: testCase.testNumber,
65
+ $time: testCaseTime,
66
+ $assertions: testCase.testResults.length,
67
+ failure: testCase.testResults
68
+ .map((r) => {
69
+ if (r.result === 'FAILURE') {
70
+ return { $message: r.errorMessage ?? 'Unknown error', $name: r.name };
71
+ }
72
+ })
73
+ .filter((f) => f),
74
+ };
75
+ }),
76
+ },
77
+ });
78
+ return Promise.resolve(`<?xml version="1.0" encoding="UTF-8"?>\n${suites}`.trim());
79
+ }
80
+ async function tapFormat(results) {
81
+ const lines = [];
82
+ let expectationCount = 0;
83
+ for (const testCase of results.testCases) {
84
+ for (const result of testCase.testResults) {
85
+ const status = result.result === 'PASS' ? 'ok' : 'not ok';
86
+ expectationCount++;
87
+ lines.push(`${status} ${expectationCount} ${testCase.testNumber}.${result.name}`);
88
+ if (status === 'not ok') {
89
+ lines.push(' ---');
90
+ lines.push(` message: ${result.errorMessage ?? 'Unknown error'}`);
91
+ lines.push(` expectation: ${result.name}`);
92
+ lines.push(` actual: ${result.actualValue}`);
93
+ lines.push(` expected: ${result.expectedValue}`);
94
+ lines.push(' ...');
95
+ }
96
+ }
97
+ }
98
+ return Promise.resolve(`Tap Version 14\n1..${expectationCount}\n${lines.join('\n')}`);
99
+ }
100
+ function humanFriendlyName(name) {
101
+ // topic_sequence_match, action_sequence_match, and bot_response_rating have all changed
102
+ // eventually we can remove them
103
+ switch (name) {
104
+ case 'topic_sequence_match':
105
+ case 'topic_assertion':
106
+ return 'Topic';
107
+ case 'action_sequence_match':
108
+ case 'actions_assertion':
109
+ return 'Action';
110
+ case 'output_latency_milliseconds':
111
+ return 'Output Latency';
112
+ case 'instruction_following':
113
+ return 'Instruction Following';
114
+ case 'bot_response_rating':
115
+ case 'output_validation':
116
+ return 'Outcome';
117
+ default:
118
+ return name;
119
+ }
120
+ }
121
+ //# sourceMappingURL=agentTestResults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agentTestResults.js","sourceRoot":"","sources":["../src/agentTestResults.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAYH,gEAcC;AAkFD,8CAoBC;AA9HD,qDAA6C;AAG7C;;;;;;GAMG;AACI,KAAK,UAAU,0BAA0B,CAC9C,OAAiC,EACjC,MAAgC;IAEhC,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,MAAM;YACT,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC;QAC7B,KAAK,OAAO;YACV,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC;QAC9B,KAAK,KAAK;YACR,OAAO,SAAS,CAAC,OAAO,CAAC,CAAC;QAC5B;YACE,MAAM,IAAI,KAAK,CAAC,uBAAuB,MAAgB,EAAE,CAAC,CAAC;IAC/D,CAAC;AACH,CAAC;AAED,KAAK,UAAU,UAAU,CAAC,OAAiC;IACzD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED,KAAK,UAAU,WAAW,CAAC,OAAiC;IAC1D,MAAM,OAAO,GAAG,IAAI,4BAAU,CAAC;QAC7B,MAAM,EAAE,IAAI;QACZ,mBAAmB,EAAE,GAAG;QACxB,gBAAgB,EAAE,KAAK;KACxB,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC;IAC3C,MAAM,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAC3C,CAAC,EAAE,EAAE,EAAE,CACL,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,Q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ACxB,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBACpB,KAAK,CAAC,IAAI,CAAC,cAAc,MAAM,CAAC,YAAY,IAAI,eAAe,EAAE,CAAC,CAAC;gBACnE,KAAK,CAAC,IAAI,CAAC,kBAAkB,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;gBAC5C,KAAK,CAAC,IAAI,CAAC,aAAa,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;gBAC9C,KAAK,CAAC,IAAI,CAAC,eAAe,MAAM,CAAC,aAAa,EAAE,CAAC,CAAC;gBAClD,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACtB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC,OAAO,CAAC,sBAAsB,gBAAgB,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACxF,CAAC;AAED,SAAgB,iBAAiB,CAAC,IAAY;IAC5C,wFAAwF;IACxF,gCAAgC;IAChC,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,sBAAsB,CAAC;QAC5B,KAAK,iBAAiB;YACpB,OAAO,OAAO,CAAC;QACjB,KAAK,uBAAuB,CAAC;QAC7B,KAAK,mBAAmB;YACtB,OAAO,QAAQ,CAAC;QAClB,KAAK,6BAA6B;YAChC,OAAO,gBAAgB,CAAC;QAC1B,KAAK,uBAAuB;YAC1B,OAAO,uBAAuB,CAAC;QACjC,KAAK,qBAAqB,CAAC;QAC3B,KAAK,mBAAmB;YACtB,OAAO,SAAS,CAAC;QACnB;YACE,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC"}
@@ -1,16 +1,6 @@
1
1
  import { Connection } from '@salesforce/core';
2
2
  import { Duration } from '@salesforce/kit';
3
- import { DeployResult } from '@salesforce/source-deploy-retrieve';
4
- import { type AvailableDefinition, type AgentTestStartResponse, type AgentTestStatusResponse, type AgentTestResultsResponse, type TestSpec } from './types.js';
5
- /**
6
- * Events emitted during agent test creation for consumers to listen to and keep track of progress.
7
- */
8
- export declare const AgentTestCreateLifecycleStages: {
9
- CreatingLocalMetadata: string;
10
- Waiting: string;
11
- DeployingMetadata: string;
12
- Done: string;
13
- };
3
+ import { type AgentTestStartResponse, type AgentTestStatusResponse, type AgentTestResultsResponse } from './types.js';
14
4
  /**
15
5
  * A service for testing agents using `AiEvaluationDefinition` metadata. Start asynchronous
16
6
  * test runs, get or poll for test status, and get detailed test results.
@@ -34,13 +24,8 @@ export declare const AgentTestCreateLifecycleStages: {
34
24
  * `const results = await agentTester.results(startResponse.runId);`
35
25
  */
36
26
  export declare class AgentTester {
37
- private connection;
38
27
  private maybeMock;
39
28
  constructor(connection: Connection);
40
- /**
41
- * List the AiEvaluationDefinitions available in the org.
42
- */
43
- list(): Promise<AvailableDefinition[]>;
44
29
  /**
45
30
  * Initiates a test run (i.e., AI evaluation).
46
31
  *
@@ -81,39 +66,7 @@ export declare class AgentTester {
81
66
  cancel(jobId: string): Promise<{
82
67
  success: boolean;
83
68
  }>;
84
- /**
85
- * Creates and deploys an AiEvaluationDefinition from a specification file.
86
- *
87
- * @param apiName - The API name of the AiEvaluationDefinition to create
88
- * @param specFilePath - The path to the specification file to create the definition from
89
- * @param options - Configuration options for creating the definition
90
- * @param options.outputDir - The directory where the AiEvaluationDefinition file will be written
91
- * @param options.preview - If true, writes the AiEvaluationDefinition file to <api-name>-preview-<timestamp>.xml in the current working directory and does not deploy it
92
- *
93
- * @returns Promise containing:
94
- * - path: The filesystem path to the created AiEvaluationDefinition file
95
- * - contents: The AiEvaluationDefinition contents as a string
96
- * - deployResult: The deployment result (if not in preview mode)
97
- *
98
- * @throws {SfError} When deployment fails
99
- */
100
- create(apiName: string, specFilePath: string, options: {
101
- outputDir: string;
102
- preview?: boolean;
103
- }): Promise<{
104
- path: string;
105
- contents: string;
106
- deployResult?: DeployResult;
107
- }>;
108
69
  }
109
- /**
110
- * Convert the raw, detailed test results to another format.
111
- *
112
- * @param results The detailed results from a test run.
113
- * @param format The desired format. One of: json, junit, or tap.
114
- * @returns
115
- */
116
- export declare function convertTestResultsToFormat(results: AgentTestResultsResponse, format: 'json' | 'junit' | 'tap'): Promise<string>;
117
70
  /**
118
71
  * Normalizes test results by decoding HTML entities in utterances and test result values.
119
72
  *
@@ -135,25 +88,3 @@ export declare function convertTestResultsToFormat(results: AgentTestResultsResp
135
88
  * ```
136
89
  */
137
90
  export declare function normalizeResults(results: AgentTestResultsResponse): AgentTestResultsResponse;
138
- export declare function humanFriendlyName(name: string): string;
139
- /**
140
- * Generate a test specification file in YAML format.
141
- * This function takes a test specification object, cleans it by removing undefined and empty string values,
142
- * converts it to YAML format, and writes it to the specified output file.
143
- *
144
- * @param spec - The test specification object to be converted to YAML.
145
- * @param outputFile - The file path where the YAML output should be written.
146
- * @throws {Error} - May throw an error if file operations fail.
147
- * @returns A Promise that resolves when the file has been written.
148
- */
149
- export declare function writeTestSpec(spec: TestSpec, outputFile: string): Promise<void>;
150
- /**
151
- * Generates a TestSpec object from an AI Evaluation Definition XML file.
152
- *
153
- * @param path - The file path to the AI Evaluation Definition XML file.
154
- * @returns Promise that resolves to a TestSpec object containing the parsed evaluation definition data.
155
- * @description Reads and parses an XML file containing AIEvaluationDefinition, converting it into a structured TestSpec format.
156
- *
157
- * @throws {Error} If the file cannot be read or parsed.
158
- */
159
- export declare function generateTestSpecFromAiEvalDefinition(path: string): Promise<TestSpec>;
@@ -6,30 +6,12 @@
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.AgentTester = exports.AgentTestCreateLifecycleStages = void 0;
10
- exports.convertTestResultsToFormat = convertTestResultsToFormat;
9
+ exports.AgentTester = void 0;
11
10
  exports.normalizeResults = normalizeResults;
12
- exports.humanFriendlyName = humanFriendlyName;
13
- exports.writeTestSpec = writeTestSpec;
14
- exports.generateTestSpecFromAiEvalDefinition = generateTestSpecFromAiEvalDefinition;
15
- const promises_1 = require("node:fs/promises");
16
- const node_path_1 = require("node:path");
17
11
  const core_1 = require("@salesforce/core");
18
12
  const kit_1 = require("@salesforce/kit");
19
- const source_deploy_retrieve_1 = require("@salesforce/source-deploy-retrieve");
20
- const yaml_1 = require("yaml");
21
- const fast_xml_parser_1 = require("fast-xml-parser");
22
13
  const maybe_mock_1 = require("./maybe-mock");
23
14
  const utils_1 = require("./utils");
24
- /**
25
- * Events emitted during agent test creation for consumers to listen to and keep track of progress.
26
- */
27
- exports.AgentTestCreateLifecycleStages = {
28
- CreatingLocalMetadata: 'Creating Local Metadata',
29
- Waiting: 'Waiting for the org to respond',
30
- DeployingMetadata: 'Deploying Metadata',
31
- Done: 'Done',
32
- };
33
15
  /**
34
16
  * A service for testing agents using `AiEvaluationDefinition` metadata. Start asynchronous
35
17
  * test runs, get or poll for test status, and get detailed test results.
@@ -53,18 +35,10 @@ exports.AgentTestCreateLifecycleStages = {
53
35
  * `const results = await agentTester.results(startResponse.runId);`
54
36
  */
55
37
  class AgentTester {
56
- connection;
57
38
  maybeMock;
58
39
  constructor(connection) {
59
- this.connection = connection;
60
40
  this.maybeMock = new maybe_mock_1.MaybeMock(connection);
61
41
  }
62
- /**
63
- * List the AiEvaluationDefinitions available in the org.
64
- */
65
- async list() {
66
- return this.connection.metadata.list({ type: 'AiEvaluationDefinition' });
67
- }
68
42
  /**
69
43
  * Initiates a test run (i.e., AI evaluation).
70
44
  *
@@ -154,120 +128,8 @@ class AgentTester {
154
128
  const url = `/einstein/ai-evaluations/runs/${jobId}/cancel`;
155
129
  return this.maybeMock.request('POST', url);
156
130
  }
157
- /**
158
- * Creates and deploys an AiEvaluationDefinition from a specification file.
159
- *
160
- * @param apiName - The API name of the AiEvaluationDefinition to create
161
- * @param specFilePath - The path to the specification file to create the definition from
162
- * @param options - Configuration options for creating the definition
163
- * @param options.outputDir - The directory where the AiEvaluationDefinition file will be written
164
- * @param options.preview - If true, writes the AiEvaluationDefinition file to <api-name>-preview-<timestamp>.xml in the current working directory and does not deploy it
165
- *
166
- * @returns Promise containing:
167
- * - path: The filesystem path to the created AiEvaluationDefinition file
168
- * - contents: The AiEvaluationDefinition contents as a string
169
- * - deployResult: The deployment result (if not in preview mode)
170
- *
171
- * @throws {SfError} When deployment fails
172
- */
173
- async create(apiName, specFilePath, options) {
174
- const parsed = (0, yaml_1.parse)(await (0, promises_1.readFile)(specFilePath, 'utf-8'));
175
- const lifecycle = core_1.Lifecycle.getInstance();
176
- await lifecycle.emit(exports.AgentTestCreateLifecycleStages.CreatingLocalMetadata, {});
177
- const preview = options.preview ?? false;
178
- // outputDir is overridden if preview is true
179
- const outputDir = preview ? process.cwd() : options.outputDir;
180
- const filename = preview
181
- ? `${apiName}-preview-${new Date().toISOString()}.xml`
182
- : `${apiName}.aiEvaluationDefinition-meta.xml`;
183
- const definitionPath = (0, node_path_1.join)(outputDir, filename);
184
- const builder = new fast_xml_parser_1.XMLBuilder({
185
- format: true,
186
- attributeNamePrefix: '$',
187
- indentBy: ' ',
188
- ignoreAttributes: false,
189
- });
190
- const xml = builder.build({
191
- AiEvaluationDefinition: {
192
- $xmlns: 'http://soap.sforce.com/2006/04/metadata',
193
- ...(parsed.description && { description: parsed.description }),
194
- name: parsed.name,
195
- subjectName: parsed.subjectName,
196
- subjectType: parsed.subjectType,
197
- ...(parsed.subjectVersion && { subjectVersion: parsed.subjectVersion }),
198
- testCase: parsed.testCases.map((tc) => ({
199
- expectation: [
200
- {
201
- expectedValue: tc.expectedTopic,
202
- name: 'topic_sequence_match',
203
- },
204
- {
205
- expectedValue: `[${(tc.expectedActions ?? []).map((v) => `"${v}"`).join(',')}]`,
206
- name: 'action_sequence_match',
207
- },
208
- {
209
- expectedValue: tc.expectedOutcome,
210
- name: 'bot_response_rating',
211
- },
212
- ],
213
- inputs: {
214
- utterance: tc.utterance,
215
- },
216
- number: parsed.testCases.indexOf(tc) + 1,
217
- })),
218
- },
219
- });
220
- const finalXml = `<?xml version="1.0" encoding="UTF-8"?>\n${xml}`;
221
- await (0, promises_1.mkdir)(outputDir, { recursive: true });
222
- await (0, promises_1.writeFile)(definitionPath, finalXml);
223
- if (preview)
224
- return {
225
- path: definitionPath,
226
- contents: finalXml,
227
- };
228
- const cs = await source_deploy_retrieve_1.ComponentSetBuilder.build({ sourcepath: [definitionPath] });
229
- const deploy = await cs.deploy({ usernameOrConnection: this.connection });
230
- deploy.onUpdate((status) => {
231
- if (status.status === source_deploy_retrieve_1.RequestStatus.Pending) {
232
- void lifecycle.emit(exports.AgentTestCreateLifecycleStages.Waiting, status);
233
- }
234
- else {
235
- void lifecycle.emit(exports.AgentTestCreateLifecycleStages.DeployingMetadata, status);
236
- }
237
- });
238
- deploy.onFinish((result) => {
239
- // small deploys like this, 1 file, can happen without an 'update' event being fired
240
- // onFinish, emit the update, and then the done event to create proper output
241
- void lifecycle.emit(exports.AgentTestCreateLifecycleStages.DeployingMetadata, result);
242
- void lifecycle.emit(exports.AgentTestCreateLifecycleStages.Done, result);
243
- });
244
- const result = await deploy.pollStatus({ timeout: kit_1.Duration.minutes(10_000), frequency: kit_1.Duration.seconds(1) });
245
- if (!result.response.success) {
246
- throw new core_1.SfError(result.response.errorMessage ?? `Unable to deploy ${result.response.id}`);
247
- }
248
- return { path: definitionPath, contents: finalXml, deployResult: result };
249
- }
250
131
  }
251
132
  exports.AgentTester = AgentTester;
252
- /**
253
- * Convert the raw, detailed test results to another format.
254
- *
255
- * @param results The detailed results from a test run.
256
- * @param format The desired format. One of: json, junit, or tap.
257
- * @returns
258
- */
259
- async function convertTestResultsToFormat(results, format) {
260
- switch (format) {
261
- case 'json':
262
- return jsonFormat(results);
263
- case 'junit':
264
- return junitFormat(results);
265
- case 'tap':
266
- return tapFormat(results);
267
- default:
268
- throw new Error(`Unsupported format: ${format}`);
269
- }
270
- }
271
133
  /**
272
134
  * Normalizes test results by decoding HTML entities in utterances and test result values.
273
135
  *
@@ -304,166 +166,4 @@ function normalizeResults(results) {
304
166
  })),
305
167
  };
306
168
  }
307
- async function jsonFormat(results) {
308
- return Promise.resolve(JSON.stringify(results, null, 2));
309
- }
310
- async function junitFormat(results) {
311
- const builder = new fast_xml_parser_1.XMLBuilder({
312
- format: true,
313
- attributeNamePrefix: '$',
314
- ignoreAttributes: false,
315
- });
316
- const testCount = results.testCases.length;
317
- const failureCount = results.testCases.filter((tc) => ['error', 'completed'].includes(tc.status.toLowerCase()) && tc.testResults.some((r) => r.result === 'FAILURE')).length;
318
- const time = results.testCases.reduce((acc, tc) => {
319
- if (tc.endTime && tc.startTime) {
320
- return acc + new Date(tc.endTime).getTime() - new Date(tc.startTime).getTime();
321
- }
322
- return acc;
323
- }, 0);
324
- const suites = builder.build({
325
- testsuites: {
326
- $name: results.subjectName,
327
- $tests: testCount,
328
- $failures: failureCount,
329
- $time: time,
330
- property: [
331
- { $name: 'status', $value: results.status },
332
- { $name: 'start-time', $value: results.startTime },
333
- { $name: 'end-time', $value: results.endTime },
334
- ],
335
- testsuite: results.testCases.map((testCase) => {
336
- const testCaseTime = testCase.endTime
337
- ? new Date(testCase.endTime).getTime() - new Date(testCase.startTime).getTime()
338
- : 0;
339
- return {
340
- $name: testCase.testNumber,
341
- $time: testCaseTime,
342
- $assertions: testCase.testResults.length,
343
- failure: testCase.testResults
344
- .map((r) => {
345
- if (r.result === 'FAILURE') {
346
- return { $message: r.errorMessage ?? 'Unknown error', $name: r.name };
347
- }
348
- })
349
- .filter((f) => f),
350
- };
351
- }),
352
- },
353
- });
354
- return Promise.resolve(`<?xml version="1.0" encoding="UTF-8"?>\n${suites}`.trim());
355
- }
356
- function humanFriendlyName(name) {
357
- // topic_sequence_match, action_sequence_match, and bot_response_rating have all changed
358
- // eventually we can remove them
359
- switch (name) {
360
- case 'topic_sequence_match':
361
- case 'topic_assertion':
362
- return 'Topic';
363
- case 'action_sequence_match':
364
- case 'actions_assertion':
365
- return 'Action';
366
- case 'output_latency_milliseconds':
367
- return 'Output Latency';
368
- case 'instruction_following':
369
- return 'Instruction Following';
370
- case 'bot_response_rating':
371
- case 'output_validation':
372
- return 'Outcome';
373
- default:
374
- return name;
375
- }
376
- }
377
- async function tapFormat(results) {
378
- const lines = [];
379
- let expectationCount = 0;
380
- for (const testCase of results.testCases) {
381
- for (const result of testCase.testResults) {
382
- const status = result.result === 'PASS' ? 'ok' : 'not ok';
383
- expectationCount++;
384
- lines.push(`${status} ${expectationCount} ${testCase.testNumber}.${result.name}`);
385
- if (status === 'not ok') {
386
- lines.push(' ---');
387
- lines.push(` message: ${result.errorMessage ?? 'Unknown error'}`);
388
- lines.push(` expectation: ${result.name}`);
389
- lines.push(` actual: ${result.actualValue}`);
390
- lines.push(` expected: ${result.expectedValue}`);
391
- lines.push(' ...');
392
- }
393
- }
394
- }
395
- return Promise.resolve(`Tap Version 14\n1..${expectationCount}\n${lines.join('\n')}`);
396
- }
397
- function transformStringToArray(str) {
398
- try {
399
- if (!str)
400
- return [];
401
- // Remove any whitespace and ensure proper JSON format
402
- const cleaned = str.replace(/\s+/g, '');
403
- return JSON.parse(cleaned);
404
- }
405
- catch {
406
- return [];
407
- }
408
- }
409
- function castArray(value) {
410
- return Array.isArray(value) ? value : [value];
411
- }
412
- /**
413
- * Generate a test specification file in YAML format.
414
- * This function takes a test specification object, cleans it by removing undefined and empty string values,
415
- * converts it to YAML format, and writes it to the specified output file.
416
- *
417
- * @param spec - The test specification object to be converted to YAML.
418
- * @param outputFile - The file path where the YAML output should be written.
419
- * @throws {Error} - May throw an error if file operations fail.
420
- * @returns A Promise that resolves when the file has been written.
421
- */
422
- async function writeTestSpec(spec, outputFile) {
423
- // strip out undefined values and empty strings
424
- const clean = Object.entries(spec).reduce((acc, [key, value]) => {
425
- if (value !== undefined && value !== '')
426
- return { ...acc, [key]: value };
427
- return acc;
428
- }, {});
429
- const yml = (0, yaml_1.stringify)(clean, undefined, {
430
- minContentWidth: 0,
431
- lineWidth: 0,
432
- });
433
- await (0, promises_1.mkdir)((0, node_path_1.dirname)(outputFile), { recursive: true });
434
- await (0, promises_1.writeFile)(outputFile, yml);
435
- }
436
- /**
437
- * Generates a TestSpec object from an AI Evaluation Definition XML file.
438
- *
439
- * @param path - The file path to the AI Evaluation Definition XML file.
440
- * @returns Promise that resolves to a TestSpec object containing the parsed evaluation definition data.
441
- * @description Reads and parses an XML file containing AIEvaluationDefinition, converting it into a structured TestSpec format.
442
- *
443
- * @throws {Error} If the file cannot be read or parsed.
444
- */
445
- async function generateTestSpecFromAiEvalDefinition(path) {
446
- const xml = await (0, promises_1.readFile)(path, 'utf-8');
447
- const parser = new fast_xml_parser_1.XMLParser();
448
- const parsed = parser.parse(xml);
449
- return {
450
- name: parsed.AiEvaluationDefinition.name,
451
- description: parsed.AiEvaluationDefinition.description,
452
- subjectType: parsed.AiEvaluationDefinition.subjectType,
453
- subjectName: parsed.AiEvaluationDefinition.subjectName,
454
- subjectVersion: parsed.AiEvaluationDefinition.subjectVersion,
455
- testCases: castArray(parsed.AiEvaluationDefinition.testCase).map((tc) => {
456
- const expectations = castArray(tc.expectation);
457
- return {
458
- utterance: tc.inputs.utterance,
459
- // TODO: remove old names once removed in 258 (topic_sequence_match, action_sequence_match, bot_response_rating)
460
- expectedTopic: expectations.find((e) => e.name === 'topic_sequence_match' || e.name === 'topic_assertion')
461
- ?.expectedValue,
462
- expectedActions: transformStringToArray(expectations.find((e) => e.name === 'action_sequence_match' || e.name === 'actions_assertion')?.expectedValue),
463
- expectedOutcome: expectations.find((e) => e.name === 'bot_response_rating' || e.name === 'output_validation')
464
- ?.expectedValue,
465
- };
466
- }),
467
- };
468
- }
469
169
  //# sourceMappingURL=agentTester.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"agentTester.js","sourceRoot":"","sources":["../src/agentTester.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAoSH,gEAcC;AAsBD,4CAeC;AA4DD,8CAoBC;AAiDD,sCAaC;AAWD,oFAyBC;AAvgBD,+CAA8D;AAC9D,yCAA0C;AAC1C,2CAA+F;AAC/F,yCAA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6 @@
1
1
  export { type AgentCreateConfig, type AgentCreateResponse, type AgentJobSpec, type AgentJobSpecCreateConfig, type AgentOptions, type AgentTone, type AgentType, type AgentPreviewMessageLinks, type AgentPreviewMessage, type AgentPreviewStartResponse, type AgentPreviewSendResponse, type AgentPreviewEndResponse, type DraftAgentTopics, type DraftAgentTopicsBody, type DraftAgentTopicsResponse, type AvailableDefinition, type AgentTestResultsResponse, type AgentTestStartResponse, type AgentTestStatusResponse, type TestCaseResult, type TestStatus, } from './types';
2
2
  export { Agent, AgentCreateLifecycleStages, generateAgentApiName } from './agent';
3
- export { AgentTester, AgentTestCreateLifecycleStages, convertTestResultsToFormat, writeTestSpec, generateTestSpecFromAiEvalDefinition, humanFriendlyName, } from './agentTester';
3
+ export { AgentTester } from './agentTester';
4
+ export { AgentTest, AgentTestCreateLifecycleStages } from './agentTest';
5
+ export { convertTestResultsToFormat, humanFriendlyName } from './agentTestResults';
4
6
  export { AgentPreview } from './agentPreview';
package/lib/index.js CHANGED
@@ -6,18 +6,19 @@
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.AgentPreview = exports.humanFriendlyName = exports.generateTestSpecFromAiEvalDefinition = exports.writeTestSpec = exports.convertTestResultsToFormat = exports.AgentTestCreateLifecycleStages = exports.AgentTester = exports.generateAgentApiName = exports.AgentCreateLifecycleStages = exports.Agent = void 0;
9
+ exports.AgentPreview = exports.humanFriendlyName = exports.convertTestResultsToFormat = exports.AgentTestCreateLifecycleStages = exports.AgentTest = exports.AgentTester = exports.generateAgentApiName = exports.AgentCreateLifecycleStages = exports.Agent = void 0;
10
10
  var agent_1 = require("./agent");
11
11
  Object.defineProperty(exports, "Agent", { enumerable: true, get: function () { return agent_1.Agent; } });
12
12
  Object.defineProperty(exports, "AgentCreateLifecycleStages", { enumerable: true, get: function () { return agent_1.AgentCreateLifecycleStages; } });
13
13
  Object.defineProperty(exports, "generateAgentApiName", { enumerable: true, get: function () { return agent_1.generateAgentApiName; } });
14
14
  var agentTester_1 = require("./agentTester");
15
15
  Object.defineProperty(exports, "AgentTester", { enumerable: true, get: function () { return agentTester_1.AgentTester; } });
16
- Object.defineProperty(exports, "AgentTestCreateLifecycleStages", { enumerable: true, get: function () { return agentTester_1.AgentTestCreateLifecycleStages; } });
17
- Object.defineProperty(exports, "convertTestResultsToFormat", { enumerable: true, get: function () { return agentTester_1.convertTestResultsToFormat; } });
18
- Object.defineProperty(exports, "writeTestSpec", { enumerable: true, get: function () { return agentTester_1.writeTestSpec; } });
19
- Object.defineProperty(exports, "generateTestSpecFromAiEvalDefinition", { enumerable: true, get: function () { return agentTester_1.generateTestSpecFromAiEvalDefinition; } });
20
- Object.defineProperty(exports, "humanFriendlyName", { enumerable: true, get: function () { return agentTester_1.humanFriendlyName; } });
16
+ var agentTest_1 = require("./agentTest");
17
+ Object.defineProperty(exports, "AgentTest", { enumerable: true, get: function () { return agentTest_1.AgentTest; } });
18
+ Object.defineProperty(exports, "AgentTestCreateLifecycleStages", { enumerable: true, get: function () { return agentTest_1.AgentTestCreateLifecycleStages; } });
19
+ var agentTestResults_1 = require("./agentTestResults");
20
+ Object.defineProperty(exports, "convertTestResultsToFormat", { enumerable: true, get: function () { return agentTestResults_1.convertTestResultsToFormat; } });
21
+ Object.defineProperty(exports, "humanFriendlyName", { enumerable: true, get: function () { return agentTestResults_1.humanFriendlyName; } });
21
22
  var agentPreview_1 = require("./agentPreview");
22
23
  Object.defineProperty(exports, "AgentPreview", { enumerable: true, get: function () { return agentPreview_1.AgentPreview; } });
23
24
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAyBH,iCAAkF;AAAzE,8FAAA,KAAK,OAAA;AAAE,mHAAA,0BAA0B,OAAA;AAAE,6GAAA,oBAAoB,OAAA;AAChE,6CAOuB;AANrB,0GAAA,WAAW,OAAA;AACX,6HAAA,8BAA8B,OAAA;AAC9B,yHAAA,0BAA0B,OAAA;AAC1B,4GAAA,aAAa,OAAA;AACb,mIAAA,oCAAoC,OAAA;AACpC,gHAAA,iBAAiB,OAAA;AAEnB,+CAA8C;AAArC,4GAAA,YAAY,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAyBH,iCAAkF;AAAzE,8FAAA,KAAK,OAAA;AAAE,mHAAA,0BAA0B,OAAA;AAAE,6GAAA,oBAAoB,OAAA;AAChE,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AACpB,yCAAwE;AAA/D,sGAAA,SAAS,OAAA;AAAE,2HAAA,8BAA8B,OAAA;AAClD,uDAAmF;AAA1E,8HAAA,0BAA0B,OAAA;AAAE,qHAAA,iBAAiB,OAAA;AACtD,+CAA8C;AAArC,4GAAA,YAAY,OAAA"}
package/lib/types.d.ts CHANGED
@@ -189,6 +189,24 @@ export type DraftAgentTopicsResponse = {
189
189
  errorMessage?: string;
190
190
  topicDrafts: DraftAgentTopics;
191
191
  };
192
+ export type AgentTestConfig = {
193
+ /**
194
+ * The API name of a AiEvaluationDefinition.
195
+ */
196
+ name?: string;
197
+ /**
198
+ * The local file path of a AiEvaluationDefinition metadata file.
199
+ */
200
+ mdPath?: string;
201
+ /**
202
+ * The local file path of an agent test spec file.
203
+ */
204
+ specPath?: string;
205
+ /**
206
+ * The agent test spec data.
207
+ */
208
+ specData?: TestSpec;
209
+ };
192
210
  export type TestStatus = 'NEW' | 'IN_PROGRESS' | 'COMPLETED' | 'ERROR' | 'TERMINATED';
193
211
  export type AgentTestStartResponse = {
194
212
  runId: string;
@@ -246,28 +264,26 @@ export type TestCase = {
246
264
  export type TestSpec = {
247
265
  name: string;
248
266
  description?: string;
249
- subjectType: string;
267
+ subjectType: 'AGENT';
250
268
  subjectName: string;
251
269
  subjectVersion?: string;
252
270
  testCases: TestCase[];
253
271
  };
254
272
  export type AiEvaluationDefinition = {
255
- AiEvaluationDefinition: {
256
- description?: string;
257
- name: string;
258
- subjectType: 'AGENT';
259
- subjectName: string;
260
- subjectVersion?: string;
261
- testCase: Array<{
262
- expectation: Array<{
263
- name: string;
264
- expectedValue: string;
265
- }>;
266
- inputs: {
267
- utterance: string;
268
- };
273
+ description?: string;
274
+ name: string;
275
+ subjectType: 'AGENT';
276
+ subjectName: string;
277
+ subjectVersion?: string;
278
+ testCase: Array<{
279
+ expectation: Array<{
280
+ name: string;
281
+ expectedValue: string;
269
282
  }>;
270
- };
283
+ inputs: {
284
+ utterance: string;
285
+ };
286
+ }>;
271
287
  };
272
288
  export type ApiStatus = {
273
289
  status: 'UP' | 'DOWN';
@@ -0,0 +1,11 @@
1
+ # invalidAgentTestConfig
2
+
3
+ Must provide one of: [ name, mdPath, specPath, specData ] when instantiating an AgentTest.
4
+
5
+ # missingConnection
6
+
7
+ Must provide an org connection to get agent test data based on an AiEvaluationDefinition API name.
8
+
9
+ # missingTestSpecData
10
+
11
+ The agent test is missing the required data to provide a test spec.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@salesforce/agents",
3
3
  "description": "Client side APIs for working with Salesforce agents",
4
- "version": "0.14.5",
4
+ "version": "0.14.6",
5
5
  "license": "BSD-3-Clause",
6
6
  "author": "Salesforce",
7
7
  "main": "lib/index",