@salesforce/agents
Version:
Client side APIs for working with Salesforce agents
60 lines (59 loc) • 2.62 kB
TypeScript
import { Connection, Logger } from '@salesforce/core';
import { MaybeMock } from './maybe-mock';
import { type AgentPreviewEndResponse, type AgentPreviewStartResponse, type AgentPreviewSendResponse, type EndReason, type BaseAgentConfig, type AgentInteractionBase, PlannerResponse } from './types.js';
/**
* Abstract base class for agent runners that provides common functionality
* for interacting with agents through the Einstein AI Agent API.
*/
export declare abstract class AgentPreviewBase implements AgentInteractionBase {
protected connection: Connection;
protected apexTraceFlag?: {
Id?: string;
ExpirationDate?: string;
};
protected readonly logger: Logger;
protected readonly maybeMock: MaybeMock;
protected apexDebugMode?: boolean;
protected constructor(config: BaseAgentConfig);
/**
* Get the base API URL for the agent service.
* This is overridden by child classes to provide their specific API base.
*/
protected abstract get apiBase(): string;
/**
* 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.
*/
setApexDebugMode(enable: boolean): void;
/**
* Start an interactive session with the agent.
* This is implemented by child classes to provide their specific start logic.
*/
abstract 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 `start()`.
* @param message A message to send to the agent.
* @returns `AgentPreviewSendResponse`
*/
abstract send(sessionId: string, message: string): Promise<AgentPreviewSendResponse>;
/**
* Ends an interactive session with the agent.
*
* @param sessionId A session ID provided by first calling `start()`.
* @param reason A reason why the interactive session was ended.
* @returns `AgentPreviewEndResponse`
*/
abstract end(sessionId: string, reason: EndReason): Promise<AgentPreviewEndResponse>;
/**
* Get the traces for a given session and message IDs.
*
* @param sessionId A session ID provided by first calling `start()`.
* @param messageIds An array of message IDs to get the traces for.
* @returns `PlannerResponse[]`
*/
abstract traces(sessionId: string, messageIds: string[]): Promise<PlannerResponse[]>;
}