Skip to content

Commit

Permalink
fix: add agent test cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
shetzel committed Oct 31, 2024
1 parent a76728f commit 29983c2
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 10 deletions.
8 changes: 8 additions & 0 deletions command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
],
"plugin": "@salesforce/plugin-agent"
},
{
"alias": [],
"command": "agent:test:cancel",
"flagAliases": [],
"flagChars": ["i", "o", "r"],
"flags": ["flags-dir", "job-id", "json", "target-org", "use-most-recent"],
"plugin": "@salesforce/plugin-agent"
},
{
"alias": [],
"command": "agent:test:run",
Expand Down
21 changes: 21 additions & 0 deletions messages/agent.test.cancel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# summary

Cancel a running test for an Agent.

# description

Cancel a running test for an Agent, providing the AiEvaluation ID.

# flags.id.summary

The AiEvaluation ID.

# flags.use-most-recent.summary

Use the job ID of the most recent test evaluation.

# examples

- Cancel a test for an Agent:

<%= config.bin %> <%= command.id %> --id AiEvalId
25 changes: 25 additions & 0 deletions schemas/agent-test-cancel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/AgentTestCancelResult",
"definitions": {
"AgentTestCancelResult": {
"type": "object",
"properties": {
"jobId": {
"type": "string"
},
"success": {
"type": "boolean"
},
"errorCode": {
"type": "string"
},
"message": {
"type": "string"
}
},
"required": ["jobId", "success"],
"additionalProperties": false
}
}
}
13 changes: 8 additions & 5 deletions schemas/agent-test-run.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
"AgentTestRunResult": {
"type": "object",
"properties": {
"buildVersion": {
"type": "number"
},
"jobId": {
"type": "string"
},
"errorRepresentation": {
"success": {
"type": "boolean"
},
"errorCode": {
"type": "string"
},
"message": {
"type": "string"
}
},
"required": ["buildVersion", "jobId"],
"required": ["jobId", "success"],
"additionalProperties": false
}
}
Expand Down
58 changes: 58 additions & 0 deletions src/commands/agent/test/cancel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2024, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-agent', 'agent.test.cancel');

export type AgentTestCancelResult = {
jobId: string; // AiEvaluation.Id
success: boolean;
errorCode?: string;
message?: string;
};

export default class AgentTestCancel extends SfCommand<AgentTestCancelResult> {
public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessages('examples');

public static readonly flags = {
'target-org': Flags.requiredOrg(),
'job-id': Flags.string({
char: 'i',
required: true,
summary: messages.getMessage('flags.id.summary'),
}),
'use-most-recent': Flags.boolean({
char: 'r',
summary: messages.getMessage('flags.use-most-recent.summary'),
exactlyOne: ['use-most-recent', 'job-id'],
}),
//
// Future flags:
// ??? api-version ???
};

public async run(): Promise<AgentTestCancelResult> {
const { flags } = await this.parse(AgentTestCancel);

this.log(`Canceling tests for AiEvaluation Job: ${flags['job-id']}`);

// Call SF Eval Connect API passing AiEvaluation.Id
// POST to /einstein/ai-evaluations/{aiEvaluationId}/stop

// Returns: AiEvaluation.Id

return {
success: true,
jobId: '4KBSM000000003F4AQ', // AiEvaluation.Id
};
}
}
14 changes: 9 additions & 5 deletions src/commands/agent/test/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-agent', 'agent.test.run');

export type AgentTestRunResult = {
buildVersion: number;
jobId: string;
errorRepresentation?: string;
jobId: string; // AiEvaluation.Id
success: boolean;
errorCode?: string;
message?: string;
};

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

// Call SF Eval Connect API passing AiEvalDefinitionVersion.Id
// POST to /einstein/ai-evaluations/{aiEvalDefinitionVersionId}/start

// Returns: AiEvaluation.Id

return {
buildVersion: 62.0, // looks like API version
jobId: '4KBSM000000003F4AQ', // evaluationJobId; needed for getting status and stopping
success: true,
jobId: '4KBSM000000003F4AQ', // AiEvaluation.Id; needed for getting status and stopping
};
}
}

0 comments on commit 29983c2

Please sign in to comment.