@salesforce/agents
Version:
Client side APIs for working with Salesforce agents
80 lines (79 loc) • 3.22 kB
TypeScript
import { Connection } from '@salesforce/core';
import { AgentPreviewBase } from './agentPreviewBase';
import { type AgentPreviewEndResponse, type AgentPreviewSendResponse, type AgentPreviewStartResponse, PlannerResponse } from './types.js';
/**
* A service to simulate interactions with an agent using a local .agent file.
* The file will be compiled using Agent.compileAgent before being used
* with the simulation endpoints.
*
* **Examples**
*
* Create an instance of the service:
*
* `const agentSimulate = new AgentSimulate(connection, './path/to/agent.agent');`
*
* Start an interactive session:
*
* `const { sessionId } = await agentSimulate.start();`
*
* Send a message to the agent using the session ID from the startResponse:
*
* `const sendResponse = await agentSimulate.send(sessionId, message);`
*
* End an interactive session:
*
* `await agentSimulate.end(sessionId, 'UserRequest');`
*
* Enable Apex Debug Mode:
*
* `agentSimulate.toggleApexDebugMode(true);`
*/
export declare class AgentSimulate extends AgentPreviewBase {
/**
* The client can specify whether the actions will run in a simulated mode ("mock actions", no side effects, mockActions=true) or a non-simulated mode ("real actions", actions with side effects, mockActions=false)
*/
mockActions: boolean;
protected readonly apiBase: string;
private readonly agentFilePath;
private compiledAgent?;
/**
* Create an instance of the service.
*
* @param connection The connection to use to make requests.
* @param agentFilePath Path to the .agent file to simulate.
* @param mockActions whether or not to mock the actions of the simulated agent
*/
constructor(connection: Connection, agentFilePath: string, mockActions: boolean);
/**
* Start an interactive simulation session with the agent.
* This will first compile the agent script if it hasn't been compiled yet.
*
* @returns `AgentPreviewStartResponse`, which includes a session ID needed for other actions.
*/
start(): Promise<AgentPreviewStartResponse>;
/**
* Send a message to the agent using the session ID obtained by calling `start()`.
*
* @param sessionId A session ID provided by first calling `agentSimulate.start()`.
* @param message A message to send to the agent.
* @returns `AgentPreviewSendResponse`
*/
send(sessionId: string, message: string): Promise<AgentPreviewSendResponse>;
/**
* Ending is not required, or supported, for AgentSimulation
* this is a noop method to support easier consumer typings
*
* @returns `AgentPreviewEndResponse`
*/
end(): Promise<AgentPreviewEndResponse>;
/**
* Enable or disable Apex Debug Mode, which will enable trace flags for the Bot user
* and create apex debug logs for use within VS Code's Apex Replay Debugger.
*
* @param enable Whether to enable or disable Apex Debug Mode.
*/
toggleApexDebugMode(enable: boolean): void;
trace(sessionId: string, messageId: string): Promise<PlannerResponse | null>;
traces(sessionId: string, messageIds: string[]): Promise<PlannerResponse[]>;
private ensureTraceFlag;
}