A production-ready, headless chat widget library built with vanilla TypeScript core and React components.
- π― Headless Architecture - Fully customizable, framework-agnostic core
- π WebSocket Real-time - Bi-directional streaming communication
- βοΈ React Components - Ready-to-use React wrapper components
- π¨ Themed UI - Beautiful default theme included
- π Markdown Support - Rich text rendering with marked.js
- π Auto-reconnect - Smart reconnection handling
- π¦ TypeScript - Full type safety
- π― Modern Stack - React 19, Tailwind CSS v4, Vite
npm install @creastat/assistant-widget
# or
bun add @creastat/assistant-widgetimport { ChatWidget } from '@creastat/assistant-widget/react';
function App() {
return (
<ChatWidget
serverUrl="ws://localhost:8080/ws"
siteToken="your-site-token"
title="IO Assistant"
placeholder="Type a message..."
theme="default"
debug={true}
onClose={() => console.log('Widget closed')}
/>
);
}import { ChatService } from '@creastat/assistant-widget';
const chat = new ChatService(
{
serverUrl: 'ws://localhost:8080/ws',
debug: true,
},
(event) => {
console.log('Chat event:', event);
}
);
// Connect
await chat.connect();
// Send message
await chat.sendMessage('Hello, AI!');
// Disconnect
chat.disconnect();| Prop | Type | Default | Description |
|---|---|---|---|
config |
ChatConfig |
required | WebSocket configuration |
autoConnect |
boolean |
true |
Auto-connect on mount |
title |
string |
'Chat' |
Widget title |
placeholder |
string |
'Type a message...' |
Input placeholder |
theme |
string |
'default' |
UI theme |
className |
string |
'' |
Additional CSS classes |
onClose |
() => void |
- | Close handler |
interface ChatConfig {
serverUrl: string; // WebSocket URL
sessionId?: string; // Optional session ID
authToken?: string; // Optional auth token
reconnect?: boolean; // Enable auto-reconnect (default: true)
reconnectInterval?: number; // Reconnect delay in ms (default: 3000)
maxReconnectAttempts?: number; // Max reconnect attempts (default: 5)
debug?: boolean; // Enable debug logs (default: false)
}interface Message {
id: string;
role: 'user' | 'assistant' | 'system';
content: string;
timestamp: number;
type?: 'text' | 'audio' | 'control' | 'break' | 'error' | 'status';
metadata?: Record<string, unknown>;
}The widget includes a beautiful default theme. It features:
- Brown gradient background (
#7d5c59to#6d5654) - Glass-morphism effects
- Smooth animations
- Responsive design
- Dark theme optimized
You can create your own theme by extending the CSS:
@theme {
--color-primary: #your-color;
--radius-widget: 1rem;
/* ... other variables */
}
.theme-custom {
.chat-header {
background: linear-gradient(135deg, #your-colors);
}
/* ... other styles */
}The widget uses a structured JSON protocol over WebSocket for all non-binary communication.
input.text: Plain text user messageinput.audio: Binary audio stream controlinput.end: End of audio input signalcontrol.config: Update session configuration
stream.llm: Partial LLM response chunksstream.stt: Real-time transcription resultsresponse.start/response.end: Response lifecycle eventsstatus: Interaction status updates (thinking, searching, etc.)service.message: System notificationserror: Error messagesaudio: Base64 encoded audio chunks (when not using binary stream)
# Install dependencies
bun install
# Build library
bun run build
# Watch mode
bun run dev
# Type check
bun run type-check
# Run demo
bun run dev:demoThe widget includes three demo pages to help you get started:
-
React Demo (
/) - Full-featured React demo with component examples- Shows React wrapper usage with
ChatWidgetcomponent - Interactive controls and live widget
- Access: Run
bun run dev:demoand visithttp://localhost:5173
- Shows React wrapper usage with
-
Vanilla JS Demo (
/demo/vanilla.html) - Pure vanilla JavaScript implementation- Shows core
ChatWidgetclass usage - Headless
ChatServiceexamples - Interactive initialization and controls
- Access:
http://localhost:5173/demo/vanilla.html
- Shows core
-
CDN Embed Example (
/demo/embed.html) - Simplest integration method- Shows CDN/script tag usage with
embed.js - Interactive script generator with compression
- Copy-paste ready code
- Access:
http://localhost:5173/demo/embed.html
- Shows CDN/script tag usage with
assistant-widget/
βββ src/
β βββ core/ # Headless Core (Vanilla TS)
β β βββ services/ # Business logic & API
β β βββ store/ # State management
β β βββ types/ # Type definitions
β β βββ ui/ # UI Controller logic
β β βββ utils/ # Helpers & Audio logic
β βββ react/ # React Wrapper
β β βββ components/ # React-specific components
β βββ themes/ # UI Themes & Templates
β β βββ default/ # Default Theme
β βββ generator.ts # Dashboard script generator
β βββ embed.ts # CDN/Embed entry point
β βββ index.ts # Main library entry
βββ demo/ # Demo applications
βββ dist/ # Compiled assets
βββ package.json
βββ tsconfig.json
βββ vite.config.ts
βββ README.md
- Chrome/Edge (latest)
- Firefox (latest)
- Safari 14+
MIT
Contributions are welcome! Please read our contributing guidelines first.
Built by Creastat team with β€οΈ