@makemore/agent-frontend 1.8.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +140 -7
- package/dist/chat-widget.css +611 -1
- package/dist/chat-widget.js +305 -1376
- package/package.json +19 -7
- package/src/components/ChatWidget.js +259 -0
- package/src/components/Header.js +111 -0
- package/src/components/InputForm.js +95 -0
- package/src/components/Message.js +115 -0
- package/src/components/MessageList.js +106 -0
- package/src/components/ModelSelector.js +68 -0
- package/src/components/Sidebar.js +58 -0
- package/src/hooks/useChat.js +456 -0
- package/src/hooks/useModels.js +69 -0
- package/src/index.js +222 -0
- package/src/utils/api.js +91 -0
- package/src/utils/config.js +83 -0
- package/src/utils/helpers.js +83 -0
package/README.md
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
# Agent Frontend
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A lightweight chat widget for AI agents built with Preact. Embed conversational AI into any website with a single script tag.
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
6
|
-
<img src="https://img.shields.io/badge/
|
|
7
|
-
<img src="https://img.shields.io/badge/size-~
|
|
8
|
-
<img src="https://img.shields.io/badge/dependencies-0-blue" alt="Zero Dependencies">
|
|
6
|
+
<img src="https://img.shields.io/badge/Preact-673AB8?logo=preact&logoColor=white" alt="Preact">
|
|
7
|
+
<img src="https://img.shields.io/badge/size-~25kb-green" alt="Size">
|
|
9
8
|
<img src="https://img.shields.io/badge/license-MIT-purple" alt="MIT License">
|
|
10
9
|
</p>
|
|
11
10
|
|
|
@@ -13,10 +12,11 @@ A standalone, zero-dependency chat widget for AI agents. Embed conversational AI
|
|
|
13
12
|
|
|
14
13
|
Most chat widgets are tightly coupled to specific frameworks or require complex build setups. Agent Frontend is different:
|
|
15
14
|
|
|
16
|
-
- **
|
|
15
|
+
- **Lightweight** - Built with Preact (~3kb) for minimal bundle size
|
|
17
16
|
- **CSS isolated** - Won't conflict with your existing styles (uses `all: initial` reset)
|
|
18
17
|
- **SSE streaming** - Real-time token-by-token responses, not polling
|
|
19
18
|
- **Production ready** - Session management, error handling, conversation persistence
|
|
19
|
+
- **Component-based** - Clean architecture with hooks for state management
|
|
20
20
|
|
|
21
21
|
## Features
|
|
22
22
|
|
|
@@ -174,6 +174,7 @@ See `django-tts-example.py` for the complete Django backend implementation.
|
|
|
174
174
|
| `showTTSButton` | boolean | `true` | Show TTS toggle button in header |
|
|
175
175
|
| `showVoiceSettings` | boolean | `true` | Show voice settings button in header (works with proxy and direct API) |
|
|
176
176
|
| `showExpandButton` | boolean | `true` | Show expand/minimize button in header |
|
|
177
|
+
| `showConversationSidebar` | boolean | `true` | Show conversation history sidebar with hamburger menu |
|
|
177
178
|
| `onEvent` | function | `null` | Callback for SSE events: `(eventType, payload) => void` |
|
|
178
179
|
| `authStrategy` | string | `null` | Auth strategy: `'token'`, `'jwt'`, `'session'`, `'anonymous'`, `'none'` (auto-detected if null) |
|
|
179
180
|
| `authToken` | string | `null` | Token value for `'token'` or `'jwt'` strategies |
|
|
@@ -574,6 +575,12 @@ ChatWidget.send('Hello, I need help!');
|
|
|
574
575
|
// Clear the conversation
|
|
575
576
|
ChatWidget.clearMessages();
|
|
576
577
|
|
|
578
|
+
// Conversation sidebar controls
|
|
579
|
+
ChatWidget.toggleSidebar(); // Open/close conversation sidebar
|
|
580
|
+
ChatWidget.newConversation(); // Start a new conversation
|
|
581
|
+
ChatWidget.switchConversation('conversation-id'); // Switch to a specific conversation
|
|
582
|
+
ChatWidget.loadMoreMessages(); // Load older messages
|
|
583
|
+
|
|
577
584
|
// Text-to-speech controls
|
|
578
585
|
ChatWidget.toggleTTS(); // Toggle TTS on/off
|
|
579
586
|
ChatWidget.stopSpeech(); // Stop current speech and clear queue
|
|
@@ -728,9 +735,135 @@ agent-frontend/
|
|
|
728
735
|
|
|
729
736
|
Requires: `EventSource` (SSE), `fetch`, `localStorage`
|
|
730
737
|
|
|
738
|
+
## Multiple Instances
|
|
739
|
+
|
|
740
|
+
You can create multiple independent chat widgets on the same page using `createInstance()`:
|
|
741
|
+
|
|
742
|
+
### Basic Multi-Instance Setup
|
|
743
|
+
|
|
744
|
+
```html
|
|
745
|
+
<div id="chat-1" style="width: 400px; height: 500px;"></div>
|
|
746
|
+
<div id="chat-2" style="width: 400px; height: 500px;"></div>
|
|
747
|
+
|
|
748
|
+
<script>
|
|
749
|
+
// Create first widget
|
|
750
|
+
const widget1 = ChatWidget.createInstance({
|
|
751
|
+
containerId: 'chat-1',
|
|
752
|
+
backendUrl: 'https://your-api.com',
|
|
753
|
+
agentKey: 'support-agent',
|
|
754
|
+
title: 'Support Chat',
|
|
755
|
+
primaryColor: '#0066cc',
|
|
756
|
+
embedded: true,
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
// Create second widget
|
|
760
|
+
const widget2 = ChatWidget.createInstance({
|
|
761
|
+
containerId: 'chat-2',
|
|
762
|
+
backendUrl: 'https://your-api.com',
|
|
763
|
+
agentKey: 'sales-agent',
|
|
764
|
+
title: 'Sales Chat',
|
|
765
|
+
primaryColor: '#00cc66',
|
|
766
|
+
embedded: true,
|
|
767
|
+
});
|
|
768
|
+
</script>
|
|
769
|
+
```
|
|
770
|
+
|
|
771
|
+
### Instance Configuration Options
|
|
772
|
+
|
|
773
|
+
| Option | Type | Default | Description |
|
|
774
|
+
|--------|------|---------|-------------|
|
|
775
|
+
| `containerId` | string | `null` | ID of the container element for embedded mode |
|
|
776
|
+
| `embedded` | boolean | `false` | If true, renders inline in container instead of floating |
|
|
777
|
+
| `metadata` | object | `{}` | Custom metadata to send with each request |
|
|
778
|
+
|
|
779
|
+
### Instance Methods
|
|
780
|
+
|
|
781
|
+
Each instance returned by `createInstance()` has its own methods:
|
|
782
|
+
|
|
783
|
+
```javascript
|
|
784
|
+
const widget = ChatWidget.createInstance({ ... });
|
|
785
|
+
|
|
786
|
+
// Control the widget
|
|
787
|
+
widget.open();
|
|
788
|
+
widget.close();
|
|
789
|
+
widget.send('Hello!');
|
|
790
|
+
widget.clearMessages();
|
|
791
|
+
|
|
792
|
+
// TTS controls
|
|
793
|
+
widget.toggleTTS();
|
|
794
|
+
widget.stopSpeech();
|
|
795
|
+
|
|
796
|
+
// Authentication
|
|
797
|
+
widget.setAuth({ strategy: 'jwt', token: 'new-token' });
|
|
798
|
+
widget.clearAuth();
|
|
799
|
+
|
|
800
|
+
// Get state/config
|
|
801
|
+
const state = widget.getState();
|
|
802
|
+
const config = widget.getConfig();
|
|
803
|
+
|
|
804
|
+
// Destroy the widget
|
|
805
|
+
widget.destroy();
|
|
806
|
+
```
|
|
807
|
+
|
|
808
|
+
### Managing Multiple Instances
|
|
809
|
+
|
|
810
|
+
```javascript
|
|
811
|
+
// Get a specific instance by ID
|
|
812
|
+
const widget = ChatWidget.getInstance('cw-1');
|
|
813
|
+
|
|
814
|
+
// Get all instances
|
|
815
|
+
const allWidgets = ChatWidget.getAllInstances();
|
|
816
|
+
|
|
817
|
+
// Destroy all instances
|
|
818
|
+
ChatWidget.getAllInstances().forEach(w => w.destroy());
|
|
819
|
+
```
|
|
820
|
+
|
|
821
|
+
### Embedded vs Floating Mode
|
|
822
|
+
|
|
823
|
+
**Embedded Mode** (`embedded: true`):
|
|
824
|
+
- Widget renders inside the specified container
|
|
825
|
+
- No floating button or close button
|
|
826
|
+
- Widget is always visible
|
|
827
|
+
- Perfect for split-pane layouts, dashboards, or dedicated chat pages
|
|
828
|
+
|
|
829
|
+
**Floating Mode** (`embedded: false`, default):
|
|
830
|
+
- Widget appears as a floating button in the corner
|
|
831
|
+
- Clicking opens the chat panel
|
|
832
|
+
- Has close and expand buttons
|
|
833
|
+
- Traditional chat widget behavior
|
|
834
|
+
|
|
835
|
+
### Storage Isolation
|
|
836
|
+
|
|
837
|
+
Each embedded instance uses isolated localStorage keys based on `containerId`:
|
|
838
|
+
- `chat_widget_conversation_id_chat-1` for widget in `#chat-1`
|
|
839
|
+
- `chat_widget_conversation_id_chat-2` for widget in `#chat-2`
|
|
840
|
+
|
|
841
|
+
This ensures conversations don't get mixed up between instances.
|
|
842
|
+
|
|
731
843
|
## Version History
|
|
732
844
|
|
|
733
|
-
###
|
|
845
|
+
### v2.0.1 (Latest)
|
|
846
|
+
- 🔄 **Preact Rewrite**: Complete rewrite using Preact for better maintainability
|
|
847
|
+
- 🧩 **Component Architecture**: Modular components (ChatWidget, Header, InputForm, Message, MessageList, Sidebar)
|
|
848
|
+
- 🪝 **React-style Hooks**: useChat and useModels hooks for state management
|
|
849
|
+
- 🎛️ **Model Selector**: Built-in model selection dropdown
|
|
850
|
+
- 📦 **Smaller Bundle**: Optimized build with esbuild
|
|
851
|
+
- 🔧 **Better Developer Experience**: Watch mode, source maps, cleaner code structure
|
|
852
|
+
|
|
853
|
+
### v1.10.1
|
|
854
|
+
- 📚 **Conversation Sidebar**: Browse and switch between past conversations via hamburger menu
|
|
855
|
+
- 📜 **Message Pagination**: Load older messages with "load more" functionality
|
|
856
|
+
- 🔐 **CSRF Support**: Automatic CSRF token handling for Django session auth
|
|
857
|
+
- ➕ **New Conversation**: Start fresh conversations from the sidebar
|
|
858
|
+
- 🔄 **Auto-restore**: Automatically loads messages when returning to a conversation
|
|
859
|
+
|
|
860
|
+
### v1.5.0
|
|
861
|
+
- 🔀 **Multiple Instances**: Create multiple independent chat widgets on the same page
|
|
862
|
+
- 📦 **Embedded Mode**: Render widgets inline in containers for dashboards and split-pane layouts
|
|
863
|
+
- 🔒 **Storage Isolation**: Each instance has isolated localStorage for conversations
|
|
864
|
+
- 🎯 **Instance API**: Full control over individual widget instances
|
|
865
|
+
|
|
866
|
+
### v1.4.0
|
|
734
867
|
- ✨ **Text-to-Speech**: ElevenLabs integration with secure Django proxy support
|
|
735
868
|
- 🔊 Automatic speech for assistant and simulated user messages
|
|
736
869
|
- 🎛️ Smart speech queuing to prevent overlap
|
|
@@ -760,4 +893,4 @@ Requires: `EventSource` (SSE), `fetch`, `localStorage`
|
|
|
760
893
|
|
|
761
894
|
## License
|
|
762
895
|
|
|
763
|
-
MIT ©
|
|
896
|
+
MIT © 2025
|