@mcp-b/char 0.0.0-beta-20260124143827

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/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Kukumis Inc. Proprietary License
2
+
3
+ Copyright (c) 2025 Kukumis Inc. All rights reserved.
4
+
5
+ This software, including all source code, object code, documentation, and any
6
+ related materials (collectively, the "Software"), is proprietary to Kukumis
7
+ Inc. and is protected by applicable intellectual property laws.
8
+
9
+ No part of the Software may be used, copied, modified, merged, published,
10
+ distributed, sublicensed, and/or sold, in whole or in part, except as expressly
11
+ authorized in a written license agreement signed by Kukumis Inc.
12
+
13
+ No license or other rights are granted by Kukumis Inc. under any patents,
14
+ copyrights, trade secrets, trademarks, or other intellectual property rights,
15
+ whether by implication, estoppel, or otherwise, except as expressly set forth
16
+ in such written license agreement.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21
+ KUKUMIS INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,367 @@
1
+ # @mcp-b/embedded-agent
2
+
3
+ An Intercom-like AI chat widget with MCP tool support and voice mode. Drop it into your app and you're done.
4
+
5
+ Styles are isolated using Shadow DOM. Customize appearance by setting CSS variables on the host page.
6
+
7
+ ## Build Architecture
8
+
9
+ This package provides the `` custom element in two formats:
10
+
11
+ | Export | Format | Use Case |
12
+ |--------|--------|----------|
13
+ | `@mcp-b/embedded-agent` / `@mcp-b/embedded-agent/web-component` | ESM web component | Bundlers, monorepo dev |
14
+ | `@mcp-b/embedded-agent/standalone` | IIFE web component | `<script>` tag embeds |
15
+
16
+ ### Bundle Sizes
17
+
18
+ | Build | Size | Gzipped | Use Case |
19
+ |-------|------|---------|----------|
20
+ | ESM | ~560 KB | ~115 KB | Bundlers (React externalized) |
21
+ | Standalone IIFE | ~2.2 MB | ~400 KB | Script tag embeds |
22
+
23
+ The standalone IIFE includes React, so it's larger but works on any website without dependencies.
24
+
25
+ ### Why Two Builds?
26
+
27
+ **ESM Build** (root export or `/web-component`)
28
+ - Web component entrypoint for bundlers
29
+ - React is externalized via `peerDependencies` (install `react` and `react-dom`)
30
+ - Smaller bundle; no duplicate React if the host already uses it
31
+ - Uses Shadow DOM for style isolation
32
+ - Use for: bundlers, monorepo consumers
33
+
34
+ **Standalone IIFE Build** (`/standalone`)
35
+ - Web component via `<script>` tag
36
+ - React is bundled inside the package
37
+ - Uses Shadow DOM for complete JS/CSS isolation
38
+ - Separate React instances in separate DOM trees = no conflict
39
+ - Use for: `<script>` tag embedding on any website (React or not)
40
+
41
+ ### The "Two Reacts" Problem
42
+
43
+ When a React app loads the standalone bundle, you get duplicate React instances which causes the infamous "hooks can only be called inside a function component" error.
44
+
45
+ **Shadow DOM solves this**: Each React instance manages its own separate DOM tree inside the shadow boundary, so they never conflict.
46
+
47
+ ```
48
+ Host Page (React 18)
49
+ ├── <div id="root"> ← Host's React
50
+ │ └── ... host app ...
51
+
52
+ └──
53
+ └── #shadow-root ← Isolation boundary
54
+ └── <div> ← Bundled React 19
55
+ └── ... widget ...
56
+ ```
57
+
58
+ ## Installation
59
+
60
+ ```bash
61
+ npm install @mcp-b/embedded-agent
62
+ ```
63
+
64
+ ## Usage
65
+
66
+ `` renders as a full-viewport overlay.
67
+
68
+ ### Recommended: Imperative Authentication (Secure)
69
+
70
+ The `connect()` method is the recommended way to authenticate. It keeps tokens out of DOM attributes, preventing exposure to session replay tools, error reporters, and DOM inspectors.
71
+
72
+ ```tsx
73
+ import { useRef, useEffect } from "react";
74
+ import "@mcp-b/embedded-agent/web-component";
75
+ import type { WebMCPAgentElement } from "@mcp-b/embedded-agent/web-component";
76
+
77
+ function App() {
78
+ const { session } = useOktaAuth(); // or Azure, Auth0, Google, etc.
79
+ const agentRef = useRef<WebMCPAgentElement>(null);
80
+
81
+ useEffect(() => {
82
+ if (agentRef.current && session?.idToken) {
83
+ agentRef.current.connect({ idToken: session.idToken });
84
+ }
85
+ }, [session?.idToken]);
86
+
87
+ return <char-agent ref={agentRef} />;
88
+ }
89
+ ```
90
+
91
+ ### Vanilla JavaScript
92
+
93
+ ```html
94
+ </char-agent>
95
+
96
+ <script type="module">
97
+ import "@mcp-b/embedded-agent/web-component";
98
+
99
+ const agent = document.querySelector("char-agent");
100
+ // Call connect() when you have the token
101
+ agent.connect({ idToken: "eyJhbGciOi..." });
102
+ </script>
103
+ ```
104
+
105
+ ### Monorepo Dogfooding
106
+
107
+ ```tsx
108
+ import { useRef, useEffect } from "react";
109
+ import "@mcp-b/embedded-agent/web-component";
110
+ import type { WebMCPAgentElement } from "@mcp-b/embedded-agent/web-component";
111
+
112
+ const authToken = session?.idToken ?? "";
113
+ const agentRef = useRef<WebMCPAgentElement>(null);
114
+
115
+ useEffect(() => {
116
+ const agent = agentRef.current ?? document.querySelector("char-agent");
117
+
118
+ if (!agent) {
119
+ const newAgent = document.createElement("char-agent");
120
+ document.body.appendChild(newAgent);
121
+ // Connect after element is in DOM
122
+ (newAgent as WebMCPAgentElement).connect({ idToken: authToken });
123
+ } else if (authToken) {
124
+ (agent as WebMCPAgentElement).connect({ idToken: authToken });
125
+ }
126
+
127
+ // Set other attributes (these don't contain sensitive data)
128
+ agent?.setAttribute("dev-mode", JSON.stringify({ useLocalApi: true }));
129
+ agent?.setAttribute("enable-debug-tools", String(import.meta.env.DEV));
130
+ }, [authToken]);
131
+
132
+ return <char-agent ref={agentRef} />;
133
+ ```
134
+
135
+ ### Script Tag (Any Website)
136
+
137
+ Use `defer` for best performance - it loads the script without blocking page rendering:
138
+
139
+ ```html
140
+ <!-- Recommended: defer loads async, executes after DOM ready -->
141
+ <script src="https://unpkg.com/@mcp-b/embedded-agent/dist/web-component-standalone.iife.js" defer></script>
142
+ </char-agent>
143
+
144
+ <script>
145
+ // Authenticate after the page loads (tokens not in DOM attributes)
146
+ document.addEventListener('DOMContentLoaded', () => {
147
+ const agent = document.querySelector('char-agent');
148
+ // Get your token from your auth provider
149
+ agent.connect({ idToken: yourIdpToken });
150
+ });
151
+ </script>
152
+ ```
153
+
154
+ Alternative CDN (jsdelivr):
155
+
156
+ ```html
157
+ <script src="https://cdn.jsdelivr.net/npm/@mcp-b/embedded-agent/dist/web-component-standalone.iife.js" defer></script>
158
+ ```
159
+
160
+ Pin to a specific version for production:
161
+
162
+ ```html
163
+ <script src="https://unpkg.com/@mcp-b/embedded-agent@1.2.7/dist/web-component-standalone.iife.js" defer></script>
164
+ ```
165
+
166
+ ### Web Component Attributes
167
+
168
+ ```html
169
+ <!-- PREFERRED: Use connect() method instead of auth-token attribute -->
170
+ <char-agent
171
+ dev-mode='{"anthropicApiKey": "sk-ant-..."}'
172
+ enable-debug-tools="true"
173
+ ></char-agent>
174
+
175
+ <script>
176
+ const agent = document.querySelector('char-agent');
177
+ agent.connect({ idToken: 'eyJhbGciOi...' });
178
+ </script>
179
+ ```
180
+
181
+ ## Props / Attributes
182
+
183
+ | Prop | Attribute | Type | Description |
184
+ |------|-----------|------|-------------|
185
+ | - | - | method | `connect({ idToken })` - Secure authentication (token not in DOM) |
186
+ | - | - | method | `connect({ ticketAuth })` - SSR-friendly authentication (pre-fetched ticket) |
187
+ | - | - | method | `disconnect()` - Clear authentication |
188
+ | `open` | `open` | boolean | Controlled open state (optional) |
189
+ | `devMode` | `dev-mode` | object/JSON | Development mode config (optional) |
190
+ | `enableDebugTools` | `enable-debug-tools` | boolean | Enable debug tools (default: false) |
191
+
192
+ ## Customization
193
+
194
+ Customize appearance by setting CSS variables on the host page:
195
+
196
+ ```css
197
+ char {
198
+ /* Brand colors */
199
+ --wm-color-primary: #8b5cf6;
200
+ --wm-color-primary-foreground: #ffffff;
201
+
202
+ /* Layout */
203
+ --wm-radius: 12px;
204
+ --wm-font-sans: 'Inter', sans-serif;
205
+
206
+ /* Backgrounds */
207
+ --wm-color-background: #ffffff;
208
+ --wm-color-foreground: #1a1a1a;
209
+ --wm-color-muted: #f5f5f5;
210
+
211
+ /* Messages */
212
+ --wm-user-bubble-bg: #8b5cf6;
213
+ --wm-user-bubble-text: #ffffff;
214
+ --wm-assistant-bubble-bg: #f5f5f5;
215
+ --wm-assistant-bubble-text: #1a1a1a;
216
+
217
+ /* Composer */
218
+ --wm-composer-bg: #ffffff;
219
+ --wm-composer-border: #e5e5e5;
220
+ --wm-composer-button-bg: #8b5cf6;
221
+
222
+ /* Tools */
223
+ --wm-tool-bg: #f9fafb;
224
+ --wm-tool-border: #e5e7eb;
225
+ --wm-tool-approve-bg: #10b981;
226
+ --wm-tool-deny-bg: #ef4444;
227
+
228
+ /* Code blocks */
229
+ --wm-code-bg: #1e1e1e;
230
+ --wm-code-text: #d4d4d4;
231
+
232
+ /* Font sizes */
233
+ --wm-font-size-xs: 0.75rem;
234
+ --wm-font-size-sm: 0.875rem;
235
+ --wm-font-size-base: 1rem;
236
+ --wm-font-size-lg: 1.125rem;
237
+ }
238
+
239
+ /* Dark mode */
240
+ char.dark {
241
+ --wm-color-background: #1a1a1a;
242
+ --wm-color-foreground: #ffffff;
243
+ --wm-color-muted: #2a2a2a;
244
+ /* ... other dark mode overrides */
245
+ }
246
+ ```
247
+
248
+ ## Development Mode
249
+
250
+ Use your own API keys during development (stateless):
251
+
252
+ ```html
253
+ <char-agent
254
+ dev-mode='{"anthropicApiKey":"sk-ant-...","openaiApiKey":"sk-...","useLocalApi":true}'
255
+ ></char-agent>
256
+ ```
257
+
258
+ **Development modes:**
259
+ - `anthropicApiKey`: Use your own Anthropic API key (falls back to Gemini if not provided)
260
+ - `openaiApiKey`: Enable voice mode with your OpenAI key
261
+ - `useLocalApi`: Point to localhost instead of production API
262
+
263
+ Common combinations:
264
+ - `{ useLocalApi: true }` - Internal monorepo development
265
+ - `{ anthropicApiKey: "sk-ant-..." }` - External dev with your own key
266
+ - `{ anthropicApiKey: "...", openaiApiKey: "...", useLocalApi: true }` - Full stack local dev
267
+
268
+ ## Performance
269
+
270
+ ### Script Loading
271
+
272
+ Always use `defer` or `async` when embedding the standalone script to avoid blocking page rendering:
273
+
274
+ ```html
275
+ <!-- GOOD: defer - loads in parallel, executes after DOM ready -->
276
+ <script src="https://unpkg.com/@mcp-b/embedded-agent/dist/web-component-standalone.iife.js" defer></script>
277
+
278
+ <!-- GOOD: async - loads in parallel, executes ASAP -->
279
+ <script src="https://unpkg.com/@mcp-b/embedded-agent/dist/web-component-standalone.iife.js" async></script>
280
+
281
+ <!-- BAD: blocks page rendering until script loads -->
282
+ <script src="https://unpkg.com/@mcp-b/embedded-agent/dist/web-component-standalone.iife.js"></script>
283
+ ```
284
+
285
+ **When to use which:**
286
+ - `defer` (recommended) - Script executes after HTML is parsed, preserves execution order
287
+ - `async` - Script executes as soon as it loads, good for independent widgets
288
+
289
+ ### Preconnect Hint
290
+
291
+ Speed up loading by adding a preconnect hint in your `<head>`:
292
+
293
+ ```html
294
+ <link rel="preconnect" href="https://unpkg.com" crossorigin>
295
+ ```
296
+
297
+ ## Features
298
+
299
+ - **MCP Tool Support** - Connect to any MCP server
300
+ - **Voice Mode** - Talk to your AI assistant
301
+ - **Action-First UI** - Shows what the AI is doing
302
+ - **Shadow DOM Isolation** - Styles don't leak in or out
303
+ - **Stateful Sessions** - Messages persist across page refreshes (when authToken is provided)
304
+ - **CSS Variable Theming** - Customize appearance without JavaScript
305
+
306
+ ## Migration Guide
307
+
308
+ ### Upgrading from Previous Versions
309
+
310
+ **Removed props:**
311
+ - `apiKey` / `userId` - Replaced by `authToken` (use your existing IDP token)
312
+ - `appId` - No longer needed (removed dead code)
313
+ - `siteId` - Org-level routing in SSO-first mode (no site scoping)
314
+ - `theme` - Use CSS variables instead (see Customization section)
315
+ - `isolateStyles` - Always enabled (Shadow DOM is always used)
316
+ - `disableShadowDOM` - Removed (Shadow DOM is always enabled)
317
+
318
+ **Migration examples:**
319
+
320
+ ```html
321
+ <!-- OLD: -->
322
+ <char-agent
323
+ app-id="app_123"
324
+ site-id="site_123"
325
+ api-key="sk_live_xxx"
326
+ theme='{"primaryColor":"#ff0000","mode":"dark"}'
327
+ isolate-styles="false"
328
+ ></char-agent>
329
+
330
+ <!-- NEW (SSO-first with connect method): -->
331
+ </char-agent>
332
+ <script>
333
+ const agent = document.querySelector('char-agent');
334
+ agent.connect({ idToken: 'eyJhbGciOi...' });
335
+ </script>
336
+
337
+ <!-- NEW (anonymous dev mode): -->
338
+ <char-agent dev-mode='{"anthropicApiKey":"sk-ant-..."}'></char-agent>
339
+
340
+ <!-- Customize via CSS: -->
341
+ <style>
342
+ char {
343
+ --wm-color-primary: #ff0000;
344
+ }
345
+ char.dark {
346
+ --wm-color-background: #1a1a1a;
347
+ }
348
+ </style>
349
+ ```
350
+
351
+ **Benefits:**
352
+ - Smaller bundle size (~200 lines removed)
353
+ - Simpler API (fewer required attributes)
354
+ - More flexible styling (CSS variables work everywhere)
355
+ - Consistent Shadow DOM isolation (no edge cases)
356
+ - No API keys to manage (uses existing IDP tokens)
357
+
358
+ ## Development
359
+
360
+ ```bash
361
+ pnpm --filter @mcp-b/embedded-agent dev # Watch TS build
362
+ pnpm --filter @mcp-b/embedded-agent dev:css # Watch Tailwind CSS
363
+ pnpm --filter @mcp-b/embedded-agent storybook # http://localhost:6006
364
+ pnpm --filter @mcp-b/embedded-agent build
365
+ pnpm --filter @mcp-b/embedded-agent check:types
366
+ pnpm --filter @mcp-b/embedded-agent test
367
+ ```