Skip to content

Commit 29983c2

Browse files
committed
fix: add agent test cancel
1 parent a76728f commit 29983c2

File tree

6 files changed

+129
-10
lines changed

6 files changed

+129
-10
lines changed

command-snapshot.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@
2626
],
2727
"plugin": "@salesforce/plugin-agent"
2828
},
29+
{
30+
"alias": [],
31+
"command": "agent:test:cancel",
32+
"flagAliases": [],
33+
"flagChars": ["i", "o", "r"],
34+
"flags": ["flags-dir", "job-id", "json", "target-org", "use-most-recent"],
35+
"plugin": "@salesforce/plugin-agent"
36+
},
2937
{
3038
"alias": [],
3139
"command": "agent:test:run",

messages/agent.test.cancel.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# summary
2+
3+
Cancel a running test for an Agent.
4+
5+
# description
6+
7+
Cancel a running test for an Agent, providing the AiEvaluation ID.
8+
9+
# flags.id.summary
10+
11+
The AiEvaluation ID.
12+
13+
# flags.use-most-recent.summary
14+
15+
Use the job ID of the most recent test evaluation.
16+
17+
# examples
18+
19+
- Cancel a test for an Agent:
20+
21+
<%= config.bin %> <%= command.id %> --id AiEvalId

schemas/agent-test-cancel.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$ref": "#/definitions/AgentTestCancelResult",
4+
"definitions": {
5+
"AgentTestCancelResult": {
6+
"type": "object",
7+
"properties": {
8+
"jobId": {
9+
"type": "string"
10+
},
11+
"success": {
12+
"type": "boolean"
13+
},
14+
"errorCode": {
15+
"type": "string"
16+
},
17+
"message": {
18+
"type": "string"
19+
}
20+
},
21+
"required": ["jobId", "success"],
22+
"additionalProperties": false
23+
}
24+
}
25+
}

schemas/agent-test-run.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
55
"AgentTestRunResult": {
66
"type": "object",
77
"properties": {
8-
"buildVersion": {
9-
"type": "number"
10-
},
118
"jobId": {
129
"type": "string"
1310
},
14-
"errorRepresentation": {
11+
"success": {
12+
"type": "boolean"
13+
},
14+
"errorCode": {
15+
"type": "string"
16+
},
17+
"message": {
1518
"type": "string"
1619
}
1720
},
18-
"required": ["buildVersion", "jobId"],
21+
"required": ["jobId", "success"],
1922
"additionalProperties": false
2023
}
2124
}

src/commands/agent/test/cancel.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2024, salesforce.com, inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
9+
import { Messages } from '@salesforce/core';
10+
11+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
12+
const messages = Messages.loadMessages('@salesforce/plugin-agent', 'agent.test.cancel');
13+
14+
export type AgentTestCancelResult = {
15+
jobId: string; // AiEvaluation.Id
16+
success: boolean;
17+
errorCode?: string;
18+
message?: string;
19+
};
20+
21+
export default class AgentTestCancel extends SfCommand<AgentTestCancelResult> {
22+
public static readonly summary = messages.getMessage('summary');
23+
public static readonly description = messages.getMessage('description');
24+
public static readonly examples = messages.getMessages('examples');
25+
26+
public static readonly flags = {
27+
'target-org': Flags.requiredOrg(),
28+
'job-id': Flags.string({
29+
char: 'i',
30+
required: true,
31+
summary: messages.getMessage('flags.id.summary'),
32+
}),
33+
'use-most-recent': Flags.boolean({
34+
char: 'r',
35+
summary: messages.getMessage('flags.use-most-recent.summary'),
36+
exactlyOne: ['use-most-recent', 'job-id'],
37+
}),
38+
//
39+
// Future flags:
40+
// ??? api-version ???
41+
};
42+
43+
public async run(): Promise<AgentTestCancelResult> {
44+
const { flags } = await this.parse(AgentTestCancel);
45+
46+
this.log(`Canceling tests for AiEvaluation Job: ${flags['job-id']}`);
47+
48+
// Call SF Eval Connect API passing AiEvaluation.Id
49+
// POST to /einstein/ai-evaluations/{aiEvaluationId}/stop
50+
51+
// Returns: AiEvaluation.Id
52+
53+
return {
54+
success: true,
55+
jobId: '4KBSM000000003F4AQ', // AiEvaluation.Id
56+
};
57+
}
58+
}

src/commands/agent/test/run.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
1212
const messages = Messages.loadMessages('@salesforce/plugin-agent', 'agent.test.run');
1313

1414
export type AgentTestRunResult = {
15-
buildVersion: number;
16-
jobId: string;
17-
errorRepresentation?: string;
15+
jobId: string; // AiEvaluation.Id
16+
success: boolean;
17+
errorCode?: string;
18+
message?: string;
1819
};
1920

2021
export default class AgentTestRun extends SfCommand<AgentTestRunResult> {
@@ -56,10 +57,13 @@ export default class AgentTestRun extends SfCommand<AgentTestRunResult> {
5657
this.log(`Starting tests for AiEvalDefinitionVersion: ${flags.id}`);
5758

5859
// Call SF Eval Connect API passing AiEvalDefinitionVersion.Id
60+
// POST to /einstein/ai-evaluations/{aiEvalDefinitionVersionId}/start
61+
62+
// Returns: AiEvaluation.Id
5963

6064
return {
61-
buildVersion: 62.0, // looks like API version
62-
jobId: '4KBSM000000003F4AQ', // evaluationJobId; needed for getting status and stopping
65+
success: true,
66+
jobId: '4KBSM000000003F4AQ', // AiEvaluation.Id; needed for getting status and stopping
6367
};
6468
}
6569
}

0 commit comments

Comments
 (0)