UNPKG

@salesforce/agents

Version:

Client side APIs for working with Salesforce agents

91 lines (90 loc) 2.81 kB
import { Connection } from '@salesforce/core'; import { Duration } from '@salesforce/kit'; import { type AgentTestStartResponse, type AgentTestStatusResponse, type AgentTestResultsResponse } from './types.js'; /** * A service for testing agents using `AiEvaluationDefinition` metadata. Start asynchronous * test runs, get or poll for test status, and get detailed test results. * * **Examples** * * Create an instance of the service: * * `const agentTester = new AgentTester(connection);` * * Start a test run: * * `const startResponse = await agentTester.start(aiEvalDef);` * * Get the status for a test run: * * `const status = await agentTester.status(startResponse.runId);` * * Get detailed results for a test run: * * `const results = await agentTester.results(startResponse.runId);` */ export declare class AgentTester { private maybeMock; constructor(connection: Connection); /** * Initiates a test run (i.e., AI evaluation). * * @param aiEvalDefName - The name of the AI evaluation definition to run. * @returns Promise that resolves with the response from starting the test. */ start(aiEvalDefName: string): Promise<AgentTestStartResponse>; /** * Get the status of a test run. * * @param {string} jobId * @returns {Promise<AgentTestStatusResponse>} */ status(jobId: string): Promise<AgentTestStatusResponse>; /** * Poll the status of a test run until the tests are complete or the timeout is reached. * * @param {string} jobId * @param {Duration} timeout * @returns {Promise<AgentTestResultsResponse>} */ poll(jobId: string, { timeout, }?: { timeout?: Duration; }): Promise<AgentTestResultsResponse>; /** * Get detailed test run results. * * @param {string} jobId * @returns {Promise<AgentTestResultsResponse>} */ results(jobId: string): Promise<AgentTestResultsResponse>; /** * Cancel an in-progress test run. * * @param {string} jobId * @returns {Promise<{success: boolean}>} */ cancel(jobId: string): Promise<{ success: boolean; }>; } /** * Normalizes test results by decoding HTML entities in utterances and test result values. * * @param results - The agent test results response object to normalize * @returns A new AgentTestResultsResponse with decoded HTML entities * * @example * ``` * const results = { * testCases: [{ * inputs: { utterance: "&quot;hello&quot;" }, * testResults: [{ * actualValue: "&amp;test", * expectedValue: "&lt;value&gt;" * }] * }] * }; * const normalized = normalizeResults(results); * ``` */ export declare function normalizeResults(results: AgentTestResultsResponse): AgentTestResultsResponse;