@bymos/agentkit-sdk 0.1.2 → 0.1.4
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/index.cjs +806 -0
- package/index.d.ts +134 -0
- package/index.js +6860 -0
- package/package.json +8 -30
- package/README.md +0 -235
package/package.json
CHANGED
|
@@ -1,47 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bymos/agentkit-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "AgentKit embeddable widget — CDN build and npm package",
|
|
6
|
-
"main": "./
|
|
7
|
-
"module": "./
|
|
8
|
-
"types": "./
|
|
6
|
+
"main": "./index.cjs",
|
|
7
|
+
"module": "./index.js",
|
|
8
|
+
"types": "./index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"import": "./
|
|
12
|
-
"require": "./
|
|
13
|
-
"types": "./
|
|
11
|
+
"import": "./index.js",
|
|
12
|
+
"require": "./index.cjs",
|
|
13
|
+
"types": "./index.d.ts"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
|
-
"files": [
|
|
17
|
-
"dist/npm",
|
|
18
|
-
"dist/agentkit-widget.iife.js",
|
|
19
|
-
"dist/agentkit-widget.js"
|
|
20
|
-
],
|
|
21
|
-
"scripts": {
|
|
22
|
-
"build": "vite build --mode cdn",
|
|
23
|
-
"build:cdn": "vite build --mode cdn",
|
|
24
|
-
"build:npm": "vite build --mode npm && node scripts/create-npm-package.js",
|
|
25
|
-
"build:all": "pnpm build:cdn && pnpm build:npm",
|
|
26
|
-
"preview": "vite preview",
|
|
27
|
-
"lint": "eslint src/",
|
|
28
|
-
"typecheck": "tsc --noEmit"
|
|
29
|
-
},
|
|
30
16
|
"dependencies": {
|
|
31
|
-
"@agentkit/widget-sdk": "workspace:*",
|
|
32
|
-
"@agentkit/widget-ui": "workspace:*",
|
|
33
17
|
"preact": "^10.28.4"
|
|
34
18
|
},
|
|
35
|
-
"devDependencies": {
|
|
36
|
-
"@preact/preset-vite": "^2.10.3",
|
|
37
|
-
"typescript": "^5.0.0",
|
|
38
|
-
"vite": "^5.0.0",
|
|
39
|
-
"vite-plugin-dts": "^4.5.4"
|
|
40
|
-
},
|
|
41
19
|
"peerDependencies": {
|
|
42
20
|
"preact": "^10.0.0"
|
|
43
21
|
},
|
|
44
22
|
"engines": {
|
|
45
23
|
"node": ">=18"
|
|
46
24
|
}
|
|
47
|
-
}
|
|
25
|
+
}
|
package/README.md
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
# @bymos/agentkit-sdk
|
|
2
|
-
|
|
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`
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
## Quick start
|
|
18
|
-
|
|
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>
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
### npm (ESM / CJS)
|
|
35
|
-
|
|
36
|
-
```ts
|
|
37
|
-
import { init, renderWidget, buildWidgetCSS, normalizeConfig } from '@bymos/agentkit-sdk';
|
|
38
|
-
|
|
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)));
|
|
45
|
-
|
|
46
|
-
widget.on('message:received', (msg) => console.log(msg.content));
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
---
|
|
50
|
-
|
|
51
|
-
## Configuration
|
|
52
|
-
|
|
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
|
|
59
|
-
|
|
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)
|
|
66
|
-
|
|
67
|
-
// Display (optional)
|
|
68
|
-
mode?: 'floating' | 'inline'; // Default: 'floating'
|
|
69
|
-
title?: string;
|
|
70
|
-
greeting?: string;
|
|
71
|
-
avatarUrl?: string;
|
|
72
|
-
subtitle?: string;
|
|
73
|
-
privacyPolicyUrl?: string;
|
|
74
|
-
|
|
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.
|
|
90
|
-
|
|
91
|
-
---
|
|
92
|
-
|
|
93
|
-
## Widget instance API
|
|
94
|
-
|
|
95
|
-
Both `init()` and `mount()` return a `WidgetInstance`:
|
|
96
|
-
|
|
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);
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
---
|
|
110
|
-
|
|
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` | — |
|
|
126
|
-
|
|
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 |
|
|
136
|
-
|
|
137
|
-
### Inline mount example
|
|
138
|
-
|
|
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',
|
|
147
|
-
mode: 'inline',
|
|
148
|
-
});
|
|
149
|
-
</script>
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
---
|
|
153
|
-
|
|
154
|
-
## npm exports
|
|
155
|
-
|
|
156
|
-
```ts
|
|
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';
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
---
|
|
190
|
-
|
|
191
|
-
## Session management
|
|
192
|
-
|
|
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.
|
|
194
|
-
|
|
195
|
-
To persist a conversation across tabs or page reloads, save and restore the session ID yourself:
|
|
196
|
-
|
|
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
|
-
```
|
|
210
|
-
|
|
211
|
-
---
|
|
212
|
-
|
|
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:
|
|
216
|
-
|
|
217
|
-
```ts
|
|
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
|
-
});
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
---
|
|
231
|
-
|
|
232
|
-
## Requirements
|
|
233
|
-
|
|
234
|
-
- Node.js ≥ 18 (for npm usage)
|
|
235
|
-
- Modern browser with Shadow DOM support
|