brainkb-assistant
Version:
A configurable, standalone BrainKB Assistant that can be integrated into any website
286 lines (241 loc) ⢠6.67 kB
Markdown
A configurable, standalone chat widget that can be integrated into any website. It supports REST APIs, WebSocket connections, and provides a rich set of features for knowledge base interactions.
```bash
npm install brainkb-assistant
```
```jsx
import BrainKBAssistant from 'brainkb-assistant';
function App() {
const config = {
api: {
endpoint: 'https://api.example.com/chat',
type: 'rest'
},
branding: {
title: 'BrainKB Assistant'
}
};
return (
<div>
<h1>My Website</h1>
<BrainKBAssistant config={config} />
</div>
);
}
```
- **š§ Configurable** - Easy to customize branding, features, and API endpoints
- **š Universal** - Works with React, Next.js, static HTML, and any web framework
- **š± Responsive** - Adapts to different screen sizes and devices
- **šÆ Context Aware** - Automatically detects current page content
- **š¬ Rich Chat** - Markdown support, file uploads, quick actions
- **š Enhanced Tables** - Professional table rendering with download functionality
- **š„ Smart Downloads** - Multi-format data export (CSV, JSON, TSV)
- **š API Flexible** - Supports REST APIs and WebSocket connections
- **š JWT Authentication** - Secure authentication with username/password
- **šØ Customizable** - Branding, colors, positioning, and features
- **š¦ Standalone** - No dependencies on your existing codebase
- **š Dynamic Response Parsing** - Handles any API response structure
- **⨠Professional UI** - Beautiful gradients, animations, and modern design
## š Documentation
- [Installation Guide](./INSTALLATION.md) - Complete setup instructions
- [Setup Guide](./SETUP_GUIDE.md) - Detailed integration guide
- [Examples](./examples/) - Integration examples for different platforms
## š§ Configuration
### Basic Configuration
```javascript
const config = {
branding: {
title: 'BrainKB Assistant',
subtitle: 'Knowledge Helper',
primaryColor: 'from-purple-600 to-blue-600'
},
api: {
endpoint: 'https://api.example.com/chat',
type: 'rest', // or 'websocket'
streaming: true, // Enable streaming responses
headers: {
'Authorization': 'Bearer your-token'
}
},
features: {
enableQuickActions: true,
enableFileUpload: true,
enableContextDetection: true,
enableMarkdown: true,
enableMessageEditing: true,
enableCodeRendering: true,
enableTypingIndicator: true
},
ui: {
position: 'bottom-right', // bottom-right, bottom-left, top-right, top-left
size: {
width: '600px',
height: '700px'
},
theme: 'light', // light, dark, auto
zIndex: 999999
},
quickActions: [
{
id: 'help',
label: 'ā Get Help',
action: 'help',
description: 'Get assistance'
}
]
};
```
```javascript
const config = {
api: {
endpoint: 'https://api.example.com/chat',
type: 'rest',
streaming: true,
// JWT Authentication
auth: {
enabled: true,
type: 'jwt',
jwtEndpoint: 'https://api.example.com/auth/login',
username: 'your-username',
password: 'your-password',
// Optional: Custom token field names
tokenKey: 'access_token', // Default: 'access_token'
refreshTokenKey: 'refresh_token', // Default: 'refresh_token'
// Optional: Auto-refresh configuration
autoRefresh: true, // Default: false
refreshThreshold: 300, // Refresh 5 minutes before expiry
},
},
// ... other configuration
};
```
```jsx
import BrainKBAssistant from 'brainkb-assistant';
function App() {
const config = {
api: {
endpoint: 'https://api.example.com/chat'
},
branding: {
title: 'My Assistant'
}
};
return (
<div>
<h1>My React App</h1>
<BrainKBAssistant config={config} />
</div>
);
}
```
```tsx
// app/layout.tsx
import BrainKBAssistant from 'brainkb-assistant';
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
const config = {
api: {
endpoint: process.env.NEXT_PUBLIC_API_ENDPOINT
}
};
return (
<html lang="en">
<body>
{children}
<BrainKBAssistant config={config} />
</body>
</html>
);
}
```
```html
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/brainkb-assistant@latest/dist/index.js"></script>
</head>
<body>
<h1>My Website</h1>
<script>
const config = {
api: {
endpoint: 'https://api.example.com/chat'
}
};
BrainKBAssistant.init({ config });
</script>
</body>
</html>
```
The assistant now includes intelligent response parsing that handles any API response structure:
```javascript
// These response formats all work:
{ content: "Hello world" }
{ message: "Hello world" }
{ data: { text: "Hello world" } }
"Hello world"
["Hello", "world"]
{ custom_field: "Hello world" }
```
```bash
git clone https://github.com/brainkb/brainkb-assistant.git
npm install
npm run dev
npm run build
npm publish
```
```
brainkb-assistant/
āāā src/
ā āāā components/
ā ā āāā BrainKBAssistant.tsx
ā ā āāā BrainKBAssistantWrapper.tsx
ā āāā styles/
ā ā āāā brainkb-assistant.css
ā āāā index.ts
āāā examples/
ā āāā react-integration.jsx
ā āāā nextjs-integration.tsx
ā āāā static-html-integration.html
ā āāā nodejs-server.js
āāā dist/
ā āāā index.js
ā āāā index.esm.js
ā āāā index.d.ts
āāā package.json
```
1. Fork the repository
2. Create a feature branch: `git checkout -b feature-name`
3. Make your changes
4. Run tests: `npm test`
5. Commit your changes: `git commit -am 'Add feature'`
6. Push to the branch: `git push origin feature-name`
7. Submit a pull request
MIT License - see [LICENSE](./LICENSE) for details.
- š [Documentation](./SETUP_GUIDE.md)
- š” [Examples](./examples/)
- š [Issues](https://github.com/brainkb/brainkb-assistant/issues)
- š¬ [Discussions](https://github.com/brainkb/brainkb-assistant/discussions)