@salesforce/agents
Version:
Client side APIs for working with Salesforce agents
88 lines (87 loc) • 3.52 kB
TypeScript
import { Connection, SfProject } from '@salesforce/core';
import { type AgentCreateConfig, type AgentCreateResponse, type AgentJobSpec, type AgentJobSpecCreateConfig, type BotMetadata, PreviewableAgent, ProductionAgentOptions, ScriptAgentOptions } from './types';
import { ScriptAgent } from './agents/scriptAgent';
import { ProductionAgent } from './agents/productionAgent';
/** Instance type returned from Agent.init(); has setSessionId, getHistoryDir, preview, etc. */
export type AgentInstance = ScriptAgent | ProductionAgent;
/**
* Events emitted during Agent.create() for consumers to listen to and keep track of progress
*
* @type {{Creating: string, Previewing: string, Retrieving: string}}
*/
export declare const AgentCreateLifecycleStages: {
Creating: string;
Previewing: string;
Retrieving: string;
};
/**
* A client side representation of an agent. Also provides utilities
* such as creating agents, listing agents, and creating agent specs.
*
* **Examples**
*
* Create a new instance and get the ID (uses the `Bot` ID):
*
* `const id = await Agent.init({connection, project, apiNameOrId: 'myBot' }).getId();`
*
* Create a new instance of an agent script based agent
*
* const agent = await Agent.init({connection, project, aabName: 'myBot' });
*
* Start a preview session
*
* const agent = await Agent.init({connection, project, aabName: 'myBot' });
* await agent.preview.start();
* await agent.preview.send('hi there');
*
* Create a new agent in the org:
*
* `const myAgent = await Agent.create(connection, project, options);`
*
* List all agents in the local project:
*
* `const agentList = await Agent.list(project);`
*/
export declare class Agent {
static init(options: ScriptAgentOptions): Promise<ScriptAgent>;
static init(options: ProductionAgentOptions): Promise<ProductionAgent>;
/**
* List all agents in the current project.
*
* @param project a `SfProject` for a local DX project.
*/
static list(project: SfProject): Promise<string[]>;
/**
* Lists all agents in the org.
*
* @param connection a `Connection` to an org.
* @returns the list of agents
*/
static listRemote(connection: Connection): Promise<BotMetadata[]>;
/**
* Lists all agents available for preview, combining agents from the org and local script files.
*
* @param connection a `Connection` to an org.
* @param project a `SfProject` for a local DX project.
* @returns the list of previewable agents with their source (org or script)
*/
static listPreviewable(connection: Connection, project: SfProject): Promise<PreviewableAgent[]>;
/**
* Creates an agent from a configuration, optionally saving the agent in an org.
*
* @param connection a `Connection` to an org.
* @param project a `SfProject` for a local DX project.
* @param config a configuration for creating or previewing an agent.
* @returns the agent definition
*/
static create(connection: Connection, project: SfProject, config: AgentCreateConfig): Promise<AgentCreateResponse>;
/**
* Create an agent spec from provided data.
*
* @param connection a `Connection` to an org.
* @param config The configuration used to generate an agent spec.
* @returns the agent job spec
*/
static createSpec(connection: Connection, config: AgentJobSpecCreateConfig): Promise<AgentJobSpec>;
}
export declare const decodeResponse: <T>(response: T) => T;