@cognitiondesk/widget 1.2.1 → 1.2.2

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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lucilo del Castillo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,269 +1,2 @@
1
- # @cognitiondesk/widget
1
+ # cognitiondesk_npm_package
2
2
 
3
- Embed a CognitionDesk AI chat widget into any website with a single API key.
4
- Supports React, Vue, plain HTML, WordPress, and Shopify — no build step required for script-tag usage.
5
-
6
- ## Installation
7
-
8
- ```bash
9
- npm install @cognitiondesk/widget
10
- ```
11
-
12
- ---
13
-
14
- ## Quick start
15
-
16
- ### React — minimal (recommended)
17
-
18
- ```jsx
19
- import { CognitionDeskWidget } from '@cognitiondesk/widget/react';
20
-
21
- export default function App() {
22
- return (
23
- <>
24
- <YourApp />
25
- {/* Loads all config from the platform using widgetId */}
26
- <CognitionDeskWidget
27
- apiKey="YOUR_API_KEY"
28
- widgetId="YOUR_WIDGET_ID"
29
- />
30
- </>
31
- );
32
- }
33
- ```
34
-
35
- ### React — full inline config
36
-
37
- ```jsx
38
- import { CognitionDeskWidget } from '@cognitiondesk/widget/react';
39
-
40
- export default function App() {
41
- return (
42
- <>
43
- <YourApp />
44
- <CognitionDeskWidget
45
- apiKey="YOUR_API_KEY"
46
- assistantId="YOUR_ASSISTANT_ID"
47
- theme="light"
48
- primaryColor="#2563eb"
49
- botName="Support Bot"
50
- botEmoji="🤖"
51
- welcomeMessage="Hi! How can I help?"
52
- placeholder="Type a message…"
53
- defaultOpen={false}
54
- streaming={true}
55
- onOpen={() => console.log('chat opened')}
56
- onClose={() => console.log('chat closed')}
57
- />
58
- </>
59
- );
60
- }
61
- ```
62
-
63
- ### React — programmatic control via ref
64
-
65
- ```jsx
66
- import { useRef } from 'react';
67
- import { CognitionDeskWidget } from '@cognitiondesk/widget/react';
68
-
69
- export default function App() {
70
- const widgetRef = useRef(null);
71
-
72
- return (
73
- <>
74
- <button onClick={() => widgetRef.current?.open()}>Open chat</button>
75
- <CognitionDeskWidget
76
- ref={widgetRef}
77
- apiKey="YOUR_API_KEY"
78
- widgetId="YOUR_WIDGET_ID"
79
- />
80
- </>
81
- );
82
- }
83
- ```
84
-
85
- ### Vanilla JS
86
-
87
- ```js
88
- import CognitionDeskWidget from '@cognitiondesk/widget';
89
-
90
- const widget = new CognitionDeskWidget({
91
- apiKey: 'YOUR_API_KEY',
92
- widgetId: 'YOUR_WIDGET_ID', // fetches full config from platform
93
- });
94
-
95
- await widget.mount(); // async when widgetId is set
96
- ```
97
-
98
- ### Script tag / CDN (no build step)
99
-
100
- ```html
101
- <!-- Minimal — loads config from the platform -->
102
- <script
103
- src="https://cdn.jsdelivr.net/npm/@cognitiondesk/widget/dist/widget.umd.cjs"
104
- data-api-key="YOUR_API_KEY"
105
- data-widget-id="YOUR_WIDGET_ID">
106
- </script>
107
- ```
108
-
109
- ```html
110
- <!-- Full inline config -->
111
- <script
112
- src="https://cdn.jsdelivr.net/npm/@cognitiondesk/widget/dist/widget.umd.cjs"
113
- data-api-key="YOUR_API_KEY"
114
- data-assistant-id="YOUR_ASSISTANT_ID"
115
- data-theme="light"
116
- data-primary-color="#2563eb"
117
- data-bot-name="Support Bot"
118
- data-bot-emoji="🤖"
119
- data-welcome-message="Hi! How can I help?"
120
- data-placeholder="Type a message…"
121
- data-streaming="true">
122
- </script>
123
- ```
124
-
125
- ---
126
-
127
- ## Authentication
128
-
129
- Every request is authenticated with an **API key** passed via the `apiKey` prop (or `data-api-key` attribute for script-tag usage).
130
-
131
- Generate and manage API keys in your [CognitionDesk dashboard](https://app.cognitiondesk.com) under **Settings → API Keys**.
132
-
133
- Each API key:
134
- - Authenticates widget requests to the AI backend
135
- - Tracks usage against your plan quotas
136
- - Associates conversations with your account
137
-
138
- ---
139
-
140
- ## Configuration options
141
-
142
- ### Core props
143
-
144
- | Prop / Attribute | Type | Default | Description |
145
- |---|---|---|---|
146
- | `apiKey` / `data-api-key` | `string` | **required** | Your CognitionDesk API key |
147
- | `widgetId` / `data-widget-id` | `string` | `undefined` | Widget ID from the platform — fetches full config automatically |
148
- | `assistantId` / `data-assistant-id` | `string` | `undefined` | Use a specific assistant (falls back to account default) |
149
- | `theme` / `data-theme` | `'light'│'dark'│'auto'` | `'light'` | Color scheme |
150
- | `primaryColor` / `data-primary-color` | `string` | `'#2563eb'` | Brand accent color (any CSS color) |
151
- | `botName` / `data-bot-name` | `string` | `'AI Assistant'` | Name shown in the widget header |
152
- | `botEmoji` / `data-bot-emoji` | `string` | `'🤖'` | Avatar emoji |
153
- | `welcomeMessage` / `data-welcome-message` | `string` | `'Hello! How can I help you today?'` | First message shown to the user |
154
- | `placeholder` / `data-placeholder` | `string` | `'Type a message…'` | Input placeholder text |
155
- | `streaming` / `data-streaming` | `boolean` | `true` | Enable streaming (SSE) responses |
156
- | `defaultOpen` | `boolean` | `false` | Open widget on load *(React only)* |
157
- | `backendUrl` / `data-backend-url` | `string` | auto | Override backend URL (self-hosted setups) |
158
-
159
- ### Rate limiting props
160
-
161
- Control how many messages a single visitor can send to prevent abuse and excessive API usage.
162
- Limits are enforced **both client-side** (instant feedback) and **server-side** (can't be bypassed).
163
-
164
- | Prop | Type | Default | Description |
165
- |---|---|---|---|
166
- | `maxMessagesPerSession` | `number` | `0` | Max total messages per visitor session. `0` = unlimited |
167
- | `maxMessagesPerMinute` | `number` | `0` | Max messages per minute per visitor. `0` = unlimited |
168
- | `limitReachedMessage` | `string` | `"You've reached the message limit for this session."` | Message shown when session limit is hit |
169
- | `rateLimitMessage` | `string` | `"You're sending messages too quickly. Please wait a moment."` | Message shown when per-minute limit is hit |
170
-
171
- > **Note:** When using `widgetId`, rate limit settings are fetched from the platform and override any props you pass here. Configure them in the **Web Widget creator** on the platform dashboard.
172
-
173
- #### Example — React
174
-
175
- ```jsx
176
- <CognitionDeskWidget
177
- apiKey="YOUR_API_KEY"
178
- assistantId="YOUR_ASSISTANT_ID"
179
- maxMessagesPerSession={50}
180
- maxMessagesPerMinute={10}
181
- limitReachedMessage="You've used all your messages for this session."
182
- rateLimitMessage="Slow down — please wait a few seconds."
183
- />
184
- ```
185
-
186
- #### Example — Vanilla JS
187
-
188
- ```js
189
- const widget = new CognitionDeskWidget({
190
- apiKey: 'YOUR_API_KEY',
191
- assistantId: 'YOUR_ASSISTANT_ID',
192
- rateLimiting: {
193
- enabled: true,
194
- maxMessagesPerSession: 50,
195
- maxMessagesPerMinute: 10,
196
- limitReachedMessage: "You've used all your messages for this session.",
197
- rateLimitMessage: "Slow down — please wait a few seconds.",
198
- },
199
- });
200
- widget.mount();
201
- ```
202
-
203
- ### Callbacks *(React only)*
204
-
205
- | Prop | Type | Description |
206
- |---|---|---|
207
- | `onOpen` | `() => void` | Called when the chat panel opens |
208
- | `onClose` | `() => void` | Called when the chat panel closes |
209
-
210
- ---
211
-
212
- ## Widget methods
213
-
214
- Available on the class instance (vanilla JS) or via `ref` (React).
215
-
216
- ```js
217
- widget.mount(el?) // Mount to DOM — pass an element or defaults to document.body
218
- // Returns a Promise when widgetId is set (async config fetch)
219
- widget.open() // Open the chat panel
220
- widget.close() // Close the chat panel
221
- widget.toggle() // Toggle open/closed
222
- widget.clearHistory() // Reset the conversation
223
- widget.unmount() // Remove from DOM and clean up
224
- ```
225
-
226
- ### React ref example
227
-
228
- ```jsx
229
- const ref = useRef(null);
230
- // ...
231
- <CognitionDeskWidget ref={ref} apiKey="..." widgetId="..." />
232
-
233
- // Later:
234
- ref.current?.open();
235
- ref.current?.clearHistory();
236
- ```
237
-
238
- ---
239
-
240
- ## CDN data-attribute reference
241
-
242
- All configuration options are available as `data-*` attributes for script-tag usage:
243
-
244
- | Attribute | Description |
245
- |---|---|
246
- | `data-api-key` | **Required.** Your API key |
247
- | `data-widget-id` | Widget ID (loads config from platform) |
248
- | `data-assistant-id` | Direct assistant ID |
249
- | `data-theme` | `"light"`, `"dark"`, or `"auto"` |
250
- | `data-primary-color` | Hex color, e.g. `"#2563eb"` |
251
- | `data-bot-name` | Display name |
252
- | `data-bot-emoji` | Avatar emoji |
253
- | `data-welcome-message` | Opening message |
254
- | `data-placeholder` | Input placeholder |
255
- | `data-streaming` | `"true"` or `"false"` |
256
- | `data-backend-url` | Override API base URL |
257
-
258
- ---
259
-
260
- ## Platform integrations
261
-
262
- Full installation guides for React, Vue, WordPress, and Shopify are available in the
263
- [CognitionDesk documentation](https://docs.cognitiondesk.com/docs/web-widget).
264
-
265
- ---
266
-
267
- ## License
268
-
269
- MIT