@makemore/agent-frontend 1.0.0 → 1.1.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/README.md +75 -4
- package/dist/chat-widget.js +23 -5
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -32,16 +32,51 @@ Most chat widgets are tightly coupled to specific frameworks or require complex
|
|
|
32
32
|
| 💾 **Persistence** | Conversations persist across page reloads via localStorage |
|
|
33
33
|
| 🛡️ **Isolated CSS** | Scoped styles that won't leak into or from your page |
|
|
34
34
|
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
### Via npm
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install @makemore/agent-frontend
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Then include in your HTML:
|
|
44
|
+
|
|
45
|
+
```html
|
|
46
|
+
<link rel="stylesheet" href="node_modules/@makemore/agent-frontend/dist/chat-widget.css">
|
|
47
|
+
<script src="node_modules/@makemore/agent-frontend/dist/chat-widget.js"></script>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Via CDN (unpkg)
|
|
51
|
+
|
|
52
|
+
```html
|
|
53
|
+
<link rel="stylesheet" href="https://unpkg.com/@makemore/agent-frontend/dist/chat-widget.css">
|
|
54
|
+
<script src="https://unpkg.com/@makemore/agent-frontend/dist/chat-widget.js"></script>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Via CDN (jsDelivr)
|
|
58
|
+
|
|
59
|
+
```html
|
|
60
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@makemore/agent-frontend/dist/chat-widget.css">
|
|
61
|
+
<script src="https://cdn.jsdelivr.net/npm/@makemore/agent-frontend/dist/chat-widget.js"></script>
|
|
62
|
+
```
|
|
63
|
+
|
|
35
64
|
## Quick Start
|
|
36
65
|
|
|
37
|
-
###
|
|
66
|
+
### Initialize the widget
|
|
38
67
|
|
|
39
68
|
```html
|
|
40
|
-
<
|
|
41
|
-
|
|
69
|
+
<script>
|
|
70
|
+
ChatWidget.init({
|
|
71
|
+
backendUrl: 'https://your-api.com',
|
|
72
|
+
agentKey: 'your-agent',
|
|
73
|
+
title: 'Support Chat',
|
|
74
|
+
primaryColor: '#0066cc',
|
|
75
|
+
});
|
|
76
|
+
</script>
|
|
42
77
|
```
|
|
43
78
|
|
|
44
|
-
###
|
|
79
|
+
### With custom API paths
|
|
45
80
|
|
|
46
81
|
```html
|
|
47
82
|
<script>
|
|
@@ -50,6 +85,11 @@ Most chat widgets are tightly coupled to specific frameworks or require complex
|
|
|
50
85
|
agentKey: 'your-agent',
|
|
51
86
|
title: 'Support Chat',
|
|
52
87
|
primaryColor: '#0066cc',
|
|
88
|
+
apiPaths: {
|
|
89
|
+
anonymousSession: '/api/auth/session/',
|
|
90
|
+
runs: '/api/chat/runs/',
|
|
91
|
+
runEvents: '/api/chat/runs/{runId}/events/',
|
|
92
|
+
},
|
|
53
93
|
});
|
|
54
94
|
</script>
|
|
55
95
|
```
|
|
@@ -74,6 +114,37 @@ Most chat widgets are tightly coupled to specific frameworks or require complex
|
|
|
74
114
|
| `anonymousTokenHeader` | string | `'X-Anonymous-Token'` | Header name for auth token |
|
|
75
115
|
| `conversationIdKey` | string | `'chat_widget_conversation_id'` | localStorage key for conversation ID |
|
|
76
116
|
| `sessionTokenKey` | string | `'chat_widget_session_token'` | localStorage key for session token |
|
|
117
|
+
| `apiPaths` | object | See below | API endpoint paths (customizable for different backends) |
|
|
118
|
+
|
|
119
|
+
### API Paths Configuration
|
|
120
|
+
|
|
121
|
+
The `apiPaths` option allows you to customize the backend API endpoints. This is useful when integrating with different backend frameworks or URL structures.
|
|
122
|
+
|
|
123
|
+
**Default values:**
|
|
124
|
+
```javascript
|
|
125
|
+
apiPaths: {
|
|
126
|
+
anonymousSession: '/api/accounts/anonymous-session/',
|
|
127
|
+
runs: '/api/agent-runtime/runs/',
|
|
128
|
+
runEvents: '/api/agent-runtime/runs/{runId}/events/',
|
|
129
|
+
simulateCustomer: '/api/agent-runtime/simulate-customer/',
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Example - Custom Django backend:**
|
|
134
|
+
```javascript
|
|
135
|
+
ChatWidget.init({
|
|
136
|
+
backendUrl: 'https://your-api.com',
|
|
137
|
+
agentKey: 'chat-agent',
|
|
138
|
+
apiPaths: {
|
|
139
|
+
anonymousSession: '/api/ai/agent/anonymous-session/',
|
|
140
|
+
runs: '/api/ai/agent/runs/',
|
|
141
|
+
runEvents: '/api/ai/agent/runs/{runId}/events/',
|
|
142
|
+
// simulateCustomer uses default value
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
You only need to specify the paths you want to override; unspecified paths will use the defaults.
|
|
77
148
|
|
|
78
149
|
## Journey Types Configuration
|
|
79
150
|
|
package/dist/chat-widget.js
CHANGED
|
@@ -36,6 +36,13 @@
|
|
|
36
36
|
anonymousTokenHeader: 'X-Anonymous-Token',
|
|
37
37
|
conversationIdKey: 'chat_widget_conversation_id',
|
|
38
38
|
sessionTokenKey: 'chat_widget_session_token',
|
|
39
|
+
// API endpoint paths (can be customized for different backend setups)
|
|
40
|
+
apiPaths: {
|
|
41
|
+
anonymousSession: '/api/accounts/anonymous-session/',
|
|
42
|
+
runs: '/api/agent-runtime/runs/',
|
|
43
|
+
runEvents: '/api/agent-runtime/runs/{runId}/events/',
|
|
44
|
+
simulateCustomer: '/api/agent-runtime/simulate-customer/',
|
|
45
|
+
},
|
|
39
46
|
};
|
|
40
47
|
|
|
41
48
|
// State
|
|
@@ -140,7 +147,7 @@
|
|
|
140
147
|
|
|
141
148
|
// Create new anonymous session
|
|
142
149
|
try {
|
|
143
|
-
const response = await fetch(`${config.backendUrl}
|
|
150
|
+
const response = await fetch(`${config.backendUrl}${config.apiPaths.anonymousSession}`, {
|
|
144
151
|
method: 'POST',
|
|
145
152
|
headers: { 'Content-Type': 'application/json' },
|
|
146
153
|
});
|
|
@@ -191,7 +198,7 @@
|
|
|
191
198
|
state.conversationId = getStoredValue(config.conversationIdKey);
|
|
192
199
|
}
|
|
193
200
|
|
|
194
|
-
const response = await fetch(`${config.backendUrl}
|
|
201
|
+
const response = await fetch(`${config.backendUrl}${config.apiPaths.runs}`, {
|
|
195
202
|
method: 'POST',
|
|
196
203
|
headers,
|
|
197
204
|
body: JSON.stringify({
|
|
@@ -231,7 +238,8 @@
|
|
|
231
238
|
state.eventSource.close();
|
|
232
239
|
}
|
|
233
240
|
|
|
234
|
-
|
|
241
|
+
const eventPath = config.apiPaths.runEvents.replace('{runId}', runId);
|
|
242
|
+
let url = `${config.backendUrl}${eventPath}`;
|
|
235
243
|
if (token) {
|
|
236
244
|
url += `?anonymous_token=${encodeURIComponent(token)}`;
|
|
237
245
|
}
|
|
@@ -366,7 +374,7 @@
|
|
|
366
374
|
render();
|
|
367
375
|
|
|
368
376
|
try {
|
|
369
|
-
const response = await fetch(`${config.backendUrl}
|
|
377
|
+
const response = await fetch(`${config.backendUrl}${config.apiPaths.simulateCustomer}`, {
|
|
370
378
|
method: 'POST',
|
|
371
379
|
headers: { 'Content-Type': 'application/json' },
|
|
372
380
|
body: JSON.stringify({
|
|
@@ -685,7 +693,17 @@
|
|
|
685
693
|
// ============================================================================
|
|
686
694
|
|
|
687
695
|
function init(userConfig = {}) {
|
|
688
|
-
|
|
696
|
+
// Deep merge apiPaths to allow partial overrides
|
|
697
|
+
const mergedApiPaths = {
|
|
698
|
+
...DEFAULT_CONFIG.apiPaths,
|
|
699
|
+
...(userConfig.apiPaths || {}),
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
config = {
|
|
703
|
+
...DEFAULT_CONFIG,
|
|
704
|
+
...userConfig,
|
|
705
|
+
apiPaths: mergedApiPaths,
|
|
706
|
+
};
|
|
689
707
|
state.journeyType = config.defaultJourneyType;
|
|
690
708
|
|
|
691
709
|
// Restore conversation ID
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@makemore/agent-frontend",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A standalone, zero-dependency chat widget for AI agents. Embed conversational AI into any website with a single script tag.",
|
|
5
5
|
"main": "dist/chat-widget.js",
|
|
6
6
|
"files": [
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
|
-
"url": "git+https://github.com/
|
|
19
|
+
"url": "git+https://github.com/makemore/agent-frontend.git"
|
|
20
20
|
},
|
|
21
21
|
"keywords": [
|
|
22
22
|
"chat",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"conversational-ai",
|
|
34
34
|
"customer-support"
|
|
35
35
|
],
|
|
36
|
-
"author": "
|
|
36
|
+
"author": "makemore",
|
|
37
37
|
"license": "MIT",
|
|
38
38
|
"bugs": {
|
|
39
|
-
"url": "https://github.com/
|
|
39
|
+
"url": "https://github.com/makemore/agent-frontend/issues"
|
|
40
40
|
},
|
|
41
|
-
"homepage": "https://github.com/
|
|
41
|
+
"homepage": "https://github.com/makemore/agent-frontend#readme",
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=12.0.0"
|
|
44
44
|
}
|