@makemore/agent-frontend 1.0.0
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/LICENSE +22 -0
- package/README.md +229 -0
- package/dist/chat-widget.css +503 -0
- package/dist/chat-widget.js +745 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Agent Frontend
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# Agent Frontend
|
|
2
|
+
|
|
3
|
+
A standalone, zero-dependency chat widget for AI agents. Embed conversational AI into any website with a single script tag.
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<img src="https://img.shields.io/badge/vanilla-JavaScript-yellow" alt="Vanilla JS">
|
|
7
|
+
<img src="https://img.shields.io/badge/size-~15kb-green" alt="Size">
|
|
8
|
+
<img src="https://img.shields.io/badge/dependencies-0-blue" alt="Zero Dependencies">
|
|
9
|
+
<img src="https://img.shields.io/badge/license-MIT-purple" alt="MIT License">
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
## Why Agent Frontend?
|
|
13
|
+
|
|
14
|
+
Most chat widgets are tightly coupled to specific frameworks or require complex build setups. Agent Frontend is different:
|
|
15
|
+
|
|
16
|
+
- **Zero dependencies** - Pure vanilla JavaScript, no React/Vue/Angular required
|
|
17
|
+
- **CSS isolated** - Won't conflict with your existing styles (uses `all: initial` reset)
|
|
18
|
+
- **SSE streaming** - Real-time token-by-token responses, not polling
|
|
19
|
+
- **Production ready** - Session management, error handling, conversation persistence
|
|
20
|
+
|
|
21
|
+
## Features
|
|
22
|
+
|
|
23
|
+
| Feature | Description |
|
|
24
|
+
|---------|-------------|
|
|
25
|
+
| 💬 **Real-time Streaming** | SSE-based message streaming for instant, token-by-token responses |
|
|
26
|
+
| 🎨 **Theming** | Customize colors, titles, messages, and position |
|
|
27
|
+
| 🌙 **Dark Mode** | Automatic dark mode based on system preferences |
|
|
28
|
+
| 📱 **Responsive** | Works seamlessly on desktop and mobile |
|
|
29
|
+
| 🔧 **Debug Mode** | Toggle visibility of tool calls and results |
|
|
30
|
+
| 🤖 **Demo Flows** | Built-in auto-run mode for showcasing agent journeys |
|
|
31
|
+
| 🔒 **Sessions** | Automatic anonymous session creation and management |
|
|
32
|
+
| 💾 **Persistence** | Conversations persist across page reloads via localStorage |
|
|
33
|
+
| 🛡️ **Isolated CSS** | Scoped styles that won't leak into or from your page |
|
|
34
|
+
|
|
35
|
+
## Quick Start
|
|
36
|
+
|
|
37
|
+
### 1. Include the files
|
|
38
|
+
|
|
39
|
+
```html
|
|
40
|
+
<link rel="stylesheet" href="https://your-cdn.com/chat-widget.css">
|
|
41
|
+
<script src="https://your-cdn.com/chat-widget.js"></script>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 2. Initialize the widget
|
|
45
|
+
|
|
46
|
+
```html
|
|
47
|
+
<script>
|
|
48
|
+
ChatWidget.init({
|
|
49
|
+
backendUrl: 'https://your-api.com',
|
|
50
|
+
agentKey: 'your-agent',
|
|
51
|
+
title: 'Support Chat',
|
|
52
|
+
primaryColor: '#0066cc',
|
|
53
|
+
});
|
|
54
|
+
</script>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Configuration Options
|
|
58
|
+
|
|
59
|
+
| Option | Type | Default | Description |
|
|
60
|
+
|--------|------|---------|-------------|
|
|
61
|
+
| `backendUrl` | string | `'http://localhost:8000'` | Backend API URL |
|
|
62
|
+
| `agentKey` | string | `'insurance-agent'` | Agent identifier |
|
|
63
|
+
| `title` | string | `'Chat Assistant'` | Widget header title |
|
|
64
|
+
| `subtitle` | string | `'How can we help you today?'` | Widget subtitle |
|
|
65
|
+
| `primaryColor` | string | `'#0066cc'` | Primary theme color |
|
|
66
|
+
| `position` | string | `'bottom-right'` | Widget position (`bottom-right` or `bottom-left`) |
|
|
67
|
+
| `defaultJourneyType` | string | `'general'` | Default journey type |
|
|
68
|
+
| `enableDebugMode` | boolean | `true` | Show debug toggle button |
|
|
69
|
+
| `enableAutoRun` | boolean | `true` | Show demo flows dropdown |
|
|
70
|
+
| `placeholder` | string | `'Type your message...'` | Input placeholder text |
|
|
71
|
+
| `emptyStateTitle` | string | `'Start a Conversation'` | Empty state heading |
|
|
72
|
+
| `emptyStateMessage` | string | `'Send a message to get started.'` | Empty state description |
|
|
73
|
+
| `journeyTypes` | object | `{}` | Journey type definitions for demo flows |
|
|
74
|
+
| `anonymousTokenHeader` | string | `'X-Anonymous-Token'` | Header name for auth token |
|
|
75
|
+
| `conversationIdKey` | string | `'chat_widget_conversation_id'` | localStorage key for conversation ID |
|
|
76
|
+
| `sessionTokenKey` | string | `'chat_widget_session_token'` | localStorage key for session token |
|
|
77
|
+
|
|
78
|
+
## Journey Types Configuration
|
|
79
|
+
|
|
80
|
+
Define demo flows that users can trigger from the dropdown:
|
|
81
|
+
|
|
82
|
+
```javascript
|
|
83
|
+
ChatWidget.init({
|
|
84
|
+
// ... other options
|
|
85
|
+
journeyTypes: {
|
|
86
|
+
quote: {
|
|
87
|
+
label: '🏠 Get a Quote',
|
|
88
|
+
description: 'Get an insurance quote',
|
|
89
|
+
initialMessage: "Hi, I'd like to get a quote for home insurance.",
|
|
90
|
+
},
|
|
91
|
+
claim: {
|
|
92
|
+
label: '📋 File a Claim',
|
|
93
|
+
description: 'File an insurance claim',
|
|
94
|
+
initialMessage: 'Hi, I need to file a claim.',
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## JavaScript API
|
|
101
|
+
|
|
102
|
+
### Methods
|
|
103
|
+
|
|
104
|
+
```javascript
|
|
105
|
+
// Initialize the widget
|
|
106
|
+
ChatWidget.init(config);
|
|
107
|
+
|
|
108
|
+
// Open the chat widget
|
|
109
|
+
ChatWidget.open();
|
|
110
|
+
|
|
111
|
+
// Close the chat widget
|
|
112
|
+
ChatWidget.close();
|
|
113
|
+
|
|
114
|
+
// Send a message programmatically
|
|
115
|
+
ChatWidget.send('Hello, I need help!');
|
|
116
|
+
|
|
117
|
+
// Clear the conversation
|
|
118
|
+
ChatWidget.clearMessages();
|
|
119
|
+
|
|
120
|
+
// Start a demo flow
|
|
121
|
+
ChatWidget.startDemoFlow('quote');
|
|
122
|
+
|
|
123
|
+
// Stop auto-run mode
|
|
124
|
+
ChatWidget.stopAutoRun();
|
|
125
|
+
|
|
126
|
+
// Remove the widget from the page
|
|
127
|
+
ChatWidget.destroy();
|
|
128
|
+
|
|
129
|
+
// Get current state (read-only)
|
|
130
|
+
const state = ChatWidget.getState();
|
|
131
|
+
|
|
132
|
+
// Get current config (read-only)
|
|
133
|
+
const config = ChatWidget.getConfig();
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Backend Requirements
|
|
137
|
+
|
|
138
|
+
The widget expects a backend API with the following endpoints:
|
|
139
|
+
|
|
140
|
+
### Create Anonymous Session
|
|
141
|
+
```
|
|
142
|
+
POST /api/accounts/anonymous-session/
|
|
143
|
+
Response: { "token": "..." }
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Create Agent Run
|
|
147
|
+
```
|
|
148
|
+
POST /api/agent-runtime/runs/
|
|
149
|
+
Headers: { "X-Anonymous-Token": "..." }
|
|
150
|
+
Body: {
|
|
151
|
+
"agentKey": "...",
|
|
152
|
+
"conversationId": "...",
|
|
153
|
+
"messages": [{ "role": "user", "content": "..." }],
|
|
154
|
+
"metadata": { "journey_type": "..." }
|
|
155
|
+
}
|
|
156
|
+
Response: { "id": "...", "conversationId": "..." }
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### SSE Events Stream
|
|
160
|
+
```
|
|
161
|
+
GET /api/agent-runtime/runs/{runId}/events/?anonymous_token=...
|
|
162
|
+
Events: assistant.message, tool.call, tool.result, run.succeeded, run.failed
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Simulate Customer (for demo flows)
|
|
166
|
+
```
|
|
167
|
+
POST /api/agent-runtime/simulate-customer/
|
|
168
|
+
Body: { "messages": [...], "journey_type": "..." }
|
|
169
|
+
Response: { "response": "..." }
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## CSS Isolation
|
|
173
|
+
|
|
174
|
+
The widget uses multiple techniques to prevent style conflicts:
|
|
175
|
+
|
|
176
|
+
```css
|
|
177
|
+
.cw-container {
|
|
178
|
+
all: initial; /* Reset all inherited styles */
|
|
179
|
+
/* ... widget styles scoped here */
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.cw-container *,
|
|
183
|
+
.cw-container *::before,
|
|
184
|
+
.cw-container *::after {
|
|
185
|
+
box-sizing: border-box; /* Consistent box model */
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
- All CSS classes prefixed with `cw-`
|
|
190
|
+
- CSS variables scoped to `.cw-container`, not `:root`
|
|
191
|
+
- High z-index (99999) to stay above host page content
|
|
192
|
+
- Font smoothing reset for consistent text rendering
|
|
193
|
+
|
|
194
|
+
## Development
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
# Clone and serve locally
|
|
198
|
+
git clone <repo-url>
|
|
199
|
+
cd agent-frontend
|
|
200
|
+
python -m http.server 8080
|
|
201
|
+
|
|
202
|
+
# Open http://localhost:8080/demo.html
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### File Structure
|
|
206
|
+
|
|
207
|
+
```
|
|
208
|
+
agent-frontend/
|
|
209
|
+
├── dist/
|
|
210
|
+
│ ├── chat-widget.js # Main library (~750 lines, ~15kb)
|
|
211
|
+
│ └── chat-widget.css # Styles (~500 lines, ~8kb)
|
|
212
|
+
├── demo.html # Interactive demo page
|
|
213
|
+
└── README.md
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Browser Support
|
|
217
|
+
|
|
218
|
+
| Browser | Version |
|
|
219
|
+
|---------|---------|
|
|
220
|
+
| Chrome | 60+ |
|
|
221
|
+
| Firefox | 55+ |
|
|
222
|
+
| Safari | 11+ |
|
|
223
|
+
| Edge | 79+ |
|
|
224
|
+
|
|
225
|
+
Requires: `EventSource` (SSE), `fetch`, `localStorage`
|
|
226
|
+
|
|
227
|
+
## License
|
|
228
|
+
|
|
229
|
+
MIT © 2024
|