@mcp-b/embedded-agent 1.2.5-beta.1 → 1.2.6

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 CHANGED
@@ -2,89 +2,258 @@
2
2
 
3
3
  An Intercom-like AI chat widget with MCP tool support and voice mode. Drop it into your app and you're done.
4
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 `<webmcp-agent>` 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
+ ### Why Two Builds?
17
+
18
+ **ESM Build** (root export or `/web-component`)
19
+ - Web component entrypoint for bundlers
20
+ - React is externalized via `peerDependencies` (install `react` and `react-dom`)
21
+ - Smaller bundle; no duplicate React if the host already uses it
22
+ - Uses Shadow DOM for style isolation
23
+ - Use for: bundlers, monorepo consumers
24
+
25
+ **Standalone IIFE Build** (`/standalone`)
26
+ - Web component via `<script>` tag
27
+ - React is bundled inside the package
28
+ - Uses Shadow DOM for complete JS/CSS isolation
29
+ - Separate React instances in separate DOM trees = no conflict
30
+ - Use for: `<script>` tag embedding on any website (React or not)
31
+
32
+ ### The "Two Reacts" Problem
33
+
34
+ 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.
35
+
36
+ **Shadow DOM solves this**: Each React instance manages its own separate DOM tree inside the shadow boundary, so they never conflict.
37
+
38
+ ```
39
+ Host Page (React 18)
40
+ ├── <div id="root"> ← Host's React
41
+ │ └── ... host app ...
42
+
43
+ └── <webmcp-agent>
44
+ └── #shadow-root ← Isolation boundary
45
+ └── <div> ← Bundled React 19
46
+ └── ... widget ...
47
+ ```
48
+
5
49
  ## Installation
6
50
 
7
51
  ```bash
8
52
  npm install @mcp-b/embedded-agent
9
53
  ```
10
54
 
11
- ## Quick Start
55
+ ## Usage
12
56
 
13
- ### React
57
+ `<webmcp-agent>` renders as a full-viewport overlay.
14
58
 
15
- ```tsx
16
- import { EmbeddedAgent } from '@mcp-b/embedded-agent'
59
+ ### Web Component (ESM)
17
60
 
18
- import '@mcp-b/embedded-agent/styles'
61
+ ```tsx
62
+ import "@mcp-b/embedded-agent/web-component";
19
63
 
20
64
  function App() {
21
- return <EmbeddedAgent appId="your-app-id" />
65
+ return <webmcp-agent auth-token="eyJhbGciOi..." />;
22
66
  }
23
67
  ```
24
68
 
25
- ### Web Component
69
+ ### Monorepo Dogfooding
70
+
71
+ ```tsx
72
+ import "@mcp-b/embedded-agent/web-component";
73
+
74
+ // authToken from your existing IDP session
75
+ const authToken = session?.idToken ?? "";
76
+
77
+ useEffect(() => {
78
+ const agent =
79
+ document.querySelector("webmcp-agent") ?? document.createElement("webmcp-agent");
80
+
81
+ if (!agent.isConnected) {
82
+ document.body.appendChild(agent);
83
+ }
84
+
85
+ agent.setAttribute("auth-token", authToken ?? "");
86
+ agent.setAttribute("dev-mode", JSON.stringify({ useLocalApi: true }));
87
+ agent.setAttribute("enable-debug-tools", String(import.meta.env.DEV));
88
+ }, [authToken]);
89
+ ```
90
+
91
+ ### Script Tag (Any Website)
26
92
 
27
93
  ```html
28
94
  <script src="https://cdn.webmcp.ai/agent.js"></script>
