@bymos/agentkit-sdk 0.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 +160 -0
- package/dist/agentkit-widget.iife.js +802 -0
- package/dist/agentkit-widget.js +7398 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# @agentkit/widget
|
|
2
|
+
|
|
3
|
+
Embeddable AI chat widget for AgentForge. Ships as a CDN bundle (IIFE), an ESM npm package, and a local development playground.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Architecture
|
|
8
|
+
|
|
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
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The widget is split across two packages:
|
|
23
|
+
|
|
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. |
|
|
28
|
+
|
|
29
|
+
`apps/widget` wires them together and produces the distributable bundles.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Running the playground
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# From the repo root:
|
|
37
|
+
pnpm install
|
|
38
|
+
pnpm dev:widget
|
|
39
|
+
|
|
40
|
+
# Or from this directory:
|
|
41
|
+
pnpm dev
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Playground opens at **http://localhost:5173**.
|
|
45
|
+
|
|
46
|
+
> Make sure the API is also running: `pnpm --filter @agentkit/api dev` (http://localhost:3000)
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Building
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# CDN bundle (dist/agentkit-widget.iife.js + dist/agentkit-widget.js)
|
|
54
|
+
pnpm build
|
|
55
|
+
|
|
56
|
+
# npm ESM/CJS bundle (dist/npm/)
|
|
57
|
+
pnpm build:npm
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Embedding via CDN (browser global)
|
|
63
|
+
|
|
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
|
+
});
|
|
75
|
+
|
|
76
|
+
// Programmatic control
|
|
77
|
+
widget.open();
|
|
78
|
+
widget.on('message:received', (msg) => console.log(msg.content));
|
|
79
|
+
|
|
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',
|
|
85
|
+
mode: 'inline',
|
|
86
|
+
});
|
|
87
|
+
</script>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## Using as an npm package
|
|
93
|
+
|
|
94
|
+
```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));
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Widget instance API
|
|
110
|
+
|
|
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
|
+
```
|
|
121
|
+
|
|
122
|
+
### Events
|
|
123
|
+
|
|
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` | — |
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Config
|
|
139
|
+
|
|
140
|
+
```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
|
+
};
|
|
158
|
+
```
|
|
159
|
+
|
|
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.
|