@agentxin-ai/chatkit-js
v0.0.2
Published
Framework-agnostic bindings for AgentXin Chatkit
Maintainers
Readme
@agentxin-ai/chatkit-js
Framework-agnostic ChatKit integration helpers for vanilla JS + Web Components.
Minimal Example
Framework-agnostic bindings for the AgentXin Chatkit Web Component.
Install
pnpm add @agentxin-ai/chatkit-jsUsage
import { createChatKit } from '@agentxin-ai/chatkit-js';
const container = document.getElementById('chatkit-root');
// 1) Create + mount the custom element
const element = document.createElement('agentxinai-chatkit');
container?.appendChild(element);
// 2) Provide options + event callbacks
const chatkit = createChatKit(element, {
options: {
api: {
async getClientSecret() {
const res = await fetch('/api/chatkit/session', { method: 'POST' });
const { client_secret } = await res.json();
return client_secret;
},
},
theme: { colorScheme: 'light', radius: 'round' },
},
onReady() {
console.log('ChatKit is ready');
},
onResponseEnd() {
console.log('Assistant finished responding');
},
});
// 3) Clean up on page unload
window.addEventListener('beforeunload', () => {
chatkit.destroy();
});const chatkit = createChatKit({ apiBase: 'https://your-agentxinai-api-host', apiKey: 'your-agentxinai-api-key', onReady: () => { console.log('chatkit ready'); }, });
document.body.appendChild(chatkit.element);
Call `chatkit.destroy()` when you no longer need the instance to remove event listeners.