29
- <webmcp-agent app-id="your-app-id"></webmcp-agent>
95
+ <webmcp-agent auth-token="eyJhbGciOi..."></webmcp-agent>
30
96
  ```
31
97
 
32
- That's it. No configuration needed.
98
+ ### Web Component Attributes
99
+
100
+ ```html
101
+ <webmcp-agent
102
+ auth-token="eyJhbGciOi..."
103
+ dev-mode='{"anthropicApiKey": "sk-ant-..."}'
104
+ enable-debug-tools="true"
105
+ ></webmcp-agent>
106
+ ```
107
+
108
+ ## Props / Attributes
109
+
110
+ | Prop | Attribute | Type | Description |
111
+ |------|-----------|------|-------------|
112
+ | `authToken` | `auth-token` | string | IDP token for stateful sessions (optional; omit for stateless) |
113
+ | `open` | `open` | boolean | Controlled open state (optional) |
114
+ | `devMode` | `dev-mode` | object/JSON | Development mode config (optional) |
115
+ | `enableDebugTools` | `enable-debug-tools` | boolean | Enable debug tools (default: false) |
116
+
117
+ ## Customization
118
+
119
+ Customize appearance by setting CSS variables on the host page:
120
+
121
+ ```css
122
+ webmcp-agent {
123
+ /* Brand colors */
124
+ --wm-color-primary: #8b5cf6;
125
+ --wm-color-primary-foreground: #ffffff;
126
+
127
+ /* Layout */
128
+ --wm-radius: 12px;
129
+ --wm-font-sans: 'Inter', sans-serif;
130
+
131
+ /* Backgrounds */
132
+ --wm-color-background: #ffffff;
133
+ --wm-color-foreground: #1a1a1a;
134
+ --wm-color-muted: #f5f5f5;
135
+
136
+ /* Messages */
137
+ --wm-user-bubble-bg: #8b5cf6;
138
+ --wm-user-bubble-text: #ffffff;
139
+ --wm-assistant-bubble-bg: #f5f5f5;
140
+ --wm-assistant-bubble-text: #1a1a1a;
141
+
142
+ /* Composer */
143
+ --wm-composer-bg: #ffffff;
144
+ --wm-composer-border: #e5e5e5;
145
+ --wm-composer-button-bg: #8b5cf6;
146
+
147
+ /* Tools */
148
+ --wm-tool-bg: #f9fafb;
149
+ --wm-tool-border: #e5e7eb;
150
+ --wm-tool-approve-bg: #10b981;
151
+ --wm-tool-deny-bg: #ef4444;
152
+
153
+ /* Code blocks */
154
+ --wm-code-bg: #1e1e1e;
155
+ --wm-code-text: #d4d4d4;
156
+
157
+ /* Font sizes */
158
+ --wm-font-size-xs: 0.75rem;
159
+ --wm-font-size-sm: 0.875rem;
160
+ --wm-font-size-base: 1rem;
161
+ --wm-font-size-lg: 1.125rem;
162
+ }
163
+
164
+ /* Dark mode */
165
+ webmcp-agent.dark {
166
+ --wm-color-background: #1a1a1a;
167
+ --wm-color-foreground: #ffffff;
168
+ --wm-color-muted: #2a2a2a;
169
+ /* ... other dark mode overrides */
170
+ }
171
+ ```
33
172
 
34
173
  ## Development Mode
35
174
 
36
- During development, use your own API keys to avoid costs:
175
+ Use your own API keys during development (stateless):
37
176
 
38
- ```tsx
39
- <EmbeddedAgent
40
- appId="your-app-id"
41
- devMode={{
42
- anthropicApiKey: 'sk-ant-...', // Required for chat
43
- openaiApiKey: 'sk-...', // Optional, enables voice mode
44
- }}
45
- />
177
+ ```html
178
+ <webmcp-agent
179
+ dev-mode='{"anthropicApiKey":"sk-ant-...","openaiApiKey":"sk-...","useLocalApi":true}'
180
+ ></webmcp-agent>
46
181
  ```
47
182
 
48
- In production, remove `devMode` to use your WebMCP plan.
183
+ **Development modes:**
184
+ - `anthropicApiKey`: Use your own Anthropic API key (falls back to Gemini if not provided)
185
+ - `openaiApiKey`: Enable voice mode with your OpenAI key
186
+ - `useLocalApi`: Point to localhost instead of production API
187
+
188
+ Common combinations:
189
+ - `{ useLocalApi: true }` - Internal monorepo development
190
+ - `{ anthropicApiKey: "sk-ant-..." }` - External dev with your own key
191
+ - `{ anthropicApiKey: "...", openaiApiKey: "...", useLocalApi: true }` - Full stack local dev
49
192
 
50
193
  ## Features
51
194
 
52
195
  - **MCP Tool Support** - Connect to any MCP server
53
- - **Voice Mode** - Talk to your AI assistant (requires OpenAI key in dev mode)
54
- - **Action-First UI** - Shows what the AI is doing, not just typing
55
- - **Drop-in Widget** - Works like Intercom, just add your app ID
196
+ - **Voice Mode** - Talk to your AI assistant
197
+ - **Action-First UI** - Shows what the AI is doing
198
+ - **Shadow DOM Isolation** - Styles don't leak in or out
199
+ - **Stateful Sessions** - Messages persist across page refreshes (when authToken is provided)
200
+ - **CSS Variable Theming** - Customize appearance without JavaScript
56
201
 
57
- ## API Reference
202
+ ## Migration Guide
58
203
 
59
- ### EmbeddedAgent Props
204
+ ### Upgrading from Previous Versions
60
205
 
