UNPKG

@salesforce/agents

Version:

Client side APIs for working with Salesforce agents

79 lines (78 loc) 2.81 kB
import { Connection } from '@salesforce/core'; import { AgentPreviewBase } from './agentPreviewBase'; import { type AgentPreviewStartResponse, type AgentPreviewSendResponse, type AgentPreviewEndResponse, type ApiStatus, type EndReason, PlannerResponse } from './types.js'; /** * A service to interact with an agent. Start an interactive session, * send messages to the agent, and end the session. * * **Examples** * * Create an instance of the service: * * `const agentPreview = new AgentPreview(connection, botId);` * * Start an interactive session: * * `const { sessionId } = await agentPreview.start();` * * Send a message to the agent using the session ID from the startResponse: * * `const sendResponse = await agentPreview.send(sessionId, message);` * * End an interactive session: * * `await agentPreview.end(sessionId, 'UserRequest');` * * Enable Apex Debug Mode: * * `agentPreview.toggleApexDebugMode(true);` */ export declare class AgentPreview extends AgentPreviewBase { protected readonly apiBase: string; private readonly botId; /** * Create an instance of the service. * * @param connection The connection to use to make requests. * @param botId The ID of the agent (`Bot` ID). */ constructor(connection: Connection, botId: string); /** * Start an interactive session with the agent. * * @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 `agentPreview.start()`. * @param message A message to send to the agent. * @returns `AgentPreviewSendResponse` */ send(sessionId: string, message: string): Promise<AgentPreviewSendResponse>; /** * Ends an interactive session with the agent. * * @param sessionId A session ID provided by first calling `agentPreview.start()`. * @param reason A reason why the interactive session was ended. * @returns `AgentPreviewEndResponse` */ end(sessionId: string, reason: EndReason): Promise<AgentPreviewEndResponse>; /** * Get the status of the Agent API (UP | DOWN). * * @returns `ApiStatus` */ status(): Promise<ApiStatus>; /** * 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 `AgentPreviewEndResponse` */ traces(sessionId: string, messageIds: string[]): Promise<PlannerResponse[]>; private getBotUserId; private ensureTraceFlag; }