@salesforce/agents
Version:
Client side APIs for working with Salesforce agents
60 lines (59 loc) • 2.1 kB
TypeScript
import { Connection } from '@salesforce/core';
import { type AgentPreviewEndResponse, type AgentPreviewStartResponse, type AgentPreviewSendResponse, type ApiStatus, type EndReason } 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);`
*
* Start an interactive session:
*
* `const { sessionId } = await agentPreview.start(botId);`
*
* 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');`
*/
export declare class AgentPreview {
private apiBase;
private instanceUrl;
private maybeMock;
constructor(connection: Connection);
/**
* Start an interactive session with the provided agent.
*
* @param botId The ID of the agent (`Bot` ID).
* @returns `AgentPreviewStartResponse`, which includes a session ID needed for other actions.
*/
start(botId: string): 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>;
}