sidenetai-sdk 1.0.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 +1036 -0
- package/dist/sidenetai-sdk.css +1 -0
- package/dist/sidenetai-sdk.es.js +37234 -0
- package/dist/sidenetai-sdk.umd.js +307 -0
- package/dist/vite.svg +1 -0
- package/package.json +83 -0
package/README.md
ADDED
|
@@ -0,0 +1,1036 @@
|
|
|
1
|
+
# SideNetAI SDK
|
|
2
|
+
|
|
3
|
+
A lightweight, easy-to-use sidebar SDK that can be loaded via script tag or npm package. The SideNetAI SDK provides a powerful, customizable sidebar interface for AI chat interactions that seamlessly integrates into any web application.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Installation](#installation)
|
|
8
|
+
- [Version Management & Updates](#version-management--updates)
|
|
9
|
+
- [Using with Non-React Apps](#using-with-non-react-apps)
|
|
10
|
+
- [Quick Start](#quick-start)
|
|
11
|
+
- [API Reference](#api-reference)
|
|
12
|
+
- [Configuration Options](#configuration-options)
|
|
13
|
+
- [Usage Examples](#usage-examples)
|
|
14
|
+
- [React Component Usage](#react-component-usage)
|
|
15
|
+
- [Customization](#customization)
|
|
16
|
+
- [Package Contents](#package-contents)
|
|
17
|
+
- [Development](#development)
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
> **Important Note About React:** The SideNetAI SDK uses React internally to render the sidebar UI. However, **your application does not need to use React** - you just need to ensure React and ReactDOM are loaded (either via CDN or npm). The SDK will work with any framework (Vue, Angular, Svelte, vanilla JavaScript, etc.) as long as React is available on the page.
|
|
22
|
+
|
|
23
|
+
### Option 1: NPM Package (Recommended)
|
|
24
|
+
|
|
25
|
+
Install the package using npm, yarn, or pnpm:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Using npm
|
|
29
|
+
npm install sidenetai-sdk
|
|
30
|
+
|
|
31
|
+
# Using yarn
|
|
32
|
+
yarn add sidenetai-sdk
|
|
33
|
+
|
|
34
|
+
# Using pnpm
|
|
35
|
+
pnpm add sidenetai-sdk
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**Note:** React and ReactDOM are peer dependencies. Make sure you have React 18 or 19 installed:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm install react@^18 react-dom@^18
|
|
42
|
+
# or
|
|
43
|
+
npm install react@^19 react-dom@^19
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**For Non-React Apps:** If your app doesn't use React, you still need to install React as a dependency (it won't interfere with your app). The SDK uses React internally but doesn't require your app to use React.
|
|
47
|
+
|
|
48
|
+
### Option 2: CDN (ES Modules)
|
|
49
|
+
|
|
50
|
+
Load the SDK directly from a CDN using ES modules:
|
|
51
|
+
|
|
52
|
+
> **Note:** Replace `@latest` with a specific version (e.g., `@1.0.14`) for production use. See [Version Management & Updates](#version-management--updates) for details.
|
|
53
|
+
|
|
54
|
+
```html
|
|
55
|
+
<!DOCTYPE html>
|
|
56
|
+
<html>
|
|
57
|
+
<head>
|
|
58
|
+
<!-- Load React and ReactDOM first (required peer dependencies) -->
|
|
59
|
+
<script crossorigin src="https://unpkg.com/react@19/umd/react.production.min.js"></script>
|
|
60
|
+
<script crossorigin src="https://unpkg.com/react-dom@19/umd/react-dom.production.min.js"></script>
|
|
61
|
+
|
|
62
|
+
<!-- Load the SDK CSS (use specific version for production) -->
|
|
63
|
+
<link rel="stylesheet" href="https://unpkg.com/sidenetai-sdk@1.0.14/dist/sidenetai-sdk.css">
|
|
64
|
+
</head>
|
|
65
|
+
<body>
|
|
66
|
+
<h1>My Website</h1>
|
|
67
|
+
|
|
68
|
+
<!-- Load and initialize the SDK -->
|
|
69
|
+
<script type="module">
|
|
70
|
+
import { initSidenet, toggleSidenet } from 'https://unpkg.com/sidenetai-sdk@1.0.14/dist/sidenetai-sdk.es.js';
|
|
71
|
+
|
|
72
|
+
// Initialize the sidebar
|
|
73
|
+
initSidenet({
|
|
74
|
+
position: 'right',
|
|
75
|
+
width: '45vw',
|
|
76
|
+
defaultOpen: false
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Make toggleSidenet available globally (optional)
|
|
80
|
+
window.toggleSidenet = toggleSidenet;
|
|
81
|
+
</script>
|
|
82
|
+
|
|
83
|
+
<!-- Add a button to toggle the sidebar -->
|
|
84
|
+
<button onclick="toggleSidenet()">Toggle Sidebar</button>
|
|
85
|
+
</body>
|
|
86
|
+
</html>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Option 3: UMD Bundle (Script Tag)
|
|
90
|
+
|
|
91
|
+
For browsers that don't support ES modules, use the UMD bundle:
|
|
92
|
+
|
|
93
|
+
> **Note:** Replace `@latest` with a specific version (e.g., `@1.0.14`) for production use. See [Version Management & Updates](#version-management--updates) for details.
|
|
94
|
+
|
|
95
|
+
```html
|
|
96
|
+
<!DOCTYPE html>
|
|
97
|
+
<html>
|
|
98
|
+
<head>
|
|
99
|
+
<!-- Load React and ReactDOM -->
|
|
100
|
+
<script crossorigin src="https://unpkg.com/react@19/umd/react.production.min.js"></script>
|
|
101
|
+
<script crossorigin src="https://unpkg.com/react-dom@19/umd/react-dom.production.min.js"></script>
|
|
102
|
+
|
|
103
|
+
<!-- Load the SDK CSS (use specific version for production) -->
|
|
104
|
+
<link rel="stylesheet" href="https://unpkg.com/sidenetai-sdk@1.0.14/dist/sidenetai-sdk.css">
|
|
105
|
+
</head>
|
|
106
|
+
<body>
|
|
107
|
+
<h1>My Website</h1>
|
|
108
|
+
|
|
109
|
+
<!-- Load the SDK UMD bundle (use specific version for production) -->
|
|
110
|
+
<script src="https://unpkg.com/sidenetai-sdk@1.0.14/dist/sidenetai-sdk.umd.js"></script>
|
|
111
|
+
|
|
112
|
+
<script>
|
|
113
|
+
// Access the SDK from the global SideNetAI object
|
|
114
|
+
const { initSidenet, toggleSidenet } = SideNetAI;
|
|
115
|
+
|
|
116
|
+
// Initialize the sidebar
|
|
117
|
+
initSidenet({
|
|
118
|
+
position: 'right',
|
|
119
|
+
width: '45vw',
|
|
120
|
+
defaultOpen: false
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// Make toggleSidenet available globally
|
|
124
|
+
window.toggleSidenet = toggleSidenet;
|
|
125
|
+
</script>
|
|
126
|
+
|
|
127
|
+
<button onclick="toggleSidenet()">Toggle Sidebar</button>
|
|
128
|
+
</body>
|
|
129
|
+
</html>
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Version Management & Updates
|
|
133
|
+
|
|
134
|
+
When you publish a new version of the SDK, host applications need to update to receive the changes. Here's how version management works:
|
|
135
|
+
|
|
136
|
+
### Semantic Versioning
|
|
137
|
+
|
|
138
|
+
The SDK follows [Semantic Versioning](https://semver.org/) (semver):
|
|
139
|
+
- **Major version** (e.g., `1.0.0` → `2.0.0`): Breaking changes
|
|
140
|
+
- **Minor version** (e.g., `1.0.0` → `1.1.0`): New features, backward compatible
|
|
141
|
+
- **Patch version** (e.g., `1.0.0` → `1.0.1`): Bug fixes, backward compatible
|
|
142
|
+
|
|
143
|
+
### Updating with NPM
|
|
144
|
+
|
|
145
|
+
#### Automatic Updates (Recommended for Development)
|
|
146
|
+
|
|
147
|
+
Use version ranges in your `package.json` to automatically receive compatible updates:
|
|
148
|
+
|
|
149
|
+
```json
|
|
150
|
+
{
|
|
151
|
+
"dependencies": {
|
|
152
|
+
"sidenetai-sdk": "^1.0.14" // Receives all 1.x.x updates (patches and minor)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**Version Range Options:**
|
|
158
|
+
- `^1.0.14` - Receives patches and minor updates (1.0.14 → 1.1.0, but not 2.0.0)
|
|
159
|
+
- `~1.0.14` - Receives only patch updates (1.0.14 → 1.0.15, but not 1.1.0)
|
|
160
|
+
- `1.0.14` - Fixed version (no automatic updates)
|
|
161
|
+
|
|
162
|
+
**To update manually:**
|
|
163
|
+
```bash
|
|
164
|
+
# Update to latest compatible version
|
|
165
|
+
npm update sidenetai-sdk
|
|
166
|
+
|
|
167
|
+
# Or install a specific version
|
|
168
|
+
npm install sidenetai-sdk@1.1.0
|
|
169
|
+
|
|
170
|
+
# Check for outdated packages
|
|
171
|
+
npm outdated sidenetai-sdk
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
#### Production Best Practices
|
|
175
|
+
|
|
176
|
+
For production applications, use **fixed versions** to prevent unexpected updates:
|
|
177
|
+
|
|
178
|
+
```json
|
|
179
|
+
{
|
|
180
|
+
"dependencies": {
|
|
181
|
+
"sidenetai-sdk": "1.0.14" // Fixed version - no automatic updates
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Then manually test and update when new versions are released:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
# Check what's available
|
|
190
|
+
npm view sidenetai-sdk versions
|
|
191
|
+
|
|
192
|
+
# Install a specific new version
|
|
193
|
+
npm install sidenetai-sdk@1.1.0
|
|
194
|
+
|
|
195
|
+
# Test your application thoroughly
|
|
196
|
+
# Then commit the updated package.json
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Updating with CDN
|
|
200
|
+
|
|
201
|
+
#### Using `@latest` (Automatic Updates)
|
|
202
|
+
|
|
203
|
+
When using `@latest`, your application will **automatically receive new versions** as they're published:
|
|
204
|
+
|
|
205
|
+
```html
|
|
206
|
+
<!-- Automatically updates to newest version -->
|
|
207
|
+
<script src="https://unpkg.com/sidenetai-sdk@latest/dist/sidenetai-sdk.umd.js"></script>
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
**⚠️ Warning:** Using `@latest` in production can cause unexpected breaking changes. Use with caution.
|
|
211
|
+
|
|
212
|
+
#### Using Specific Versions (Recommended for Production)
|
|
213
|
+
|
|
214
|
+
Pin to a specific version for production stability:
|
|
215
|
+
|
|
216
|
+
```html
|
|
217
|
+
<!-- Fixed version - won't update automatically -->
|
|
218
|
+
<script src="https://unpkg.com/sidenetai-sdk@1.0.14/dist/sidenetai-sdk.umd.js"></script>
|
|
219
|
+
<link rel="stylesheet" href="https://unpkg.com/sidenetai-sdk@1.0.14/dist/sidenetai-sdk.css">
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**To update manually:**
|
|
223
|
+
1. Check the [npm registry](https://www.npmjs.com/package/sidenetai-sdk) for new versions
|
|
224
|
+
2. Update the version number in your HTML:
|
|
225
|
+
```html
|
|
226
|
+
<!-- Update from 1.0.14 to 1.1.0 -->
|
|
227
|
+
<script src="https://unpkg.com/sidenetai-sdk@1.1.0/dist/sidenetai-sdk.umd.js"></script>
|
|
228
|
+
```
|
|
229
|
+
3. Test your application thoroughly
|
|
230
|
+
4. Deploy the updated version
|
|
231
|
+
|
|
232
|
+
### Version Strategy Recommendations
|
|
233
|
+
|
|
234
|
+
| Environment | Strategy | Version Format |
|
|
235
|
+
|------------|----------|----------------|
|
|
236
|
+
| **Development** | Auto-update patches/minor | `^1.0.14` or `@latest` |
|
|
237
|
+
| **Staging** | Manual updates, test first | `1.0.14` (fixed) |
|
|
238
|
+
| **Production** | Fixed version, manual updates | `1.0.14` (fixed) |
|
|
239
|
+
|
|
240
|
+
### Checking for Updates
|
|
241
|
+
|
|
242
|
+
**NPM Users:**
|
|
243
|
+
```bash
|
|
244
|
+
# Check current version
|
|
245
|
+
npm list sidenetai-sdk
|
|
246
|
+
|
|
247
|
+
# Check for updates
|
|
248
|
+
npm outdated sidenetai-sdk
|
|
249
|
+
|
|
250
|
+
# View all available versions
|
|
251
|
+
npm view sidenetai-sdk versions
|
|
252
|
+
|
|
253
|
+
# View latest version
|
|
254
|
+
npm view sidenetai-sdk version
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
**CDN Users:**
|
|
258
|
+
- Visit https://www.npmjs.com/package/sidenetai-sdk to see the latest version
|
|
259
|
+
- Check the [changelog](https://github.com/your-repo/sidenetai-sdk/releases) (if available) for breaking changes
|
|
260
|
+
|
|
261
|
+
### Migration Guide
|
|
262
|
+
|
|
263
|
+
When updating to a new major version (e.g., `1.x.x` → `2.x.x`), check for:
|
|
264
|
+
- Breaking changes in the API
|
|
265
|
+
- Configuration option changes
|
|
266
|
+
- Required dependency updates
|
|
267
|
+
- Deprecated features
|
|
268
|
+
|
|
269
|
+
Always test in a development environment before updating production.
|
|
270
|
+
|
|
271
|
+
### Example: Update Workflow
|
|
272
|
+
|
|
273
|
+
**Scenario:** New version `1.1.0` is published
|
|
274
|
+
|
|
275
|
+
**For NPM users with version ranges:**
|
|
276
|
+
```bash
|
|
277
|
+
# 1. Check what will be updated
|
|
278
|
+
npm outdated
|
|
279
|
+
|
|
280
|
+
# 2. Update (if using ^ version range, this happens automatically)
|
|
281
|
+
npm update sidenetai-sdk
|
|
282
|
+
|
|
283
|
+
# 3. Test your application
|
|
284
|
+
npm test
|
|
285
|
+
|
|
286
|
+
# 4. If everything works, commit the updated package.json
|
|
287
|
+
git add package.json package-lock.json
|
|
288
|
+
git commit -m "Update sidenetai-sdk to 1.1.0"
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
**For CDN users:**
|
|
292
|
+
```html
|
|
293
|
+
<!-- 1. Update the version number in your HTML -->
|
|
294
|
+
<script src="https://unpkg.com/sidenetai-sdk@1.1.0/dist/sidenetai-sdk.umd.js"></script>
|
|
295
|
+
|
|
296
|
+
<!-- 2. Test thoroughly -->
|
|
297
|
+
<!-- 3. Deploy -->
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
## Using with Non-React Apps
|
|
301
|
+
|
|
302
|
+
The SideNetAI SDK works perfectly with applications that don't use React. Here's how:
|
|
303
|
+
|
|
304
|
+
### For Vanilla HTML/JavaScript Apps
|
|
305
|
+
|
|
306
|
+
If your app is just plain HTML and JavaScript, load React via CDN (as shown in the CDN installation options above). React will only be used by the SDK internally - your app code can continue using vanilla JavaScript.
|
|
307
|
+
|
|
308
|
+
### For Vue.js Apps
|
|
309
|
+
|
|
310
|
+
```javascript
|
|
311
|
+
// In your Vue app (e.g., main.js or a component)
|
|
312
|
+
import { initSidenet, toggleSidenet } from 'sidenetai-sdk';
|
|
313
|
+
import 'sidenetai-sdk/dist/sidenetai-sdk.css';
|
|
314
|
+
|
|
315
|
+
// Initialize when your Vue app mounts
|
|
316
|
+
export default {
|
|
317
|
+
mounted() {
|
|
318
|
+
initSidenet({
|
|
319
|
+
position: 'right',
|
|
320
|
+
width: '45vw',
|
|
321
|
+
defaultOpen: false
|
|
322
|
+
});
|
|
323
|
+
},
|
|
324
|
+
methods: {
|
|
325
|
+
toggleSidenet() {
|
|
326
|
+
toggleSidenet();
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
Make sure React is installed:
|
|
333
|
+
```bash
|
|
334
|
+
npm install react@^18 react-dom@^18
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### For Angular Apps
|
|
338
|
+
|
|
339
|
+
```typescript
|
|
340
|
+
// In your Angular component (e.g., app.component.ts)
|
|
341
|
+
import { Component, OnInit } from '@angular/core';
|
|
342
|
+
import { initSidenet, toggleSidenet } from 'sidenetai-sdk';
|
|
343
|
+
import 'sidenetai-sdk/dist/sidenetai-sdk.css';
|
|
344
|
+
|
|
345
|
+
@Component({
|
|
346
|
+
selector: 'app-root',
|
|
347
|
+
templateUrl: './app.component.html'
|
|
348
|
+
})
|
|
349
|
+
export class AppComponent implements OnInit {
|
|
350
|
+
ngOnInit() {
|
|
351
|
+
initSidenet({
|
|
352
|
+
position: 'right',
|
|
353
|
+
width: '45vw',
|
|
354
|
+
defaultOpen: false
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
toggleSidenet() {
|
|
359
|
+
toggleSidenet();
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
Make sure React is installed:
|
|
365
|
+
```bash
|
|
366
|
+
npm install react@^18 react-dom@^18
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
### For Svelte Apps
|
|
370
|
+
|
|
371
|
+
```javascript
|
|
372
|
+
// In your Svelte component (e.g., App.svelte)
|
|
373
|
+
<script>
|
|
374
|
+
import { onMount } from 'svelte';
|
|
375
|
+
import { initSidenet, toggleSidenet } from 'sidenetai-sdk';
|
|
376
|
+
import 'sidenetai-sdk/dist/sidenetai-sdk.css';
|
|
377
|
+
|
|
378
|
+
onMount(() => {
|
|
379
|
+
initSidenet({
|
|
380
|
+
position: 'right',
|
|
381
|
+
width: '45vw',
|
|
382
|
+
defaultOpen: false
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
function handleToggle() {
|
|
387
|
+
toggleSidenet();
|
|
388
|
+
}
|
|
389
|
+
</script>
|
|
390
|
+
|
|
391
|
+
<button on:click={handleToggle}>Toggle Sidebar</button>
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
Make sure React is installed:
|
|
395
|
+
```bash
|
|
396
|
+
npm install react@^18 react-dom@^18
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
### Key Points
|
|
400
|
+
|
|
401
|
+
- **React is only used internally** by the SDK - your app can use any framework or no framework
|
|
402
|
+
- **No conflicts** - React loaded by the SDK won't interfere with your app's framework
|
|
403
|
+
- **CDN option** - For vanilla HTML/JS apps, you can load React via CDN (no npm needed)
|
|
404
|
+
- **NPM option** - For apps using build tools, install React as a dependency
|
|
405
|
+
|
|
406
|
+
## Quick Start
|
|
407
|
+
|
|
408
|
+
### Basic Usage with NPM
|
|
409
|
+
|
|
410
|
+
```javascript
|
|
411
|
+
// Import the SDK functions and styles
|
|
412
|
+
import { initSidenet, toggleSidenet, destroySidenet } from 'sidenetai-sdk';
|
|
413
|
+
import 'sidenetai-sdk/dist/sidenetai-sdk.css';
|
|
414
|
+
|
|
415
|
+
// Initialize the sidebar with default settings
|
|
416
|
+
initSidenet();
|
|
417
|
+
|
|
418
|
+
// Or with custom configuration
|
|
419
|
+
initSidenet({
|
|
420
|
+
position: 'right', // 'left' or 'right'
|
|
421
|
+
width: '45vw', // Width in px or vw (e.g., '500px' or '45vw')
|
|
422
|
+
userId: 'user-123', // Optional: User identifier
|
|
423
|
+
copilotId: 'project-456', // Optional: Project identifier
|
|
424
|
+
defaultOpen: false // Whether sidebar starts open (default: true)
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
// Toggle sidebar visibility
|
|
428
|
+
toggleSidenet();
|
|
429
|
+
|
|
430
|
+
// Clean up when done
|
|
431
|
+
destroySidenet();
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
## API Reference
|
|
435
|
+
|
|
436
|
+
### `initSidenet(options?)`
|
|
437
|
+
|
|
438
|
+
Initializes the sidebar on the page. This function creates and mounts the sidebar component. It should be called once when your application loads.
|
|
439
|
+
|
|
440
|
+
**Parameters:**
|
|
441
|
+
- `options` (optional): Configuration object with the following properties:
|
|
442
|
+
- `position` (optional): `'left'` or `'right'` - Sidebar position on the page. Default: `'right'`
|
|
443
|
+
- `width` (optional): `string` - Sidebar width with unit (e.g., `'500px'` or `'45vw'`). Default: `'45vw'`
|
|
444
|
+
- `userId` (optional): `string` - User identifier for the chat session
|
|
445
|
+
- `copilotId` (optional): `string` - Project identifier for the chat session
|
|
446
|
+
- `defaultOpen` (optional): `boolean` - Whether the sidebar should be open by default. Default: `true`
|
|
447
|
+
|
|
448
|
+
**Returns:** `void`
|
|
449
|
+
|
|
450
|
+
**Example:**
|
|
451
|
+
```javascript
|
|
452
|
+
import { initSidenet } from 'sidenetai-sdk';
|
|
453
|
+
import 'sidenetai-sdk/dist/sidenetai-sdk.css';
|
|
454
|
+
|
|
455
|
+
// Initialize with default settings (right side, 45vw width, open by default)
|
|
456
|
+
initSidenet();
|
|
457
|
+
|
|
458
|
+
// Initialize with custom settings
|
|
459
|
+
initSidenet({
|
|
460
|
+
position: 'left',
|
|
461
|
+
width: '400px',
|
|
462
|
+
userId: 'user-123',
|
|
463
|
+
copilotId: 'project-456',
|
|
464
|
+
defaultOpen: false
|
|
465
|
+
});
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
**Note:** Calling `initSidenet()` multiple times will result in a warning and will not reinitialize the sidebar. Use `destroySidenet()` first if you need to reinitialize.
|
|
469
|
+
|
|
470
|
+
---
|
|
471
|
+
|
|
472
|
+
### `toggleSidenet()`
|
|
473
|
+
|
|
474
|
+
Toggles the sidebar visibility (show/hide). If the sidebar is currently visible, it will be hidden, and vice versa. The function automatically adjusts the page body margins to accommodate the sidebar when visible.
|
|
475
|
+
|
|
476
|
+
**Parameters:** None
|
|
477
|
+
|
|
478
|
+
**Returns:** `void`
|
|
479
|
+
|
|
480
|
+
**Example:**
|
|
481
|
+
```javascript
|
|
482
|
+
import { toggleSidenet } from 'sidenetai-sdk';
|
|
483
|
+
|
|
484
|
+
// Toggle sidebar visibility
|
|
485
|
+
toggleSidenet();
|
|
486
|
+
|
|
487
|
+
// You can also attach it to a button
|
|
488
|
+
document.getElementById('sidebar-toggle-btn').addEventListener('click', toggleSidenet);
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
---
|
|
492
|
+
|
|
493
|
+
### `destroySidenet()`
|
|
494
|
+
|
|
495
|
+
Completely removes the sidebar from the page and cleans up all associated resources. This function unmounts the React component, removes the container element, and restores the original body styles.
|
|
496
|
+
|
|
497
|
+
**Parameters:** None
|
|
498
|
+
|
|
499
|
+
**Returns:** `void`
|
|
500
|
+
|
|
501
|
+
**Example:**
|
|
502
|
+
```javascript
|
|
503
|
+
import { destroySidenet } from 'sidenetai-sdk';
|
|
504
|
+
|
|
505
|
+
// Remove the sidebar when navigating away or closing the app
|
|
506
|
+
destroySidenet();
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
---
|
|
510
|
+
|
|
511
|
+
### `updateSidenetConfig(options)`
|
|
512
|
+
|
|
513
|
+
Updates the sidebar configuration dynamically without reinitializing. This is useful when you need to change the sidebar settings after initialization (e.g., changing width, position, or user/project IDs).
|
|
514
|
+
|
|
515
|
+
**Parameters:**
|
|
516
|
+
- `options`: Configuration object with the following properties:
|
|
517
|
+
- `width` (optional): `string` - New width with unit (e.g., `'600px'` or `'50vw'`)
|
|
518
|
+
- `position` (optional): `'left'` or `'right'` - New sidebar position
|
|
519
|
+
- `userId` (optional): `string` - Updated user identifier
|
|
520
|
+
- `copilotId` (optional): `string` - Updated project identifier
|
|
521
|
+
- `defaultOpen` (optional): `boolean` - Updated default open state
|
|
522
|
+
|
|
523
|
+
**Returns:** `void`
|
|
524
|
+
|
|
525
|
+
**Example:**
|
|
526
|
+
```javascript
|
|
527
|
+
import { initSidenet, updateSidenetConfig } from 'sidenetai-sdk';
|
|
528
|
+
import 'sidenetai-sdk/dist/sidenetai-sdk.css';
|
|
529
|
+
|
|
530
|
+
// Initialize the sidebar
|
|
531
|
+
initSidenet({
|
|
532
|
+
width: '400px',
|
|
533
|
+
position: 'right'
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
// Later, update the width dynamically
|
|
537
|
+
updateSidenetConfig({
|
|
538
|
+
width: '600px'
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
// Update position
|
|
542
|
+
updateSidenetConfig({
|
|
543
|
+
position: 'left'
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
// Update user/project IDs
|
|
547
|
+
updateSidenetConfig({
|
|
548
|
+
userId: 'new-user-123',
|
|
549
|
+
copilotId: 'new-project-456'
|
|
550
|
+
});
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
**Note:** The sidebar must be initialized with `initSidenet()` before calling this function.
|
|
554
|
+
|
|
555
|
+
---
|
|
556
|
+
|
|
557
|
+
### `refreshSidenetStyles()`
|
|
558
|
+
|
|
559
|
+
Refreshes the sidebar styles from the database without reinitializing. This function is useful when you've updated styling configuration in your backend and want to apply those changes to an already-initialized sidebar.
|
|
560
|
+
|
|
561
|
+
**Parameters:** None
|
|
562
|
+
|
|
563
|
+
**Returns:** `void`
|
|
564
|
+
|
|
565
|
+
**Example:**
|
|
566
|
+
```javascript
|
|
567
|
+
import { initSidenet, refreshSidenetStyles } from 'sidenetai-sdk';
|
|
568
|
+
import 'sidenetai-sdk/dist/sidenetai-sdk.css';
|
|
569
|
+
|
|
570
|
+
// Initialize the sidebar
|
|
571
|
+
initSidenet();
|
|
572
|
+
|
|
573
|
+
// Later, when database styles are updated, refresh them
|
|
574
|
+
refreshSidenetStyles();
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
**Note:** The sidebar must be initialized with `initSidenet()` before calling this function.
|
|
578
|
+
|
|
579
|
+
---
|
|
580
|
+
|
|
581
|
+
### `refreshSidenetScrollbar()`
|
|
582
|
+
|
|
583
|
+
Refreshes the scrollbar positioning calculation. Call this function if the host page's scrollbar properties change (e.g., scrollbar visibility changes) to ensure the sidebar is positioned correctly.
|
|
584
|
+
|
|
585
|
+
**Parameters:** None
|
|
586
|
+
|
|
587
|
+
**Returns:** `void`
|
|
588
|
+
|
|
589
|
+
**Example:**
|
|
590
|
+
```javascript
|
|
591
|
+
import { initSidenet, refreshSidenetScrollbar } from 'sidenetai-sdk';
|
|
592
|
+
import 'sidenetai-sdk/dist/sidenetai-sdk.css';
|
|
593
|
+
|
|
594
|
+
// Initialize the sidebar
|
|
595
|
+
initSidenet();
|
|
596
|
+
|
|
597
|
+
// Later, if the page scrollbar changes, refresh detection
|
|
598
|
+
refreshSidenetScrollbar();
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
**Note:** The sidebar must be initialized with `initSidenet()` before calling this function.
|
|
602
|
+
|
|
603
|
+
---
|
|
604
|
+
|
|
605
|
+
### `Sidebar` Component (React)
|
|
606
|
+
|
|
607
|
+
For advanced usage in React applications, you can import and use the `Sidebar` component directly. This gives you more control over the component lifecycle and integration with your React app.
|
|
608
|
+
|
|
609
|
+
**Props:**
|
|
610
|
+
- `config`: Configuration object
|
|
611
|
+
- `position` (optional): `'left'` or `'right'` - Default: `'right'`
|
|
612
|
+
- `width` (optional): `string` - Width with unit (e.g., `'500px'` or `'45vw'`)
|
|
613
|
+
- `userId` (optional): `string` - User identifier
|
|
614
|
+
- `copilotId` (optional): `string` - Project identifier
|
|
615
|
+
- `defaultOpen` (optional): `boolean` - Whether sidebar starts open
|
|
616
|
+
- `onWidthChange` (optional): `(newWidth: string) => void` - Callback when width changes
|
|
617
|
+
|
|
618
|
+
**Example:**
|
|
619
|
+
```javascript
|
|
620
|
+
import React from 'react';
|
|
621
|
+
import { Sidebar } from 'sidenetai-sdk';
|
|
622
|
+
import 'sidenetai-sdk/dist/sidenetai-sdk.css';
|
|
623
|
+
|
|
624
|
+
function MyApp() {
|
|
625
|
+
const handleWidthChange = (newWidth) => {
|
|
626
|
+
console.log('Sidebar width changed to:', newWidth);
|
|
627
|
+
};
|
|
628
|
+
|
|
629
|
+
return (
|
|
630
|
+
<div>
|
|
631
|
+
<h1>My Application</h1>
|
|
632
|
+
<Sidebar
|
|
633
|
+
config={{
|
|
634
|
+
position: 'right',
|
|
635
|
+
width: '45vw',
|
|
636
|
+
userId: 'user-123',
|
|
637
|
+
copilotId: 'project-456',
|
|
638
|
+
defaultOpen: false
|
|
639
|
+
}}
|
|
640
|
+
onWidthChange={handleWidthChange}
|
|
641
|
+
/>
|
|
642
|
+
</div>
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
export default MyApp;
|
|
647
|
+
```
|
|
648
|
+
|
|
649
|
+
---
|
|
650
|
+
|
|
651
|
+
## Configuration Options
|
|
652
|
+
|
|
653
|
+
The `initSidenet()` function accepts a configuration object with the following options:
|
|
654
|
+
|
|
655
|
+
| Option | Type | Default | Description |
|
|
656
|
+
|--------|------|---------|-------------|
|
|
657
|
+
| `position` | `'left' \| 'right'` | `'right'` | Sidebar position on the page |
|
|
658
|
+
| `width` | `string` | `'45vw'` | Sidebar width with unit (px or vw). Examples: `'500px'`, `'45vw'`, `'50%'` |
|
|
659
|
+
| `userId` | `string` | `undefined` | Optional user identifier for chat sessions |
|
|
660
|
+
| `copilotId` | `string` | `undefined` | Optional project identifier for chat sessions |
|
|
661
|
+
| `defaultOpen` | `boolean` | `true` | Whether the sidebar should be open when initialized |
|
|
662
|
+
|
|
663
|
+
### Width Units
|
|
664
|
+
|
|
665
|
+
The `width` option accepts values with the following units:
|
|
666
|
+
- **px**: Fixed pixel width (e.g., `'500px'`)
|
|
667
|
+
- **vw**: Viewport width percentage (e.g., `'45vw'` means 45% of viewport width)
|
|
668
|
+
|
|
669
|
+
**Examples:**
|
|
670
|
+
```javascript
|
|
671
|
+
// Fixed width in pixels
|
|
672
|
+
initSidenet({ width: '500px' });
|
|
673
|
+
|
|
674
|
+
// Responsive width based on viewport
|
|
675
|
+
initSidenet({ width: '45vw' });
|
|
676
|
+
|
|
677
|
+
// Default width (45vw)
|
|
678
|
+
initSidenet();
|
|
679
|
+
```
|
|
680
|
+
|
|
681
|
+
## Usage Examples
|
|
682
|
+
|
|
683
|
+
### Example 1: Basic Integration
|
|
684
|
+
|
|
685
|
+
```javascript
|
|
686
|
+
import { initSidenet, toggleSidenet } from 'sidenetai-sdk';
|
|
687
|
+
import 'sidenetai-sdk/dist/sidenetai-sdk.css';
|
|
688
|
+
|
|
689
|
+
// Initialize sidebar on page load
|
|
690
|
+
initSidenet({
|
|
691
|
+
position: 'right',
|
|
692
|
+
defaultOpen: false
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
// Add a toggle button
|
|
696
|
+
document.getElementById('chat-button').addEventListener('click', toggleSidenet);
|
|
697
|
+
```
|
|
698
|
+
|
|
699
|
+
### Example 2: Dynamic Configuration Updates
|
|
700
|
+
|
|
701
|
+
```javascript
|
|
702
|
+
import { initSidenet, updateSidenetConfig } from 'sidenetai-sdk';
|
|
703
|
+
import 'sidenetai-sdk/dist/sidenetai-sdk.css';
|
|
704
|
+
|
|
705
|
+
// Initialize with default settings
|
|
706
|
+
initSidenet();
|
|
707
|
+
|
|
708
|
+
// Update configuration based on user preferences
|
|
709
|
+
function updateUserPreferences(userId, copilotId) {
|
|
710
|
+
updateSidenetConfig({
|
|
711
|
+
userId: userId,
|
|
712
|
+
copilotId: copilotId,
|
|
713
|
+
width: '50vw'
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
// Update based on screen size
|
|
718
|
+
function handleResize() {
|
|
719
|
+
const width = window.innerWidth < 768 ? '100vw' : '45vw';
|
|
720
|
+
updateSidenetConfig({ width });
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
window.addEventListener('resize', handleResize);
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
### Example 3: React Integration
|
|
727
|
+
|
|
728
|
+
```javascript
|
|
729
|
+
import React, { useEffect } from 'react';
|
|
730
|
+
import { initSidenet, destroySidenet, toggleSidenet } from 'sidenetai-sdk';
|
|
731
|
+
import 'sidenetai-sdk/dist/sidenetai-sdk.css';
|
|
732
|
+
|
|
733
|
+
function App() {
|
|
734
|
+
useEffect(() => {
|
|
735
|
+
// Initialize sidebar when component mounts
|
|
736
|
+
initSidenet({
|
|
737
|
+
position: 'right',
|
|
738
|
+
width: '45vw',
|
|
739
|
+
userId: 'user-123',
|
|
740
|
+
copilotId: 'project-456',
|
|
741
|
+
defaultOpen: false
|
|
742
|
+
});
|
|
743
|
+
|
|
744
|
+
// Cleanup when component unmounts
|
|
745
|
+
return () => {
|
|
746
|
+
destroySidenet();
|
|
747
|
+
};
|
|
748
|
+
}, []);
|
|
749
|
+
|
|
750
|
+
return (
|
|
751
|
+
<div>
|
|
752
|
+
<h1>My Application</h1>
|
|
753
|
+
<button onClick={toggleSidenet}>Toggle Chat</button>
|
|
754
|
+
</div>
|
|
755
|
+
);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
export default App;
|
|
759
|
+
```
|
|
760
|
+
|
|
761
|
+
### Example 4: Vanilla JavaScript with Event Handling
|
|
762
|
+
|
|
763
|
+
```javascript
|
|
764
|
+
import { initSidenet, toggleSidenet, updateSidenetConfig } from 'sidenetai-sdk';
|
|
765
|
+
import 'sidenetai-sdk/dist/sidenetai-sdk.css';
|
|
766
|
+
|
|
767
|
+
// Initialize sidebar
|
|
768
|
+
initSidenet({
|
|
769
|
+
position: 'right',
|
|
770
|
+
width: '45vw',
|
|
771
|
+
defaultOpen: false
|
|
772
|
+
});
|
|
773
|
+
|
|
774
|
+
// Make functions globally available
|
|
775
|
+
window.toggleSidenet = toggleSidenet;
|
|
776
|
+
|
|
777
|
+
// Handle keyboard shortcuts
|
|
778
|
+
document.addEventListener('keydown', (e) => {
|
|
779
|
+
// Toggle sidebar with Ctrl/Cmd + B
|
|
780
|
+
if ((e.ctrlKey || e.metaKey) && e.key === 'b') {
|
|
781
|
+
e.preventDefault();
|
|
782
|
+
toggleSidenet();
|
|
783
|
+
}
|
|
784
|
+
});
|
|
785
|
+
|
|
786
|
+
// Update sidebar when user logs in
|
|
787
|
+
function onUserLogin(userId, copilotId) {
|
|
788
|
+
updateSidenetConfig({
|
|
789
|
+
userId: userId,
|
|
790
|
+
copilotId: copilotId
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
```
|
|
794
|
+
|
|
795
|
+
### Example 5: Responsive Width Changes
|
|
796
|
+
|
|
797
|
+
```javascript
|
|
798
|
+
import { initSidenet, updateSidenetConfig } from 'sidenetai-sdk';
|
|
799
|
+
import 'sidenetai-sdk/dist/sidenetai-sdk.css';
|
|
800
|
+
|
|
801
|
+
// Initialize with responsive width
|
|
802
|
+
let currentWidth = window.innerWidth < 768 ? '100vw' : '45vw';
|
|
803
|
+
initSidenet({
|
|
804
|
+
width: currentWidth,
|
|
805
|
+
defaultOpen: false
|
|
806
|
+
});
|
|
807
|
+
|
|
808
|
+
// Update width on window resize
|
|
809
|
+
let resizeTimeout;
|
|
810
|
+
window.addEventListener('resize', () => {
|
|
811
|
+
clearTimeout(resizeTimeout);
|
|
812
|
+
resizeTimeout = setTimeout(() => {
|
|
813
|
+
const newWidth = window.innerWidth < 768 ? '100vw' : '45vw';
|
|
814
|
+
updateSidenetConfig({ width: newWidth });
|
|
815
|
+
}, 250); // Debounce resize events
|
|
816
|
+
});
|
|
817
|
+
```
|
|
818
|
+
|
|
819
|
+
## React Component Usage
|
|
820
|
+
|
|
821
|
+
For React applications where you want more control over the component lifecycle, you can import and use the `Sidebar` component directly:
|
|
822
|
+
|
|
823
|
+
```javascript
|
|
824
|
+
import React, { useState } from 'react';
|
|
825
|
+
import { Sidebar } from 'sidenetai-sdk';
|
|
826
|
+
import 'sidenetai-sdk/dist/sidenetai-sdk.css';
|
|
827
|
+
|
|
828
|
+
function App() {
|
|
829
|
+
const [sidebarConfig, setSidebarConfig] = useState({
|
|
830
|
+
position: 'right' as const,
|
|
831
|
+
width: '45vw',
|
|
832
|
+
userId: 'user-123',
|
|
833
|
+
copilotId: 'project-456',
|
|
834
|
+
defaultOpen: false
|
|
835
|
+
});
|
|
836
|
+
|
|
837
|
+
const handleWidthChange = (newWidth: string) => {
|
|
838
|
+
console.log('Sidebar width changed:', newWidth);
|
|
839
|
+
setSidebarConfig(prev => ({ ...prev, width: newWidth }));
|
|
840
|
+
};
|
|
841
|
+
|
|
842
|
+
return (
|
|
843
|
+
<div className="app">
|
|
844
|
+
<header>
|
|
845
|
+
<h1>My Application</h1>
|
|
846
|
+
</header>
|
|
847
|
+
<main>
|
|
848
|
+
{/* Your main content */}
|
|
849
|
+
</main>
|
|
850
|
+
<Sidebar
|
|
851
|
+
config={sidebarConfig}
|
|
852
|
+
onWidthChange={handleWidthChange}
|
|
853
|
+
/>
|
|
854
|
+
</div>
|
|
855
|
+
);
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
export default App;
|
|
859
|
+
```
|
|
860
|
+
|
|
861
|
+
## Customization
|
|
862
|
+
|
|
863
|
+
### CSS Import
|
|
864
|
+
|
|
865
|
+
The SDK requires its CSS file to be imported. Make sure to include it in your application:
|
|
866
|
+
|
|
867
|
+
```javascript
|
|
868
|
+
// ES Modules / NPM
|
|
869
|
+
import 'sidenetai-sdk/dist/sidenetai-sdk.css';
|
|
870
|
+
|
|
871
|
+
// CDN
|
|
872
|
+
<link rel="stylesheet" href="https://unpkg.com/sidenetai-sdk@latest/dist/sidenetai-sdk.css">
|
|
873
|
+
```
|
|
874
|
+
|
|
875
|
+
### CSS Variables
|
|
876
|
+
|
|
877
|
+
The sidebar uses CSS custom properties (variables) that can be overridden for customization. The container ID is fixed as `sidebarai-container`.
|
|
878
|
+
|
|
879
|
+
**Available CSS Variables:**
|
|
880
|
+
- `--sidebar-bg-color`: Background color of the sidebar
|
|
881
|
+
- `--sidebar-text-color`: Text color in the sidebar
|
|
882
|
+
- `--sidebar-border-color`: Border color
|
|
883
|
+
- `--sidebar-border-radius`: Border radius
|
|
884
|
+
- `--sidebar-font-size`: Font size
|
|
885
|
+
- `--sidebar-font-family`: Font family
|
|
886
|
+
- `--sidebar-box-shadow`: Box shadow
|
|
887
|
+
- `--sidebar-button-bg`: Button background color
|
|
888
|
+
- `--sidebar-button-hover`: Button hover color
|
|
889
|
+
|
|
890
|
+
**Example Customization:**
|
|
891
|
+
```css
|
|
892
|
+
/* Override sidebar styles */
|
|
893
|
+
#sidebarai-container {
|
|
894
|
+
--sidebar-bg-color: #1a1a1a;
|
|
895
|
+
--sidebar-text-color: #ffffff;
|
|
896
|
+
--sidebar-border-radius: 12px;
|
|
897
|
+
--sidebar-box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
/* Or override directly */
|
|
901
|
+
#sidebarai-container {
|
|
902
|
+
width: 500px !important;
|
|
903
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
|
|
904
|
+
border-radius: 12px !important;
|
|
905
|
+
}
|
|
906
|
+
```
|
|
907
|
+
|
|
908
|
+
### Container ID
|
|
909
|
+
|
|
910
|
+
The sidebar container uses a fixed ID: `sidebarai-container`. This ID cannot be changed, but you can style it using CSS:
|
|
911
|
+
|
|
912
|
+
```css
|
|
913
|
+
#sidebarai-container {
|
|
914
|
+
/* Your custom styles */
|
|
915
|
+
}
|
|
916
|
+
```
|
|
917
|
+
|
|
918
|
+
## Package Contents
|
|
919
|
+
|
|
920
|
+
The package includes the following files:
|
|
921
|
+
|
|
922
|
+
- **ES Module**: `dist/sidenetai-sdk.es.js` - For modern bundlers and ES module imports
|
|
923
|
+
- **UMD Bundle**: `dist/sidenetai-sdk.umd.js` - For script tag usage and older bundlers
|
|
924
|
+
- **CSS Styles**: `dist/sidenetai-sdk.css` - Required stylesheet
|
|
925
|
+
- **TypeScript Types**: Included automatically (TypeScript support)
|
|
926
|
+
|
|
927
|
+
## Development
|
|
928
|
+
|
|
929
|
+
### Prerequisites
|
|
930
|
+
|
|
931
|
+
- Node.js 18+
|
|
932
|
+
- pnpm (recommended) or npm/yarn
|
|
933
|
+
|
|
934
|
+
### Setup
|
|
935
|
+
|
|
936
|
+
```bash
|
|
937
|
+
# Install dependencies
|
|
938
|
+
pnpm install
|
|
939
|
+
|
|
940
|
+
# Start development server
|
|
941
|
+
pnpm dev
|
|
942
|
+
|
|
943
|
+
# Build for production
|
|
944
|
+
pnpm build
|
|
945
|
+
|
|
946
|
+
# Preview production build
|
|
947
|
+
pnpm preview
|
|
948
|
+
|
|
949
|
+
# Run linter
|
|
950
|
+
pnpm lint
|
|
951
|
+
```
|
|
952
|
+
|
|
953
|
+
### Project Structure
|
|
954
|
+
|
|
955
|
+
```
|
|
956
|
+
sidenetai-sdk/
|
|
957
|
+
├── src/
|
|
958
|
+
│ ├── components/ # React components
|
|
959
|
+
│ ├── api/ # API integration
|
|
960
|
+
│ ├── lib/ # Utilities and types
|
|
961
|
+
│ ├── hooks/ # React hooks
|
|
962
|
+
│ ├── sdk.tsx # Core SDK implementation
|
|
963
|
+
│ └── sdk-entry.ts # SDK entry point
|
|
964
|
+
├── dist/ # Built files (generated)
|
|
965
|
+
└── package.json
|
|
966
|
+
```
|
|
967
|
+
|
|
968
|
+
## TypeScript Support
|
|
969
|
+
|
|
970
|
+
The package includes full TypeScript definitions. Import types as needed:
|
|
971
|
+
|
|
972
|
+
```typescript
|
|
973
|
+
import { initSidenet, type SidenetOptions } from 'sidenetai-sdk';
|
|
974
|
+
|
|
975
|
+
const options: SidenetOptions = {
|
|
976
|
+
position: 'right',
|
|
977
|
+
width: '45vw',
|
|
978
|
+
userId: 'user-123',
|
|
979
|
+
copilotId: 'project-456',
|
|
980
|
+
defaultOpen: false
|
|
981
|
+
};
|
|
982
|
+
|
|
983
|
+
initSidenet(options);
|
|
984
|
+
```
|
|
985
|
+
|
|
986
|
+
## Browser Support
|
|
987
|
+
|
|
988
|
+
The SDK supports all modern browsers that support:
|
|
989
|
+
- ES6+ JavaScript features
|
|
990
|
+
- React 18 or 19
|
|
991
|
+
- CSS Custom Properties (CSS Variables)
|
|
992
|
+
|
|
993
|
+
**Minimum Browser Versions:**
|
|
994
|
+
- Chrome/Edge: 90+
|
|
995
|
+
- Firefox: 88+
|
|
996
|
+
- Safari: 14+
|
|
997
|
+
|
|
998
|
+
## Troubleshooting
|
|
999
|
+
|
|
1000
|
+
### Sidebar not appearing
|
|
1001
|
+
|
|
1002
|
+
1. Make sure you've imported the CSS file: `import 'sidenetai-sdk/dist/sidenetai-sdk.css'`
|
|
1003
|
+
2. Check that React and ReactDOM are loaded before initializing the SDK
|
|
1004
|
+
3. Verify that `initSidenet()` is being called after the DOM is ready
|
|
1005
|
+
|
|
1006
|
+
### Styles not applying
|
|
1007
|
+
|
|
1008
|
+
1. Ensure the CSS file is imported
|
|
1009
|
+
2. Check for CSS conflicts with your existing styles
|
|
1010
|
+
3. Verify that CSS custom properties are supported in your target browsers
|
|
1011
|
+
|
|
1012
|
+
### Multiple initialization warnings
|
|
1013
|
+
|
|
1014
|
+
If you see warnings about the sidebar being already initialized:
|
|
1015
|
+
- Call `destroySidenet()` before reinitializing
|
|
1016
|
+
- Or restructure your code to only call `initSidenet()` once
|
|
1017
|
+
|
|
1018
|
+
### React not found errors
|
|
1019
|
+
|
|
1020
|
+
If you're using a non-React app and see errors about React not being found:
|
|
1021
|
+
- **For NPM projects:** Install React as a dependency: `npm install react@^18 react-dom@^18`
|
|
1022
|
+
- **For CDN usage:** Ensure React and ReactDOM scripts are loaded before the SDK
|
|
1023
|
+
- **For build tools:** Make sure React is included in your bundle (it won't conflict with other frameworks)
|
|
1024
|
+
- React is only used internally by the SDK - your app doesn't need to use React
|
|
1025
|
+
|
|
1026
|
+
## License
|
|
1027
|
+
|
|
1028
|
+
MIT License - feel free to use in your projects!
|
|
1029
|
+
|
|
1030
|
+
## Contributing
|
|
1031
|
+
|
|
1032
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
1033
|
+
|
|
1034
|
+
## Support
|
|
1035
|
+
|
|
1036
|
+
For issues, questions, or feature requests, please open an issue on the GitHub repository.
|