@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.
Files changed (2) hide show
  1. package/README.md +184 -109
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,87 +1,149 @@
1
- # @agentkit/widget
1
+ # @bymos/agentkit-sdk
2
2
 
3
- Embeddable AI chat widget for AgentForge. Ships as a CDN bundle (IIFE), an ESM npm package, and a local development playground.
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
- ## Architecture
17
+ ## Quick start
8
18
 
9
- ```
10
- apps/widget/
11
- src/
12
- cdn-entry.ts → window.AgentKit browser global
13
- npm-entry.ts → re-exports for ESM/CJS npm consumers
14
- playground/
15
- index.html → demo page
16
- main.tsx → demo wiring
17
-
18
- packages/widget-sdk/ → headless SDK core (no React, no UI)
19
- packages/widget-ui/ → React UI components + theme
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
- The widget is split across two packages:
34
+ ### npm (ESM / CJS)
35
+
36
+ ```ts
37
+ import { init, renderWidget, buildWidgetCSS, normalizeConfig } from '@bymos/agentkit-sdk';
23
38
 
24
- | Package | Role |
25
- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
26
- | `@agentkit/widget-sdk` | Framework-agnostic browser core: config, API client, session storage, event emitter, DOM mounting, widget lifecycle controller |
27
- | `@agentkit/widget-ui` | React 18 components: `WidgetApp`, `WidgetShell`, `Launcher`, `MessageList`, `Composer`, etc. |
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
- `apps/widget` wires them together and produces the distributable bundles.
46
+ widget.on('message:received', (msg) => console.log(msg.content));
47
+ ```
30
48
 
31
49
  ---
32
50
 
33
- ## Running the playground
51
+ ## Configuration
34
52
 
35
- ```bash
36
- # From the repo root:
37
- pnpm install
38
- pnpm dev:widget
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
- # Or from this directory:
41
- pnpm dev
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
- Playground opens at **http://localhost:5173**.
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
- > Make sure the API is also running: `pnpm --filter @agentkit/api dev` (http://localhost:3000)
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
- ## Building
93
+ ## Widget instance API
51
94
 
52
- ```bash
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
- # npm ESM/CJS bundle (dist/npm/)
57
- pnpm build:npm
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
- ## Embedding via CDN (browser global)
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
- ```html
65
- <script src="agentkit-widget.iife.js"></script>
66
- <script>
67
- // Floating widget (bottom-right)
68
- const widget = window.AgentKit.init({
69
- agentId: 'demo-agent',
70
- apiBaseUrl: 'https://your-api.example.com',
71
- title: 'Support',
72
- greeting: 'Hi! How can I help?',
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
- // Programmatic control
77
- widget.open();
78
- widget.on('message:received', (msg) => console.log(msg.content));
137
+ ### Inline mount example
79
138
 
80
- // Inline mount into a DOM element
81
- const el = document.getElementById('chat-container');
82
- window.AgentKit.mount(el, {
83
- agentId: 'demo-agent',
84
- apiBaseUrl: 'https://your-api.example.com',
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
- ## Using as an npm package
154
+ ## npm exports
93
155
 
94
156
  ```ts
95
- import { init, mount, renderWidget, buildWidgetCSS, normalizeConfig } from '@agentkit/widget';
96
-
97
- const config = { agentId: 'demo-agent', apiBaseUrl: 'https://api.example.com' };
98
- const normalized = normalizeConfig(config);
99
- const css = buildWidgetCSS(normalized);
100
-
101
- const widget = init(config, renderWidget, css);
102
-
103
- widget.on('ready', (state) => console.log('Widget ready', state.sessionId));
104
- widget.on('message:received', (msg) => console.log(msg.content));
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
- ## Widget instance API
191
+ ## Session management
110
192
 
111
- ```ts
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
- ### Events
195
+ To persist a conversation across tabs or page reloads, save and restore the session ID yourself:
123
196
 
124
- | Event | Payload |
125
- | ----------------------------- | ------------------------ |
126
- | `ready` | `WidgetState` |
127
- | `open` / `close` | — |
128
- | `message:sent` | `WidgetMessage` |
129
- | `message:received` | `WidgetMessage` |
130
- | `message:error` | `{ error, message }` |
131
- | `conversation:started` | `{ sessionId }` |
132
- | `stream:start` / `stream:end` | `—` / `{ content }` |
133
- | `stream:delta` | `{ delta, accumulated }` |
134
- | `destroy` | — |
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
- ## Config
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
- type AgentKitWidgetConfig = {
142
- agentId: string; // required
143
- apiBaseUrl: string; // required
144
- userId?: string;
145
- sessionId?: string; // overrides localStorage session
146
- mode?: 'floating' | 'inline';
147
- title?: string;
148
- greeting?: string;
149
- streaming?: boolean;
150
- metadata?: Record<string, unknown>;
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
- Server-side widget config (`GET /v1/agents/:agentId/widget-config`) is fetched at init time and merged as defaults; local config overrides always win.
230
+ ---
231
+
232
+ ## Requirements
233
+
234
+ - Node.js ≥ 18 (for npm usage)
235
+ - Modern browser with Shadow DOM support
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bymos/agentkit-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "description": "AgentKit embeddable widget — CDN build and npm package",
6
6
  "main": "./dist/npm/index.cjs",