@zelto/web-chat-sdk
v0.2.1
Published
Embeddable TypeScript SDK for Zelto agent chat (bubble + panel UI, multi-session, actions) connecting to the ai-platform embed chat API.
Readme
Zelto Web Chat SDK
Embeddable TypeScript SDK for Zelto web chat. Renders a floating chat bubble and panel, connects to the ai-platform embed chat API, and supports multiple chat sessions plus action handling.
Installation
pnpm add @zelto/web-chat-sdkQuick start
import { init, setContext, mountChat, unmountChat } from '@zelto/web-chat-sdk';
init({
apiKey: 'vk_...',
userId: 'user-123',
baseUrl: 'https://your-zelto-instance/api/v1', // required for sending messages
});
setContext({
page: window.location.pathname,
plan: 'pro',
});
mountChat(); // Renders bubble + panel and wires send to the embed chat API
// unmountChat(); // Removes the widgetWhen baseUrl is set, sending a message calls POST {baseUrl}/chat with your API key and user id, streams the reply, and shows errors (e.g. 401, 429) in the panel. The SDK supports multiple sessions (session switcher + Session History API), action handler registration (registerAction), and configurable context (setContext). See tasks/prd-web-chat-sdk.md for full spec.
Testing
- Unit, integration, component:
pnpm run test(Vitest + jsdom) - Coverage:
pnpm run test:coverage(src only; thresholds: 70% stmts/branches/lines, 80% functions; PRD target 80%) - Bundle size:
pnpm run check:bundle-size(fails if ESM gzip > 50 kB) - E2E (Playwright): Install browsers once with
pnpm exec playwright install, thenpnpm run test:e2e. Uses a smoke host page that embeds the SDK and mocks the API.
