@bymos/agentkit-sdk 0.6.2 → 0.6.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/README.md CHANGED
@@ -16,36 +16,58 @@ pnpm add @bymos/agentkit-sdk
16
16
 
17
17
  ## Quick start
18
18
 
19
+ Both integration paths take the **same single-argument config**.
20
+
19
21
  ### CDN (no build step)
20
22
 
21
23
  ```html
22
- <script src="https://unpkg.com/@bymos/agentkit-sdk@0.5.0/agentkit-widget.iife.js"></script>
24
+ <script src="https://unpkg.com/@bymos/agentkit-sdk@0.6/agentkit-widget.iife.js"></script>
23
25
  <script>
24
26
  window.AgentKit.init({
25
27
  agentId: 'your-agent-id',
26
28
  tenantId: 'your-tenant-id',
27
29
  apiBaseUrl: 'https://api.klicforge.ai',
28
30
  title: 'Support',
29
- greeting: 'Hi! How can I help?',
30
31
  });
31
32
  </script>
32
33
  ```
33
34
 
35
+ The `@0.6` pin tracks the latest patch of that minor line. Pin an exact version
36
+ (`@0.6.3`) if you need byte-identical builds, and add
37
+ [SRI](https://developer.mozilla.org/docs/Web/Security/Subresource_Integrity)
38
+ (`integrity` + `crossorigin="anonymous"`) when you do — an SRI hash only holds
39
+ against an exact version.
40
+
34
41
  ### npm (ESM / CJS)
35
42
 
36
43
  ```ts
37
- import { init, renderWidget, buildWidgetCSS, normalizeConfig } from '@bymos/agentkit-sdk';
44
+ import { init } from '@bymos/agentkit-sdk';
38
45
 
39
- const config = {
46
+ const widget = init({
40
47
  agentId: 'your-agent-id',
41
48
  tenantId: 'your-tenant-id',
42
49
  apiBaseUrl: 'https://api.klicforge.ai',
43
- };
44
- const widget = init(config, renderWidget, buildWidgetCSS(normalizeConfig(config)));
50
+ });
45
51
 
46
52
  widget.on('message:received', (msg) => console.log(msg.content));
47
53
  ```
48
54
 
55
+ `init` and `mount` default their renderer and stylesheet to the bundled UI. To
56
+ supply your own UI layer, pass them explicitly —
57
+ `init(config, myRenderer, myCss)` — which is also the pre-0.6 call shape and
58
+ still works unchanged.
59
+
60
+ ---
61
+
62
+ ## Before it will run: allow your domain
63
+
64
+ The API rejects widget traffic from any origin that is not on the agent's
65
+ allowlist. In the KlicForge dashboard open your agent → **Channels** → **Widget**
66
+ and add every origin the widget loads from (`https://example.com`,
67
+ `https://www.example.com` — scheme and host must match exactly; there are no
68
+ wildcards). Without this the widget renders an access-restricted panel instead of
69
+ a chat.
70
+
49
71
  ---
50
72
 
51
73
  ## Configuration
@@ -53,24 +75,30 @@ widget.on('message:received', (msg) => console.log(msg.content));
53
75
  ```ts
54
76
  type AgentKitWidgetConfig = {
55
77
  // Required
56
- agentId: string; // Agent ID from your KlicForge dashboard
57
- tenantId: string; // Tenant ID from your KlicForge dashboard
78
+ agentId: string; // Agent ID or slug from your KlicForge dashboard
58
79
  apiBaseUrl: string; // Base URL of your KlicForge API
59
80
 
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)
81
+ // Strongly recommended — required for conversation tracking and validation
82
+ tenantId?: string;
83
+
84
+ // Identity of the end user in your app (all optional; omit for anonymous)
85
+ user?: {
86
+ externalId?: string; // Your own identifier — DB ID, UUID, email, anything
87
+ authId?: string; // ID from your auth system (JWT sub, Clerk userId, …)
88
+ name?: string;
89
+ email?: string;
90
+ };
91
+ sessionId?: string; // Resume a conversation across tabs/page loads
66
92
 
67
93
  // Display (optional)
68
94
  mode?: 'floating' | 'inline'; // Default: 'floating'
69
- title?: string;
70
- greeting?: string;
95
+ title?: string; // Default: 'AI Assistant'
96
+ subtitle?: string; // Shown under the agent name in the header
97
+ description?: string; // Shown in the empty state
71
98
  avatarUrl?: string;
72
- subtitle?: string;
73
99
  privacyPolicyUrl?: string;
100
+ termsOfServiceUrl?: string;
101
+ disclosureText?: string; // AI processing notice; pass '' to hide it
74
102
 
75
103
  // Behaviour (optional)
76
104
  streaming?: boolean; // Default: true
@@ -80,32 +108,49 @@ type AgentKitWidgetConfig = {
80
108
  theme?: {
81
109
  mode?: 'light' | 'dark' | 'system'; // Default: 'light'
82
110
  accentColor?: string; // Default: '#6366f1'
83
- fontFamily?: string;
111
+ fontFamily?: string; // Default: system UI stack
84
112
  borderRadius?: string; // Default: '12px'
85
113
  };
86
114
  };
87
115
  ```
88
116
 
89
- At init time the widget fetches any widget config set for your agent in the KlicForge dashboard (title, greeting, avatar, etc.) and uses it as defaults. Any values you pass here override the dashboard config.
117
+ Config is validated at init — an invalid value throws a `ZodError`, so wrap
118
+ `init()` in a try/catch if the values are user-supplied.
119
+
120
+ At init time the widget fetches the widget config set for your agent in the
121
+ KlicForge dashboard (title, avatar, suggested questions, attachment limits) and
122
+ uses it as defaults. Anything you pass here overrides it.
123
+
124
+ Suggested questions, photo/file upload and attachment limits are **server-only** —
125
+ configure them on the agent in the dashboard; they cannot be set from the host page.
126
+
127
+ Your agent always serves its **published** version. `preview`, `skipServerConfigFetch`
128
+ and `configChannel` are dashboard-internal: they only do anything for a caller
129
+ holding a KlicForge session cookie for the owning tenant, so setting them on a
130
+ public site has no effect.
90
131
 
91
132
  ---
92
133
 
93
134
  ## Widget instance API
94
135
 
95
- Both `init()` and `mount()` return a `WidgetInstance`:
136
+ `init()`, `mount()` and `mountFloating()` all return a `WidgetInstance`:
96
137
 
97
138
  ```ts
98
139
  widget.open();
99
140
  widget.close();
100
141
  widget.toggle();
101
142
  widget.sendMessage('Hello!');
102
- widget.reset(); // Clear conversation and show greeting again
103
- widget.destroy();
143
+ widget.sendMessage('See this', [{ file, kind: 'image' }]);
144
+ widget.reset(); // Clear the conversation and start over
145
+ widget.destroy(); // Tears down the DOM and closes the event stream
104
146
  widget.getState(); // → WidgetState
105
147
  widget.on(event, fn);
106
148
  widget.off(event, fn);
107
149
  ```
108
150
 
151
+ Call `destroy()` when unmounting in an SPA — it closes the operator-reply event
152
+ stream, which otherwise reconnects indefinitely.
153
+
109
154
  ---
110
155
 
111
156
  ## Events
@@ -121,9 +166,13 @@ widget.off(event, fn);
121
166
  | `stream:start` | — |
122
167
  | `stream:delta` | `{ delta, accumulated }` |
123
168
  | `stream:end` | `{ content }` |
169
+ | `control_mode_changed` | `{ mode }` |
124
170
  | `reset` | — |
125
171
  | `destroy` | — |
126
172
 
173
+ `control_mode_changed` fires when a human operator takes over the conversation
174
+ or hands it back to the agent.
175
+
127
176
  ---
128
177
 
129
178
  ## CDN global API (`window.AgentKit`)
@@ -138,24 +187,26 @@ widget.off(event, fn);
138
187
 
139
188
  ```html
140
189
  <div id="chat"></div>
141
- <script src="https://unpkg.com/@bymos/agentkit-sdk@0.5.0/agentkit-widget.iife.js"></script>
190
+ <script src="https://unpkg.com/@bymos/agentkit-sdk@0.6/agentkit-widget.iife.js"></script>
142
191
  <script>
143
192
  window.AgentKit.mount(document.getElementById('chat'), {
144
193
  agentId: 'your-agent-id',
145
194
  tenantId: 'your-tenant-id',
146
195
  apiBaseUrl: 'https://api.klicforge.ai',
147
- mode: 'inline',
148
196
  });
149
197
  </script>
150
198
  ```
151
199
 
200
+ `mount()` always renders inline — there is no need to pass `mode`.
201
+
152
202
  ---
153
203
 
154
204
  ## npm exports
155
205
 
156
206
  ```ts
157
207
  // Lifecycle
158
- import { init, mount, destroyWidget, listWidgets, createWidget } from '@bymos/agentkit-sdk';
208
+ import { init, mount, mountFloating, destroy } from '@bymos/agentkit-sdk';
209
+ import { destroyWidget, listWidgets, createWidget } from '@bymos/agentkit-sdk';
159
210
 
160
211
  // Config
161
212
  import { normalizeConfig } from '@bymos/agentkit-sdk';
@@ -163,7 +214,7 @@ import { normalizeConfig } from '@bymos/agentkit-sdk';
163
214
  // Session
164
215
  import { getSessionId, setSessionId, clearSession } from '@bymos/agentkit-sdk';
165
216
 
166
- // UI (requires preact peer dep)
217
+ // UI (requires the preact peer dep)
167
218
  import { renderWidget, buildWidgetCSS, buildThemeVars } from '@bymos/agentkit-sdk';
168
219
 
169
220
  // Lower-level
@@ -186,24 +237,32 @@ import type {
186
237
  } from '@bymos/agentkit-sdk';
187
238
  ```
188
239
 
240
+ `mountFloating(element, config)` anchors the launcher inside a specific element
241
+ rather than the page — useful for previews and bounded layouts.
242
+
189
243
  ---
190
244
 
191
245
  ## Session management
192
246
 
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.
247
+ Within a browser tab, sessions are automatic — the SDK reads and writes
248
+ `sessionStorage` keyed by `agentId` with no configuration needed. Sessions are
249
+ cleared when the tab closes, and storage access is failure-tolerant: in Safari
250
+ private mode or a partitioned third-party context the widget simply starts a new
251
+ conversation on each load rather than erroring.
194
252
 
195
- To persist a conversation across tabs or page reloads, save and restore the session ID yourself:
253
+ To persist a conversation across tabs or page reloads, save and restore the
254
+ session ID yourself:
196
255
 
197
256
  ```ts
198
257
  widget.on('conversation:started', ({ sessionId }) => {
199
258
  localStorage.setItem('chat-session', sessionId);
200
259
  });
201
260
 
202
- // Later, on next load:
261
+ // Later, on the next load:
203
262
  const widget = window.AgentKit.init({
204
263
  agentId: 'your-agent-id',
205
264
  tenantId: 'your-tenant-id',
206
- apiBaseUrl: '...',
265
+ apiBaseUrl: 'https://api.klicforge.ai',
207
266
  sessionId: localStorage.getItem('chat-session') ?? undefined,
208
267
  });
209
268
  ```
@@ -212,12 +271,14 @@ const widget = window.AgentKit.init({
212
271
 
213
272
  ## Theming
214
273
 
215
- The widget renders inside a **Shadow DOM** to prevent CSS conflicts with your page. Use the `theme` config to customise it:
274
+ The widget renders inside a **Shadow DOM** to prevent CSS conflicts with your
275
+ page. Use the `theme` config to customise it:
216
276
 
217
277
  ```ts
218
278
  window.AgentKit.init({
219
279
  agentId: 'your-agent-id',
220
- apiBaseUrl: '...',
280
+ tenantId: 'your-tenant-id',
281
+ apiBaseUrl: 'https://api.klicforge.ai',
221
282
  theme: {
222
283
  mode: 'dark',
223
284
  accentColor: '#ec4899',
@@ -227,6 +288,26 @@ window.AgentKit.init({
227
288
  });
228
289
  ```
229
290
 
291
+ Theme values become CSS custom properties inside the shadow root —
292
+ `--ak-accent`, `--ak-accent-hover`, `--ak-font`, `--ak-radius`. Setting those
293
+ variables on your own page has no effect; pass `theme` instead.
294
+
295
+ ---
296
+
297
+ ## Content Security Policy
298
+
299
+ If your site sends a CSP, the widget needs:
300
+
301
+ | Directive | Value |
302
+ | ------------- | ------------------------------------------------------------ |
303
+ | `script-src` | `https://unpkg.com` (CDN install only) |
304
+ | `connect-src` | your `apiBaseUrl` |
305
+ | `img-src` | your `apiBaseUrl` and any avatar host, plus `data:` |
306
+ | `style-src` | `'unsafe-inline'` — styles are injected into the shadow root |
307
+
308
+ Shadow DOM does not exempt inline styles from CSP, so `style-src 'unsafe-inline'`
309
+ is currently required.
310
+
230
311
  ---
231
312
 
232
313
  ## Requirements