@salesforce/agents
Version:
Client side APIs for working with Salesforce agents
147 lines (146 loc) • 5.07 kB
TypeScript
import { Connection, SfProject } from '@salesforce/core';
import { type AgentCreateConfig, type AgentCreateResponse, type AgentJson, type AgentJobSpec, type AgentJobSpecCreateConfig, type AgentOptions, type BotMetadata, type BotVersionMetadata, type CompileAgentScriptResponse, AgentScriptContent, PublishAgent, ExtendedAgentJobSpec } from './types.js';
/**
* 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 within an org. 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 = new Agent({connection, name}).getId();`
*
* 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 {
private options;
private id?;
private name?;
private botMetadata?;
/**
* Create an instance of an agent in an org. Must provide a connection to an org
* and the agent (Bot) API name or ID as part of `AgentOptions`.
*
* @param options
*/
constructor(options: AgentOptions);
/**
* 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[]>;
/**
* 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>;
/**
* Creates an AiAuthoringBundle directory, .script file, and -meta.xml file
*
* @returns Promise<void>
* @beta
* @param options {
* connection: Connection;
* project: SfProject;
* bundleApiName: string;
* outputDir?: string;
* agentSpec?: ExtendedAgentJobSpec;
*}
*/
static createAuthoringBundle(options: {
connection: Connection;
project: SfProject;
bundleApiName: string;
outputDir?: string;
agentSpec?: ExtendedAgentJobSpec;
}): Promise<void>;
/**
* Compiles AgentScript returning agent JSON when successful, otherwise the compile errors are returned.
*
* @param connection The connection to the org
* @param agentScriptContent The AgentScriptContent to compile
* @returns Promise<CompileAgentScriptResponse> The raw API response
* @beta
*/
static compileAgentScript(connection: Connection, agentScriptContent: AgentScriptContent): Promise<CompileAgentScriptResponse>;
/**
* Publish an AgentJson representation to the org
*
* @beta
* @param {Connection} connection The connection to the org
* @param {SfProject} project The Salesforce project
* @param {AgentJson} agentJson The agent JSON with name
* @returns {Promise<PublishAgentJsonResponse>} The publish response
*/
static publishAgentJson(connection: Connection, project: SfProject, agentJson: AgentJson): Promise<PublishAgent>;
/**
* Returns the ID for this agent.
*
* @returns The ID of the agent (The `Bot` ID).
*/
getId(): Promise<string>;
/**
* Queries BotDefinition and BotVersions (limited to 10) for the bot metadata and assigns:
* 1. this.id
* 2. this.name
* 3. this.botMetadata
* 4. this.botVersionMetadata
*/
getBotMetadata(): Promise<BotMetadata>;
/**
* Returns the latest bot version metadata.
*
* @returns the latest bot version metadata
*/
getLatestBotVersionMetadata(): Promise<BotVersionMetadata>;
/**
* Activates the agent.
*
* @returns void
*/
activate(): Promise<void>;
/**
* Deactivates the agent.
*
* @returns void
*/
deactivate(): Promise<void>;
private setAgentStatus;
}
export declare const decodeResponse: <T>(response: T) => T;