@bymos/agentkit-sdk 0.1.0 → 0.1.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 +184 -109
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,87 +1,149 @@
|
|
|
1
|
-
# @agentkit
|
|
1
|
+
# @bymos/agentkit-sdk
|
|
2
2
|
|
|
3
|
-
Embeddable AI chat widget for AgentForge.
|
|
3
|
+
Embeddable AI chat widget for [AgentForge](https://agentforge.io). Add a fully-featured, themeable chat widget to any website or app — via a `<script>` tag or npm.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @bymos/agentkit-sdk
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @bymos/agentkit-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
**Peer dependency:** `preact@^10.0.0`
|
|
4
14
|
|
|
5
15
|
---
|
|
6
16
|
|
|
7
|
-
##
|
|
17
|
+
## Quick start
|
|
8
18
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
### CDN (no build step)
|
|
20
|
+
|
|
21
|
+
```html
|
|
22
|
+
<script src="https://unpkg.com/@bymos/agentkit-sdk/dist/agentkit-widget.iife.js"></script>
|
|
23
|
+
<script>
|
|
24
|
+
window.AgentKit.init({
|
|
25
|
+
agentId: 'your-agent-id',
|
|
26
|
+
tenantId: 'your-tenant-id',
|
|
27
|
+
apiBaseUrl: 'https://api-agentforge.bymos.dev',
|
|
28
|
+
title: 'Support',
|
|
29
|
+
greeting: 'Hi! How can I help?',
|
|
30
|
+
});
|
|
31
|
+
</script>
|
|
20
32
|
```
|
|
21
33
|
|
|
22
|
-
|
|
34
|
+
### npm (ESM / CJS)
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { init, renderWidget, buildWidgetCSS, normalizeConfig } from '@bymos/agentkit-sdk';
|
|
23
38
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
39
|
+
const config = {
|
|
40
|
+
agentId: 'your-agent-id',
|
|
41
|
+
tenantId: 'your-tenant-id',
|
|
42
|
+
apiBaseUrl: 'https://api-agentforge.bymos.dev',
|
|
43
|
+
};
|
|
44
|
+
const widget = init(config, renderWidget, buildWidgetCSS(normalizeConfig(config)));
|
|
28
45
|
|
|
29
|
-
|
|
46
|
+
widget.on('message:received', (msg) => console.log(msg.content));
|
|
47
|
+
```
|
|
30
48
|
|
|
31
49
|
---
|
|
32
50
|
|
|
33
|
-
##
|
|
51
|
+
## Configuration
|
|
34
52
|
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
53
|
+
```ts
|
|
54
|
+
type AgentKitWidgetConfig = {
|
|
55
|
+
// Required
|
|
56
|
+
agentId: string; // Agent ID from your AgentForge dashboard
|
|
57
|
+
tenantId: string; // Tenant ID from your AgentForge dashboard
|
|
58
|
+
apiBaseUrl: string; // Base URL of your AgentForge API
|
|
39
59
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
60
|
+
// Identity (optional)
|
|
61
|
+
userId?: string;
|
|
62
|
+
authUserId?: string; // Your authenticated user ID — links widget conversations to users in your app (highest-priority contact identifier)
|
|
63
|
+
name?: string;
|
|
64
|
+
email?: string;
|
|
65
|
+
sessionId?: string; // Resume a conversation across tabs/page loads (within a tab, sessions are automatic)
|
|
43
66
|
|
|
44
|
-
|
|
67
|
+
// Display (optional)
|
|
68
|
+
mode?: 'floating' | 'inline'; // Default: 'floating'
|
|
69
|
+
title?: string;
|
|
70
|
+
greeting?: string;
|
|
71
|
+
avatarUrl?: string;
|
|
72
|
+
subtitle?: string;
|
|
73
|
+
privacyPolicyUrl?: string;
|
|
45
74
|
|
|
46
|
-
|
|
75
|
+
// Behaviour (optional)
|
|
76
|
+
streaming?: boolean; // Default: true
|
|
77
|
+
metadata?: Record<string, unknown>; // Sent with every message
|
|
78
|
+
|
|
79
|
+
// Theming (optional)
|
|
80
|
+
theme?: {
|
|
81
|
+
mode?: 'light' | 'dark' | 'system'; // Default: 'light'
|
|
82
|
+
accentColor?: string; // Default: '#6366f1'
|
|
83
|
+
fontFamily?: string;
|
|
84
|
+
borderRadius?: string; // Default: '12px'
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
At init time the widget fetches any widget config set for your agent in the AgentForge dashboard (title, greeting, avatar, etc.) and uses it as defaults. Any values you pass here override the dashboard config.
|
|
47
90
|
|
|
48
91
|
---
|
|
49
92
|
|
|
50
|
-
##
|
|
93
|
+
## Widget instance API
|
|
51
94
|
|
|
52
|
-
|
|
53
|
-
# CDN bundle (dist/agentkit-widget.iife.js + dist/agentkit-widget.js)
|
|
54
|
-
pnpm build
|
|
95
|
+
Both `init()` and `mount()` return a `WidgetInstance`:
|
|
55
96
|
|
|
56
|
-
|
|
57
|
-
|
|
97
|
+
```ts
|
|
98
|
+
widget.open();
|
|
99
|
+
widget.close();
|
|
100
|
+
widget.toggle();
|
|
101
|
+
widget.sendMessage('Hello!');
|
|
102
|
+
widget.reset(); // Clear conversation and show greeting again
|
|
103
|
+
widget.destroy();
|
|
104
|
+
widget.getState(); // → WidgetState
|
|
105
|
+
widget.on(event, fn);
|
|
106
|
+
widget.off(event, fn);
|
|
58
107
|
```
|
|
59
108
|
|
|
60
109
|
---
|
|
61
110
|
|
|
62
|
-
##
|
|
111
|
+
## Events
|
|
112
|
+
|
|
113
|
+
| Event | Payload |
|
|
114
|
+
| ---------------------- | ------------------------ |
|
|
115
|
+
| `ready` | `WidgetState` |
|
|
116
|
+
| `open` / `close` | — |
|
|
117
|
+
| `message:sent` | `WidgetMessage` |
|
|
118
|
+
| `message:received` | `WidgetMessage` |
|
|
119
|
+
| `message:error` | `{ error, message }` |
|
|
120
|
+
| `conversation:started` | `{ sessionId }` |
|
|
121
|
+
| `stream:start` | — |
|
|
122
|
+
| `stream:delta` | `{ delta, accumulated }` |
|
|
123
|
+
| `stream:end` | `{ content }` |
|
|
124
|
+
| `reset` | — |
|
|
125
|
+
| `destroy` | — |
|
|
63
126
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
theme: { accentColor: '#6366f1' },
|
|
74
|
-
});
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## CDN global API (`window.AgentKit`)
|
|
130
|
+
|
|
131
|
+
| Method | Description |
|
|
132
|
+
| ------------------------ | ---------------------------------------------------- |
|
|
133
|
+
| `init(config)` | Create a floating widget anchored to `document.body` |
|
|
134
|
+
| `mount(element, config)` | Mount a widget inline inside a DOM element |
|
|
135
|
+
| `destroy(id?)` | Destroy widget by ID, or all widgets if no ID given |
|
|
75
136
|
|
|
76
|
-
|
|
77
|
-
widget.open();
|
|
78
|
-
widget.on('message:received', (msg) => console.log(msg.content));
|
|
137
|
+
### Inline mount example
|
|
79
138
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
139
|
+
```html
|
|
140
|
+
<div id="chat"></div>
|
|
141
|
+
<script src="https://unpkg.com/@bymos/agentkit-sdk/dist/agentkit-widget.iife.js"></script>
|
|
142
|
+
<script>
|
|
143
|
+
window.AgentKit.mount(document.getElementById('chat'), {
|
|
144
|
+
agentId: 'your-agent-id',
|
|
145
|
+
tenantId: 'your-tenant-id',
|
|
146
|
+
apiBaseUrl: 'https://api-agentforge.bymos.dev',
|
|
85
147
|
mode: 'inline',
|
|
86
148
|
});
|
|
87
149
|
</script>
|
|
@@ -89,72 +151,85 @@ pnpm build:npm
|
|
|
89
151
|
|
|
90
152
|
---
|
|
91
153
|
|
|
92
|
-
##
|
|
154
|
+
## npm exports
|
|
93
155
|
|
|
94
156
|
```ts
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
157
|
+
// Lifecycle
|
|
158
|
+
import { init, mount, destroyWidget, listWidgets, createWidget } from '@bymos/agentkit-sdk';
|
|
159
|
+
|
|
160
|
+
// Config
|
|
161
|
+
import { normalizeConfig } from '@bymos/agentkit-sdk';
|
|
162
|
+
|
|
163
|
+
// Session
|
|
164
|
+
import { getSessionId, setSessionId, clearSession } from '@bymos/agentkit-sdk';
|
|
165
|
+
|
|
166
|
+
// UI (requires preact peer dep)
|
|
167
|
+
import { renderWidget, buildWidgetCSS, buildThemeVars } from '@bymos/agentkit-sdk';
|
|
168
|
+
|
|
169
|
+
// Lower-level
|
|
170
|
+
import { ApiClient, streamChat, EventEmitter } from '@bymos/agentkit-sdk';
|
|
171
|
+
import {
|
|
172
|
+
createShadowHost,
|
|
173
|
+
createFloatingContainer,
|
|
174
|
+
prepareInlineContainer,
|
|
175
|
+
} from '@bymos/agentkit-sdk';
|
|
176
|
+
|
|
177
|
+
// Types
|
|
178
|
+
import type {
|
|
179
|
+
AgentKitWidgetConfig,
|
|
180
|
+
NormalizedWidgetConfig,
|
|
181
|
+
WidgetInstance,
|
|
182
|
+
WidgetState,
|
|
183
|
+
WidgetMessage,
|
|
184
|
+
WidgetEventMap,
|
|
185
|
+
RenderFn,
|
|
186
|
+
} from '@bymos/agentkit-sdk';
|
|
105
187
|
```
|
|
106
188
|
|
|
107
189
|
---
|
|
108
190
|
|
|
109
|
-
##
|
|
191
|
+
## Session management
|
|
110
192
|
|
|
111
|
-
|
|
112
|
-
widget.open();
|
|
113
|
-
widget.close();
|
|
114
|
-
widget.toggle();
|
|
115
|
-
widget.sendMessage('Hello!');
|
|
116
|
-
widget.getState(); // → WidgetState
|
|
117
|
-
widget.on('event', handler);
|
|
118
|
-
widget.off('event', handler);
|
|
119
|
-
widget.destroy();
|
|
120
|
-
```
|
|
193
|
+
Within a browser tab, sessions are automatic — the SDK reads and writes `sessionStorage` keyed by `agentId` with no configuration needed. Sessions are cleared when the tab closes.
|
|
121
194
|
|
|
122
|
-
|
|
195
|
+
To persist a conversation across tabs or page reloads, save and restore the session ID yourself:
|
|
123
196
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
197
|
+
```ts
|
|
198
|
+
widget.on('conversation:started', ({ sessionId }) => {
|
|
199
|
+
localStorage.setItem('chat-session', sessionId);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// Later, on next load:
|
|
203
|
+
const widget = window.AgentKit.init({
|
|
204
|
+
agentId: 'your-agent-id',
|
|
205
|
+
tenantId: 'your-tenant-id',
|
|
206
|
+
apiBaseUrl: '...',
|
|
207
|
+
sessionId: localStorage.getItem('chat-session') ?? undefined,
|
|
208
|
+
});
|
|
209
|
+
```
|
|
135
210
|
|
|
136
211
|
---
|
|
137
212
|
|
|
138
|
-
##
|
|
213
|
+
## Theming
|
|
214
|
+
|
|
215
|
+
The widget renders inside a **Shadow DOM** to prevent CSS conflicts with your page. Use the `theme` config to customise it:
|
|
139
216
|
|
|
140
217
|
```ts
|
|
141
|
-
|
|
142
|
-
agentId:
|
|
143
|
-
apiBaseUrl:
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
theme?: {
|
|
152
|
-
mode?: 'light' | 'dark' | 'system';
|
|
153
|
-
accentColor?: string;
|
|
154
|
-
fontFamily?: string;
|
|
155
|
-
borderRadius?: string;
|
|
156
|
-
};
|
|
157
|
-
};
|
|
218
|
+
window.AgentKit.init({
|
|
219
|
+
agentId: 'your-agent-id',
|
|
220
|
+
apiBaseUrl: '...',
|
|
221
|
+
theme: {
|
|
222
|
+
mode: 'dark',
|
|
223
|
+
accentColor: '#ec4899',
|
|
224
|
+
fontFamily: "'Inter', sans-serif",
|
|
225
|
+
borderRadius: '8px',
|
|
226
|
+
},
|
|
227
|
+
});
|
|
158
228
|
```
|
|
159
229
|
|
|
160
|
-
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## Requirements
|
|
233
|
+
|
|
234
|
+
- Node.js ≥ 18 (for npm usage)
|
|
235
|
+
- Modern browser with Shadow DOM support
|