61
- | Prop | Type | Required | Description |
62
- | --------- | --------------- | -------- | ----------------------------------------- |
63
- | `appId` | `string` | Yes | Your WebMCP app ID (get one at webmcp.ai) |
64
- | `devMode` | `DevModeConfig` | No | Development mode with your own API keys |
206
+ **Removed props:**
207
+ - `apiKey` / `userId` - Replaced by `authToken` (use your existing IDP token)
208
+ - `appId` - No longer needed (removed dead code)
209
+ - `siteId` - Org-level routing in SSO-first mode (no site scoping)
210
+ - `theme` - Use CSS variables instead (see Customization section)
211
+ - `isolateStyles` - Always enabled (Shadow DOM is always used)
212
+ - `disableShadowDOM` - Deprecated (Shadow DOM is always enabled)
65
213
 
66
- ### DevModeConfig
214
+ **Migration examples:**
67
215
 
68
- | Property | Type | Required | Description |
69
- | ----------------- | -------- | -------- | ---------------------------------- |
70
- | `anthropicApiKey` | `string` | Yes | Your Anthropic API key for chat |
71
- | `openaiApiKey` | `string` | No | Your OpenAI API key for voice mode |
216
+ ```html
217
+ <!-- OLD: -->
218
+ <webmcp-agent
219
+ app-id="app_123"
220
+ site-id="site_123"
221
+ api-key="sk_live_xxx"
222
+ theme='{"primaryColor":"#ff0000","mode":"dark"}'
223
+ isolate-styles="false"
224
+ ></webmcp-agent>
72
225
 
73
- ## How It Works
226
+ <!-- NEW (SSO-first): -->
227
+ <webmcp-agent auth-token="eyJhbGciOi..."></webmcp-agent>
74
228
 
75
- The widget connects to WebMCP's infrastructure (Cloudflare Workers) which handles:
229
+ <!-- NEW (stateless): -->
230
+ <webmcp-agent></webmcp-agent>
76
231
 
77
- - Chat completions via Anthropic Claude
78
- - Voice mode via OpenAI Realtime API
79
- - MCP tool execution
232
+ <!-- Customize via CSS: -->
233
+ <style>
234
+ webmcp-agent {
235
+ --wm-color-primary: #ff0000;
236
+ }
237
+ webmcp-agent.dark {
238
+ --wm-color-background: #1a1a1a;
239
+ }
240
+ </style>
241
+ ```
80
242
 
81
- In development mode, your API keys are used. In production, your WebMCP plan covers the costs.
243
+ **Benefits:**
244
+ - Smaller bundle size (~200 lines removed)
245
+ - Simpler API (fewer required attributes)
246
+ - More flexible styling (CSS variables work everywhere)
247
+ - Consistent Shadow DOM isolation (no edge cases)
248
+ - No API keys to manage (uses existing IDP tokens)
82
249
 
83
250
  ## Development
84
251
 
85
252
  ```bash
86
- pnpm build # Build the package
87
- pnpm check:types # Type check
88
- pnpm check:lint # Lint
89
- pnpm test # Run tests
253
+ pnpm --filter @mcp-b/embedded-agent dev # Watch TS build
254
+ pnpm --filter @mcp-b/embedded-agent dev:css # Watch Tailwind CSS
255
+ pnpm --filter @mcp-b/embedded-agent storybook # http://localhost:6006
256
+ pnpm --filter @mcp-b/embedded-agent build
257
+ pnpm --filter @mcp-b/embedded-agent check:types
258
+ pnpm --filter @mcp-b/embedded-agent test
90
259
  ```
package/dist/jsx.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ /**
2
+ * TypeScript JSX type declarations for the webmcp-agent custom element.
3
+ *
4
+ * This file provides proper typing for the <webmcp-agent> custom element
5
+ * when used in React/TypeScript projects.
6
+ *
7
+ * @see https://www.totaltypescript.com/workshops/advanced-typescript-patterns/advanced-challenges/custom-jsx-elements
8
+ * @see https://www.typescriptlang.org/docs/handbook/jsx.html
9
+ */
10
+
11
+ import 'react';
12
+
13
+ declare module 'react' {
14
+ namespace JSX {
15
+ interface IntrinsicElements {
16
+ 'webmcp-agent': React.DetailedHTMLProps<
17
+ React.HTMLAttributes<HTMLElement> & {
18
+ /**
19
+ * IDP token for SSO-First authentication.
20
+ * When provided, the agent will authenticate the user and persist threads to the backend.
21
+ * When omitted, the agent runs in stateless mode (memory-only).
22
+ */
23
+ 'auth-token'?: string;
24
+
25
+ /**
26
+ * Whether the agent panel should be open by default.
27
+ */
28
+ open?: boolean;
29
+
30
+ /**
31
+ * Development mode configuration (JSON string).
32
+ * Example: JSON.stringify({ useLocalApi: true })
33
+ */
34
+ 'dev-mode'?: string;
35
+
36
+ /**
37
+ * Enable debug tools panel for development.
38
+ */
39
+ 'enable-debug-tools'?: boolean;
40
+ },
41
+ HTMLElement
42
+ >;
43
+ }
44
+ }
45
+ }