@salesforce/agentforce-conversation-client
v1.122.2
Published
Agentforce Conversation Client SDK for embedding via Lightning Out 2.0
Maintainers
Keywords
Readme
@salesforce/agentforce-conversation-client(Beta)
Beta: This package is currently in beta. APIs and behavior may change in future releases.
The Agentforce Conversation Client SDK enables embedding the Agentforce chat experience for employee agents into external applications.
Overview
This library embeds the Agentforce Conversation Client for employee agents using Lightning Out 2.0.
Prerequisites
- One of
salesforceOriginorfrontdoorUrlis required. - Use
salesforceOriginwhen your app is hosted inside a Salesforce org and already has an authenticated session. - Use
frontdoorUrlwhen embedding the chat client outside Salesforce (for example, a localhost or external app). - Lightning Out 2.0 uses an existing session to initialize; without it, the embed will fail to start.
Installation
npm install @salesforce/agentforce-conversation-clientUsage
Basic Embedding
import { embedAgentforceClient } from "@salesforce/agentforce-conversation-client";
const { loApp, chatClientComponent } = embedAgentforceClient({
container: "#agentforce-container",
salesforceOrigin: "https://myorg.my.salesforce.com",
});With agentId and agentLabel
import { embedAgentforceClient } from "@salesforce/agentforce-conversation-client";
const { loApp, chatClientComponent } = embedAgentforceClient({
container: "#agentforce-container",
salesforceOrigin: "https://myorg.my.salesforce.com",
agentforceClientConfig: {
agentId: "AGENT_ID_FROM_ORG",
agentLabel: "My Agent",
},
});With rendering modes
import { embedAgentforceClient } from "@salesforce/agentforce-conversation-client";
// Floating (default)
embedAgentforceClient({
container: "#agentforce-container",
salesforceOrigin: "https://myorg.my.salesforce.com",
agentforceClientConfig: {
renderingConfig: { mode: "floating", showHeaderIcon: true },
},
});
// Inline (width/height configurable)
// The parent container must have an explicit height for inline mode to fill properly.
embedAgentforceClient({
container: "#agentforce-container",
salesforceOrigin: "https://myorg.my.salesforce.com",
agentforceClientConfig: {
renderingConfig: { mode: "inline", width: 420, height: 600 },
},
});
// Inline filling the parent container
embedAgentforceClient({
container: "#agentforce-container",
salesforceOrigin: "https://myorg.my.salesforce.com",
agentforceClientConfig: {
renderingConfig: { mode: "inline", width: "100%", height: "100%" },
},
});Header visibility (headerEnabled)
In inline mode, the header is hidden by default. Set headerEnabled: true to show it. In floating mode, the header is always visible regardless of this setting.
embedAgentforceClient({
container: "#agentforce-container",
salesforceOrigin: "https://myorg.my.salesforce.com",
agentforceClientConfig: {
agentLabel: "My Agent",
renderingConfig: {
mode: "inline",
width: "100%",
height: "100%",
headerEnabled: true,
},
},
});Show Agentforce header icon (showHeaderIcon)
By default, the header icon is hidden when showHeaderIcon is not set.
import { embedAgentforceClient } from "@salesforce/agentforce-conversation-client";
embedAgentforceClient({
container: "#agentforce-container",
salesforceOrigin: "https://myorg.my.salesforce.com",
agentforceClientConfig: {
renderingConfig: {
mode: "floating",
showHeaderIcon: true, // set false (or omit) to hide the header icon
},
},
});Theming with styleTokens
Use agentforceClientConfig.styleTokens to theme the Agentforce Conversation Client. You do not need to provide all tokens—only the ones you want to override. Tokens are grouped by UI area:
Example
import { embedAgentforceClient } from "@salesforce/agentforce-conversation-client";
const { loApp, chatClientComponent } = embedAgentforceClient({
container: "#agentforce-container",
salesforceOrigin: "https://myorg.my.salesforce.com",
agentforceClientConfig: {
styleTokens: {
headerBlockBackground: "#7B2CBF",
headerBlockTextColor: "#ffffff",
},
},
});Style Token Reference
Share: Style Token Reference
Container
| Token name | UI area themed |
| --------------------- | --------------------------- |
| fabBackground | FAB button background color |
| containerBackground | Chat container background |
| headerBackground | Header background |
| containerWidth | Chat container width |
| chatBorderRadius | Chat border radius |
| layoutMaxWidth | Layout max width |
Agentforce Header
| Token name | UI area themed |
| ------------------------------- | ---------------------------------- |
| headerBlockBackground | Header block background |
| headerBlockBorderBottomWidth | Header border bottom width |
| headerBlockBorderBottomStyle | Header border bottom style |
| headerBlockBorderBottomColor | Header border bottom color |
| headerBlockBorderRadius | Header corner radius |
| headerBlockPaddingBlock | Header block padding (vertical) |
| headerBlockPaddingInline | Header inline padding (horizontal) |
| headerBlockMinHeight | Header minimum height |
| headerBlockBrandingGap | Header branding area gap |
| headerBlockFontFamily | Header font family |
| headerBlockFontWeight | Header title font weight |
| headerBlockFontSize | Header title font size |
| headerBlockLineHeight | Header title line height |
| headerBlockTextColor | Header text color |
| headerBlockIconDisplay | Header icon display |
| headerBlockIconMargin | Header icon margin |
| headerBlockIconColor | Header icon color |
| headerBlockIconWidth | Header icon width |
| headerBlockIconHeight | Header icon height |
| headerBlockLogoMaxHeight | Header logo max height |
| headerBlockLogoMaxWidth | Header logo max width |
| headerBlockLogoMinWidth | Header logo min width |
| headerBlockButtonHeight | Header action button height |
| headerBlockButtonWidth | Header action button width |
| headerBlockButtonPadding | Header action button padding |
| headerBlockButtonBorderRadius | Header action button border radius |
| headerBlockHoverBackground | Header hover background |
| headerBlockActiveBackground | Header active background |
| headerBlockFocusBorder | Header focus border |
Agentforce Welcome Block
| Token name | UI area themed |
| ----------------------------------- | -------------------------------- |
| welcomeBlockTextContainerWidth | Welcome text container width |
| welcomeBlockFontFamily | Welcome block font family |
| welcomeBlockFontSize | Welcome block font size |
| welcomeBlockFontWeight | Welcome block font weight |
| welcomeBlockLineHeight | Welcome block line height |
| welcomeBlockLetterSpacing | Welcome block letter spacing |
| welcomeBlockTextColor | Welcome block text color |
| welcomeBlockPaddingVertical | Welcome block vertical padding |
| welcomeBlockPaddingHorizontal | Welcome block horizontal padding |
| welcomeBlockTextAnimationDuration | Welcome text animation duration |
Agentforce Messages
| Token name | UI area themed |
| -------------------------------- | ------------------------------------------------------- |
| messageBlockBorderRadius | Message block border radius |
| avatarDisplay | Avatar display property (e.g. block, none) |
| hideMessageActions | Message actions display (e.g. block, none to hide) |
| hideCopyAction | Copy action button display (e.g. inline-flex, none) |
| messageBlockPaddingContainer | Message block container padding |
| messageBlockFontSize | Message block font size |
| messageBlockBackgroundColor | Message block background (base) |
| messageBlockInboundBorder | Inbound message border |
| messageBlockOutboundBorder | Outbound message border |
| messageBlockBodyWidth | Message block body width |
| messageBlockPadding | Message block padding |
| messageBlockContainerMarginTop | Message block container top margin |
| messageBlockLineHeight | Message block line height |
Avatar visibility (behavioral config)
Use renderingConfig.showAvatar to control whether avatars are rendered in message rows.
showAvatar: true(default) renders avatars.showAvatar: falsehides avatars by removing them from the DOM.
Inbound message (customer → agent)
| Token name | UI area themed |
| ----------------------------------------- | --------------------------------- |
| inboundMessageTextColor | Inbound message text color (base) |
| messageBlockInboundBorderRadius | Inbound message border radius |
| messageBlockInboundBackgroundColor | Inbound message background |
| messageBlockInboundTextColor | Inbound message text color |
| messageBlockInboundWidth | Inbound message width |
| messageBlockInboundTextAlign | Inbound message text alignment |
| messageBlockInboundHoverBackgroundColor | Inbound message hover background |
Outbound message (agent → customer)
| Token name | UI area themed |
| ------------------------------------- | ------------------------------- |
| messageBlockOutboundBorderRadius | Outbound message border radius |
| messageBlockOutboundBackgroundColor | Outbound message background |
| messageBlockOutboundTextColor | Outbound message text color |
| messageBlockOutboundWidth | Outbound message width |
| messageBlockOutboundMarginLeft | Outbound message left margin |
| messageBlockOutboundTextAlign | Outbound message text alignment |
Agentforce Input
| Token name | UI area themed |
| ------------------------------------------ | ---------------------------------------------- |
| messageInputPadding | Message input container padding |
| messageInputFooterBorderColor | Message input footer border color |
| messageInputBorderRadius | Message input border radius |
| messageInputBorderTransitionDuration | Message input border transition duration |
| messageInputBorderTransitionEasing | Message input border transition easing |
| messageInputTextColor | Message input text color |
| messageInputTextBackgroundColor | Message input text background color |
| messageInputFooterBorderFocusColor | Message input footer focus border color |
| messageInputFocusShadow | Message input focus shadow |
| messageInputMaxHeight | Message input max height |
| messageInputLineHeight | Message input line height |
| messageInputTextPadding | Message input text padding |
| messageInputFontWeight | Message input font weight |
| messageInputFontSize | Message input font size |
| messageInputOverflowY | Message input overflow Y |
| messageInputScrollbarWidth | Message input scrollbar width |
| messageInputScrollbarColor | Message input scrollbar color |
| messageInputActionsWidth | Message input actions width |
| messageInputActionsPaddingRight | Message input actions right padding |
| messageInputFooterPlaceholderText | Message input placeholder text color |
| messageInputPlaceholderFontWeight | Placeholder font weight |
| messageInputErrorTextColor | Message input error text color |
| messageInputActionsGap | Message input actions gap |
| messageInputActionsPadding | Message input actions padding |
| messageInputActionButtonSize | Message input action button size |
| messageInputActionButtonRadius | Message input action button radius |
| messageInputFooterSendButton | Message input send button color |
| messageInputSendButtonDisabledColor | Message input send button disabled color |
| messageInputActionButtonFocusBorder | Message input action button focus border |
| messageInputActionButtonActiveIconColor | Message input action button active icon color |
| messageInputActionButtonActiveBackground | Message input action button active background |
| messageInputSendButtonIconColor | Message input send button icon color |
| messageInputFooterSendButtonHoverColor | Message input send button hover color |
| messageInputActionButtonHoverShadow | Message input action button hover shadow |
| messageInputFilePreviewPadding | Message input file preview padding |
| messageInputTextareaMaxHeight | Message input textarea max height |
| messageInputTextareaWithImageMaxHeight | Message input textarea max height (with image) |
Agentforce Error Block
| Token name | UI area themed |
| ---------------------- | ---------------------------- |
| errorBlockBackground | Error block background color |
With Configuration
import { embedAgentforceClient } from "@salesforce/agentforce-conversation-client";
const { loApp, chatClientComponent } = embedAgentforceClient({
container: "#agentforce-container",
salesforceOrigin: "https://myorg.my.salesforce.com",
agentforceClientConfig: {
agentId: "AGENT_ID_FROM_ORG",
agentLabel: "My Agent",
styleTokens: {
messageBlockInboundBackgroundColor: "#0176d3",
},
renderingConfig: {
mode: "inline", // or "floating"
width: "100%",
height: "100%",
headerEnabled: true,
showHeaderIcon: false,
showAvatar: false,
},
},
});With Lightning Out 2.0 App ID
import { embedAgentforceClient } from "@salesforce/agentforce-conversation-client";
const { loApp } = embedAgentforceClient({
container: "#agentforce-container",
salesforceOrigin: "https://myorg.my.salesforce.com",
appId: "18_DIGIT_SALESFORCE_ID",
});Listening for Events
const { loApp } = embedAgentforceClient({
container: "#agentforce-container",
salesforceOrigin: "https://myorg.my.salesforce.com",
});
loApp.addEventListener("lo.application.ready", () => {
console.log("Lightning Out 2.0 is ready");
});
loApp.addEventListener("lo.component.ready", (event) => {
console.log("Component ready:", event.detail.componentName);
});
loApp.addEventListener("lo.application.error", (event) => {
console.error("Error:", event.detail);
});API
embedAgentforceClient(options)
Embeds the Agentforce Conversation Client by creating a Lightning Out 2.0 app and chat wrapper under the provided container. In floating mode, the chat is displayed as a fixed overlay; in inline mode, it renders within the container layout.
Note: The embed is initially hidden and becomes visible after the chat wrapper dispatches the
accreadyevent.
Parameters
| Parameter | Type | Required | Description |
| ------------------------------------------------------- | ------------------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| options.container | string \| HTMLElement | Yes | CSS selector or HTMLElement to embed into |
| options.salesforceOrigin | string | No | Salesforce org origin URL (use when hosted in a Salesforce org). At least one of salesforceOrigin or frontdoorUrl is required |
| options.appId | string | No | 18-digit Lightning Out 2.0 app ID (app-id); find it in Lightning Out 2.0 App Manager in Setup; not required for apps created before Spring '26 |
| options.frontdoorUrl | string | No | Frontdoor URL for authentication (use when embedding outside Salesforce). At least one of salesforceOrigin or frontdoorUrl is required |
| options.agentforceClientConfig | AgentforceClientConfig | No | Configuration for the Agentforce client (see sub-properties below) |
| agentforceClientConfig.agentId | string | Yes* | The agent to load — required in practice, will not work without it |
| agentforceClientConfig.agentLabel | string | No | Display name shown in the chat header. Falls back to the agent's configured name if omitted |
| agentforceClientConfig.styleTokens | Record<string, string> | No | Theme colors and style overrides (see Style Tokens section) |
| agentforceClientConfig.renderingConfig.mode | "inline" \| "floating" | No | Rendering mode. Defaults to "floating" |
| agentforceClientConfig.renderingConfig.width | string \| number | No | Width of the inline frame. Number values are treated as px, strings as CSS values (e.g. "100%") |
| agentforceClientConfig.renderingConfig.height | string \| number | No | Height of the inline frame. Number values are treated as px, strings as CSS values (e.g. "100%") |
| agentforceClientConfig.renderingConfig.headerEnabled | boolean | No | Show or hide the chat header bar. Defaults to hidden in inline mode. Set true to show it |
| agentforceClientConfig.renderingConfig.showHeaderIcon | boolean | No | Show or hide the icon in the header. Omit or set false to hide |
| agentforceClientConfig.renderingConfig.showAvatar | boolean | No | Show or hide avatars in message rows. Defaults to true |
Returns
| Property | Type | Description |
| --------------------- | ------------------------- | --------------------------------- |
| loApp | LightningOutApplication | The Lightning Out 2.0 application |
| chatClientComponent | HTMLElement | The chat client component element |
Types
// Accepts any style property key-value pairs
type StyleTokens = Record<string, string>;
interface AgentforceClientConfig {
// styleTokens supports theming the Agentforce Conversation Client
styleTokens?: StyleTokens;
// The agent to load (required in practice)
agentId?: string;
// Display name shown in the chat header
agentLabel?: string;
renderingConfig?: {
mode?: "inline" | "floating";
width?: string | number;
height?: string | number;
headerEnabled?: boolean;
showHeaderIcon?: boolean;
showAvatar?: boolean;
};
}
interface EmbedAgentforceClientOptions {
container: string | HTMLElement;
salesforceOrigin?: string;
appId?: string;
frontdoorUrl?: string;
agentforceClientConfig?: AgentforceClientConfig;
}
interface EmbedAgentforceClientResult {
loApp: LightningOutApplication;
chatClientComponent: HTMLElement;
}Development
# Build the package
npm run build
# Watch mode for development
npm run devLicense
See LICENSE file in the repository root.
