@verba-ai/chat-sdk 1.0.0 → 1.0.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.
- package/README.md +107 -68
- package/package.json +11 -3
package/README.md
CHANGED
|
@@ -1,102 +1,141 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @verba-ai/chat-sdk
|
|
2
2
|
|
|
3
|
-
A lightweight,
|
|
3
|
+
A lightweight, TypeScript SDK for embedding the Verba AI chat widget into any web application.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The SDK acts as a secure, high-performance orchestration layer that manages the injection and lifecycle of the Verba chat `iframe`. It supports both floating and inline mounting strategies.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Installation
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
* **Isomorphic Design**: Works seamlessly in modern browsers.
|
|
11
|
-
* **Dual Mounting Strategies**:
|
|
12
|
-
* **Floating Bubble**: A fixed-position toggle button at the bottom-right (or left) corner.
|
|
13
|
-
* **Inline Mounting**: Target any DOM element or CSS selector to embed the chat directly.
|
|
14
|
-
* **Secure Communication**: Bi-directional `postMessage` bridge with strict origin validation and namespace protection.
|
|
15
|
-
* **Lifecycle Management**: Robust methods for `init()`, `show()`, `hide()`, and `destroy()`.
|
|
16
|
-
* **Zero Dependencies**: Optimized for minimum bundle size (< 5 KB gzipped).
|
|
9
|
+
Install via your preferred package manager:
|
|
17
10
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
sdk
|
|
24
|
-
├── dist/ # Compiled distribution files (ESM/UMD)
|
|
25
|
-
├── public/ # Static assets
|
|
26
|
-
├── src/
|
|
27
|
-
│ ├── index.ts # Main entry point (ChatSDK class)
|
|
28
|
-
│ ├── messenger.ts # Multi-origin communication bridge
|
|
29
|
-
│ ├── ui.ts # CSS-in-JS and DOM factory helpers
|
|
30
|
-
│ └── types.ts # Shared TypeScript interfaces & enums
|
|
31
|
-
├── index.html # Interactive developer demo page
|
|
32
|
-
├── package.json # Library metadata & build scripts
|
|
33
|
-
├── tsconfig.json # TypeScript compiler configuration
|
|
34
|
-
└── vite.config.ts # Vite library mode configuration
|
|
11
|
+
```bash
|
|
12
|
+
npm install @verba-ai/chat-sdk
|
|
13
|
+
# or
|
|
14
|
+
yarn add @verba-ai/chat-sdk
|
|
15
|
+
# or
|
|
16
|
+
pnpm add @verba-ai/chat-sdk
|
|
35
17
|
```
|
|
36
18
|
|
|
37
|
-
|
|
19
|
+
---
|
|
38
20
|
|
|
39
|
-
|
|
40
|
-
| :--- | :--- |
|
|
41
|
-
| **`src/index.ts`** | The main entry point. Exports the `ChatSDK` class which manages the state machine and coordinates UI injection and messaging. |
|
|
42
|
-
| **`src/messenger.ts`** | Encapsulates `window.postMessage` logic. It handles secure event dispatching, origin checks, and subscription management. |
|
|
43
|
-
| **`src/ui.ts`** | Handles "CSS-in-JS". It injects required styles into the document head and contains factory functions for creating the iframe, bubble button, and containers. |
|
|
44
|
-
| **`src/types.ts`** | Centralized location for all TypeScript definitions, ensuring type safety for the configuration and the messaging protocol. |
|
|
45
|
-
| **`vite.config.ts`** | Configures Vite for **Library Mode**. It uses Rollup to generate optimized ESM and UMD bundles and handles `.d.ts` generation. |
|
|
46
|
-
| **`index.html`** | A standalone demo page that allows developers to test the SDK's features in real-time, complete with a specialized event log. |
|
|
21
|
+
## Usage
|
|
47
22
|
|
|
48
|
-
|
|
23
|
+
### 1. Floating Bubble (Default)
|
|
24
|
+
The easiest way to integrate the chat. It creates a fixed-position action button in the bottom corner of your screen that toggles the chat window.
|
|
49
25
|
|
|
50
|
-
|
|
26
|
+
```typescript
|
|
27
|
+
import { ChatSDK } from '@verba-ai/chat-sdk';
|
|
51
28
|
|
|
52
|
-
|
|
29
|
+
const chat = new ChatSDK({
|
|
30
|
+
// Required: Your unique Verba tenant ID
|
|
31
|
+
tenant: 'your-tenant-id',
|
|
32
|
+
|
|
33
|
+
// Optional: Simple theme selection
|
|
34
|
+
theme: 'dark',
|
|
35
|
+
|
|
36
|
+
// Optional: Position of the bubble
|
|
37
|
+
position: 'bottom-right'
|
|
38
|
+
});
|
|
53
39
|
|
|
54
|
-
|
|
55
|
-
|
|
40
|
+
// Inject the bubble into the DOM
|
|
41
|
+
chat.init();
|
|
42
|
+
|
|
43
|
+
// Optional programmatic controls
|
|
44
|
+
// chat.show();
|
|
45
|
+
// chat.hide();
|
|
46
|
+
// chat.destroy();
|
|
56
47
|
```
|
|
57
48
|
|
|
58
|
-
###
|
|
49
|
+
### 2. Inline Mounting
|
|
50
|
+
If you want to render the chat inside a specific part of your page (like a dashboard panel or a dedicated contact page).
|
|
59
51
|
|
|
60
52
|
```typescript
|
|
61
|
-
import { ChatSDK } from '@verba/chat-sdk';
|
|
53
|
+
import { ChatSDK } from '@verba-ai/chat-sdk';
|
|
54
|
+
|
|
55
|
+
// Ensure the container exists in your DOM
|
|
56
|
+
// <div id="my-chat-container" style="height: 600px;"></div>
|
|
62
57
|
|
|
63
58
|
const chat = new ChatSDK({
|
|
64
59
|
tenant: 'your-tenant-id',
|
|
65
|
-
|
|
60
|
+
|
|
61
|
+
// Target a CSS selector or pass an HTMLElement directly
|
|
62
|
+
container: '#my-chat-container',
|
|
63
|
+
|
|
64
|
+
// Optional: Advanced visual theming
|
|
65
|
+
theme: {
|
|
66
|
+
primaryColor: '#6366f1',
|
|
67
|
+
backgroundColor: '#080b14',
|
|
68
|
+
textColor: '#f1f5f9',
|
|
69
|
+
borderRadius: '12px'
|
|
70
|
+
}
|
|
66
71
|
});
|
|
67
72
|
|
|
68
|
-
chat.init();
|
|
73
|
+
chat.init();
|
|
69
74
|
```
|
|
70
75
|
|
|
71
|
-
###
|
|
76
|
+
### 3. Usage via CDN (UMD)
|
|
77
|
+
If you aren't using a bundler (Webpack/Vite/Rollup), you can load the SDK directly via a script tag.
|
|
72
78
|
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
```html
|
|
80
|
+
<script src="https://unpkg.com/@verba-ai/chat-sdk@latest/dist/chat-sdk.umd.cjs"></script>
|
|
81
|
+
<script>
|
|
82
|
+
const { ChatSDK } = window.VerbaChatSDK;
|
|
83
|
+
|
|
84
|
+
new ChatSDK({ tenant: 'your-tenant-id' }).init();
|
|
85
|
+
</script>
|
|
78
86
|
```
|
|
79
87
|
|
|
80
88
|
---
|
|
81
89
|
|
|
82
|
-
##
|
|
90
|
+
## 📚 API Reference
|
|
83
91
|
|
|
84
|
-
###
|
|
85
|
-
To generate the production-ready bundles in the `dist/` directory:
|
|
86
|
-
```bash
|
|
87
|
-
npm run build:lib
|
|
88
|
-
```
|
|
92
|
+
### `ChatSDK` Class
|
|
89
93
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
+
The main entry point for the widget.
|
|
95
|
+
|
|
96
|
+
#### Methods
|
|
97
|
+
|
|
98
|
+
| Method | Description |
|
|
99
|
+
| :--- | :--- |
|
|
100
|
+
| `init()` | Injects the CSS and iframe into the DOM. Resolves the SDK state to `ready`. |
|
|
101
|
+
| `show()` | Makes the widget visible (animates the iframe open in floating mode). |
|
|
102
|
+
| `hide()` | Hides the widget (animates the iframe closed in floating mode). |
|
|
103
|
+
| `destroy()`| Completely tears down the SDK, removing all injected DOM elements, styles, and events. |
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
### Configuration Types
|
|
108
|
+
|
|
109
|
+
#### `ChatSDKConfig`
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
interface ChatSDKConfig {
|
|
113
|
+
/** Your Verba tenant ID (Required) */
|
|
114
|
+
tenant: string;
|
|
115
|
+
|
|
116
|
+
/** Where to mount the widget. Omit for floating bubble. */
|
|
117
|
+
container?: string | HTMLElement;
|
|
118
|
+
|
|
119
|
+
/** Visual theme. String preset or detailed config. */
|
|
120
|
+
theme?: 'light' | 'dark' | ThemeConfig;
|
|
121
|
+
|
|
122
|
+
/** Position of the floating bubble (Default: 'bottom-right') */
|
|
123
|
+
position?: 'bottom-right' | 'bottom-left';
|
|
124
|
+
|
|
125
|
+
/** Arbitrary metadata to pass to the widget */
|
|
126
|
+
userMetadata?: Record<string, unknown>;
|
|
127
|
+
}
|
|
94
128
|
```
|
|
95
129
|
|
|
130
|
+
#### `ThemeConfig`
|
|
96
131
|
|
|
97
|
-
|
|
132
|
+
```typescript
|
|
133
|
+
interface ThemeConfig {
|
|
134
|
+
primaryColor?: string;
|
|
135
|
+
textColor?: string;
|
|
136
|
+
backgroundColor?: string;
|
|
137
|
+
fontFamily?: string;
|
|
138
|
+
borderRadius?: string | number;
|
|
139
|
+
}
|
|
140
|
+
```
|
|
98
141
|
|
|
99
|
-
| File | Purpose |
|
|
100
|
-
| :--- | :--- |
|
|
101
|
-
| **`index.html`** | A standalone demo page that allows testing SDK's features in real-time, complete with a specialized event log. |
|
|
102
|
-
| **`test.html`** | Testing the actual builded library. |
|
package/package.json
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verba-ai/chat-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Lightweight TypeScript SDK for embedding the Verba AI chat widget via iframe.",
|
|
5
|
-
"keywords": [
|
|
5
|
+
"keywords": [
|
|
6
|
+
"chat",
|
|
7
|
+
"widget",
|
|
8
|
+
"sdk",
|
|
9
|
+
"iframe",
|
|
10
|
+
"verba"
|
|
11
|
+
],
|
|
6
12
|
"license": "MIT",
|
|
7
13
|
"type": "module",
|
|
8
14
|
"main": "./dist/chat-sdk.umd.cjs",
|
|
@@ -14,7 +20,9 @@
|
|
|
14
20
|
"require": "./dist/chat-sdk.umd.cjs"
|
|
15
21
|
}
|
|
16
22
|
},
|
|
17
|
-
"files": [
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
18
26
|
"scripts": {
|
|
19
27
|
"dev": "vite",
|
|
20
28
|
"build:lib": "tsc --noEmit && vite build --config vite.config.ts",
|