A flexible chat interface component provided as a framework-agnostic web component, making it usable in any framework or vanilla JavaScript.
The ap-chat web component provides AI assistant functionality with a powerful service-based API. The component includes:
- A resizable and collapsible UI that can operate in side-by-side, full-screen, or embedded mode
- Support for text messages with markdown formatting and citations
- File attachments with drag-and-drop support
- Customizable first-run experience with suggested prompts
- Extensible architecture with custom message renderers
- Event system for intercepting and handling chat interactions
- Support for real-time streaming responses and simulated streaming
- Interactive message actions system
- Comprehensive conversation history management
- Settings panel with customizable content
- Real-time voice input and output streaming
- Model and agent mode selection
- Custom header actions with nested menus
- Loading and waiting state management
- Pagination support for large conversations
This package is a self-contained web component with all dependencies bundled (React, Material-UI, etc.):
- Format: ESM only (no CommonJS) - requires modern bundlers and Node.js 14+
- Code splitting: Vendor chunks and locales are lazy-loaded on demand
- Tree-shaking: Not applicable (self-contained bundle)
Web components are designed for modern browsers and bundlers. If you need CommonJS support, use the React components from @uipath/apollo-react directly instead.
npm install @uipath/ap-chat
# or
pnpm add @uipath/ap-chat
# or
yarn add @uipath/ap-chatNote: This package is published to both npm and GitHub Package Registry. External users will automatically pull from npm. Internal UiPath users with .npmrc configured will automatically pull from GitHub Package Registry.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>AP Chat Example</title>
</head>
<body>
<ap-chat id="chat"></ap-chat>
<script type="module">
import { AutopilotChatService } from '@uipath/ap-chat/service';
import '@uipath/ap-chat';
// Create and initialize the service
const service = AutopilotChatService.Instantiate({
instanceName: 'my-chat',
config: {
mode: 'side-by-side',
firstRunExperience: {
title: "Welcome to Autopilot Chat!",
description: "Ask me anything about your data or how to use this application.",
suggestions: [
{ label: "Get started", prompt: "How do I get started?" },
{ label: "Show features", prompt: "What features are available?" }
]
}
}
});
// Set the service instance and properties on the web component
const chatElement = document.getElementById('chat');
chatElement.chatServiceInstance = service;
chatElement.locale = 'en';
chatElement.theme = 'light';
// Listen for user requests
service.on('Request', (data) => {
console.log('User sent:', data.content);
// Send a response
setTimeout(() => {
service.sendResponse({
content: `Echo: ${data.content}`,
role: 'assistant'
});
}, 1000);
});
// Open the chat
service.open();
</script>
</body>
</html>For React applications, use the @uipath/apollo-react package directly instead of the web component:
import { ApChat, AutopilotChatService, AutopilotChatMode } from '@uipath/apollo-react/ap-chat';
function App() {
const service = AutopilotChatService.Instantiate({
instanceName: 'my-chat',
config: {
mode: AutopilotChatMode.SideBySide
}
});
// ... use ApChat React component directly
}See the @uipath/apollo-react documentation for details.
The <ap-chat> element exposes the following JavaScript properties:
// Chat service instance (required)
chatElement.chatServiceInstance = service;
// Locale (optional, default: 'en')
// Supported: 'en', 'de', 'es', 'es-MX', 'fr', 'ja', 'ko', 'pt', 'pt-BR', 'ru', 'tr', 'zh-CN', 'zh-TW'
chatElement.locale = 'en';
// Theme (optional, default: 'light')
// Supported: 'light', 'dark', 'light-hc', 'dark-hc'
chatElement.theme = 'light';The complete chat service API documentation is available in the @uipath/apollo-react package documentation.
Configuration & Initialization
initialize(config)- Initialize the chat serviceopen()- Open the chat interfaceclose()- Close the chat interfacesetChatMode(mode)- Set chat window mode ('side-by-side', 'full-screen', 'embedded')setLocale(locale)- Change locale dynamicallysetTheme(theme)- Change theme dynamically
Message Handling
sendRequest(message)- Send a user requestsendResponse(message)- Send an AI responsesetConversation(messages)- Set entire conversationgetConversation()- Get current conversationsetPrompt(prompt)- Set input field valuesetSuggestions(suggestions)- Show suggestion chips
Event Handling
on(event, handler)- Subscribe to eventsintercept(event, interceptor)- Intercept events
Common Events
Request- User sends a messageResponse- AI response receivedModeChange- Chat mode changedOpen- Chat openedClose- Chat closed
import { AutopilotChatService } from '@uipath/ap-chat/service';
const service = AutopilotChatService.Instantiate({
instanceName: 'streaming-chat',
config: {
mode: 'side-by-side'
}
});
// Stream a response word by word
const messageId = 'stream-' + Date.now();
const words = ['Hello', 'World', 'This', 'is', 'streaming'];
words.forEach((word, index) => {
setTimeout(() => {
service.sendResponse({
id: messageId,
content: word,
stream: true,
done: index === words.length - 1
});
}, index * 200);
});service.sendResponse({
role: 'assistant',
contentParts: [
{
text: 'The NBA Finals are the annual championship series.',
citations: [
{
id: 1,
title: 'NBA Official Finals Overview',
url: 'https://www.nba.com/history/finals'
}
]
}
]
});service.sendResponse({
content: 'Here is your data analysis',
actions: [
{
name: 'export',
label: 'Export Data',
icon: 'download',
eventName: 'export-data'
}
]
});
service.on('export-data', ({ message, action }) => {
console.log('Export triggered for message:', message.id);
});For comprehensive documentation including:
- All service methods and parameters
- Event system details
- Message renderers
- History management
- Settings panel
- Model and agent mode selection
- Streaming and citations
- And much more...
See the complete documentation.
The package includes full TypeScript definitions. Import types from the service:
import {
AutopilotChatService,
AutopilotChatMessage,
AutopilotChatConfiguration,
AutopilotChatEvent
} from '@uipath/ap-chat/service';The web component uses modern browser features:
- Custom Elements v1
- Shadow DOM v1
- ES Modules
Supported browsers:
- Chrome/Edge 88+
- Firefox 90+
- Safari 14+
MIT