nextjs-chatbot-ui 1.4.0 → 1.4.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 CHANGED
@@ -1,6 +1,27 @@
1
- # Chatbot UI Component
1
+ # nextjs-chatbot-ui
2
2
 
3
- A beautiful, configurable chatbot UI component for Next.js applications with Tailwind CSS. Inspired by Sendbird's modern chat interface.
3
+ A beautiful, configurable chatbot UI component for Next.js with Tailwind CSS. Perfect for customer support, AI assistants, and chat applications.
4
+
5
+ ## ⚡ Super Simple Usage (Just 2 Files!)
6
+
7
+ ```javascript
8
+ // app/page.tsx
9
+ 'use client';
10
+ import { Chatbot } from 'nextjs-chatbot-ui';
11
+ export default function Home() {
12
+ return <Chatbot config={{ backendUrl: '/api/chat' }} />;
13
+ }
14
+ ```
15
+
16
+ ```javascript
17
+ // app/api/chat/route.ts
18
+ export async function POST(req: Request) {
19
+ const { message } = await req.json();
20
+ return Response.json({ message: `You said: ${message}` });
21
+ }
22
+ ```
23
+
24
+ **Done!** See `SIMPLE_SETUP.md` for more examples.
4
25
 
5
26
  ## Features
6
27
 
@@ -33,6 +54,34 @@ This package requires:
33
54
  npm install nextjs-chatbot-ui
34
55
  ```
35
56
 
57
+ ## Quick Start (Minimal Code)
58
+
59
+ ### Simplest Usage (Just 2 files!)
60
+
61
+ **1. Add to your page:**
62
+ ```javascript
63
+ // app/page.tsx
64
+ 'use client';
65
+ import { Chatbot } from 'nextjs-chatbot-ui';
66
+
67
+ export default function Home() {
68
+ return <Chatbot config={{ backendUrl: '/api/chat' }} />;
69
+ }
70
+ ```
71
+
72
+ **2. Create API endpoint:**
73
+ ```javascript
74
+ // app/api/chat/route.ts
75
+ import { NextResponse } from 'next/server';
76
+
77
+ export async function POST(req: Request) {
78
+ const { message } = await req.json();
79
+ return NextResponse.json({ message: `You said: ${message}` });
80
+ }
81
+ ```
82
+
83
+ **Done!** See `SIMPLE_SETUP.md` for more examples.
84
+
36
85
  ## Usage
37
86
 
38
87
  ### Basic Setup
@@ -230,7 +279,9 @@ interface ChatbotConfig {
230
279
 
231
280
  ### Backend API Requirements
232
281
 
233
- Your backend should accept POST requests with the following format:
282
+ **✅ Works with ANY backend!** Express, FastAPI, Flask, Django, NestJS, Go, or any other framework.
283
+
284
+ Your backend just needs to implement **one POST endpoint** that accepts and returns JSON:
234
285
 
235
286
  **Request:**
236
287
  ```json
@@ -243,7 +294,7 @@ Your backend should accept POST requests with the following format:
243
294
  }
244
295
  ```
245
296
 
246
- **Response:**
297
+ **Response (either format works):**
247
298
  ```json
248
299
  {
249
300
  "message": "Bot's response text",
@@ -260,7 +311,10 @@ or
260
311
  }
261
312
  ```
262
313
 
263
- **Note:** The `suggestedReplies` or `suggestions` field is optional and will display as clickable buttons below the bot's message, similar to Sendbird's interface.
314
+ **Note:**
315
+ - The `suggestedReplies` or `suggestions` field is optional
316
+ - The component accepts either `message` or `response` in the response
317
+ - See `BACKEND_INTEGRATION.md` for examples with different backend frameworks (Express, FastAPI, Flask, Django, NestJS, Go, etc.)
264
318
 
265
319
  ### Example Implementation
266
320
 
@@ -500,6 +554,45 @@ If the database connection is not establishing:
500
554
 
501
555
  5. **Verify database credentials**: Ensure your database host, port, username, password, and database name are correct.
502
556
 
557
+ ## RAG Chatbot Architecture
558
+
559
+ This package supports RAG (Retrieval-Augmented Generation) chatbot architecture for answering questions about your database.
560
+
561
+ ### Architecture Flow
562
+
563
+ ```
564
+ React UI → Express API → MongoDB + ChromaDB → OpenAI
565
+ ```
566
+
567
+ 1. **Setup Phase**: Use `AdminSetup` component to connect to database, select collections/columns, and process embeddings
568
+ 2. **Query Phase**: Use `Chatbot` component to ask questions, which are answered using vector search and LLM generation
569
+
570
+ ### Quick Start with RAG
571
+
572
+ 1. **Set up backend** (see `server.js` or `example-nextjs-api-routes.md`):
573
+ - Express server with MongoDB, ChromaDB, and OpenAI integration
574
+ - Endpoints: `/api/search`, `/api/database/process-embeddings`
575
+
576
+ 2. **Configure chatbot**:
577
+ ```javascript
578
+ const config: ChatbotConfig = {
579
+ backendUrl: '/api/search', // RAG search endpoint
580
+ labels: {
581
+ title: 'RAG Chatbot',
582
+ placeholder: 'Ask me anything about your data...',
583
+ },
584
+ };
585
+ ```
586
+
587
+ 3. **Use AdminSetup** to:
588
+ - Connect to your database
589
+ - Select collections and columns
590
+ - Process embeddings (fetches data → converts to embeddings → stores in ChromaDB)
591
+
592
+ 4. **Query your data** using the Chatbot component
593
+
594
+ For complete RAG architecture documentation, see `RAG_ARCHITECTURE.md`.
595
+
503
596
  ## License
504
597
 
505
598
  MIT
@@ -0,0 +1,86 @@
1
+ import { useState } from 'react';
2
+ import type { DatabaseConfig, DatabaseConnection } from '../types/admin';
3
+
4
+ /**
5
+ * Simplified hook for admin setup
6
+ * Handles all API calls automatically
7
+ */
8
+ export function useAdminSetup() {
9
+ const [isLoading, setIsLoading] = useState(false);
10
+
11
+ const handleTestConnection = async (connection: DatabaseConnection): Promise<boolean> => {
12
+ setIsLoading(true);
13
+ try {
14
+ const response = await fetch('/api/database/test', {
15
+ method: 'POST',
16
+ headers: { 'Content-Type': 'application/json' },
17
+ body: JSON.stringify(connection),
18
+ });
19
+ const data = await response.json();
20
+ return data.success === true;
21
+ } catch (error) {
22
+ return false;
23
+ } finally {
24
+ setIsLoading(false);
25
+ }
26
+ };
27
+
28
+ const handleFetchCollections = async (connection: DatabaseConnection): Promise<string[]> => {
29
+ setIsLoading(true);
30
+ try {
31
+ const response = await fetch('/api/database/collections', {
32
+ method: 'POST',
33
+ headers: { 'Content-Type': 'application/json' },
34
+ body: JSON.stringify(connection),
35
+ });
36
+ const data = await response.json();
37
+ return data.collections || data.tables || [];
38
+ } catch (error) {
39
+ return [];
40
+ } finally {
41
+ setIsLoading(false);
42
+ }
43
+ };
44
+
45
+ const handleFetchColumns = async (connection: DatabaseConnection, collection?: string): Promise<string[]> => {
46
+ setIsLoading(true);
47
+ try {
48
+ const response = await fetch('/api/database/columns', {
49
+ method: 'POST',
50
+ headers: { 'Content-Type': 'application/json' },
51
+ body: JSON.stringify({ ...connection, collection }),
52
+ });
53
+ const data = await response.json();
54
+ return data.columns || [];
55
+ } catch (error) {
56
+ return [];
57
+ } finally {
58
+ setIsLoading(false);
59
+ }
60
+ };
61
+
62
+ const handleProcessEmbeddings = async (config: DatabaseConfig): Promise<{ success: boolean; message?: string }> => {
63
+ setIsLoading(true);
64
+ try {
65
+ const response = await fetch('/api/database/process-embeddings', {
66
+ method: 'POST',
67
+ headers: { 'Content-Type': 'application/json' },
68
+ body: JSON.stringify(config),
69
+ });
70
+ const data = await response.json();
71
+ return { success: data.success || false, message: data.message };
72
+ } catch (error: any) {
73
+ return { success: false, message: error.message };
74
+ } finally {
75
+ setIsLoading(false);
76
+ }
77
+ };
78
+
79
+ return {
80
+ handleTestConnection,
81
+ handleFetchCollections,
82
+ handleFetchColumns,
83
+ handleProcessEmbeddings,
84
+ isLoading,
85
+ };
86
+ }
@@ -0,0 +1,27 @@
1
+ import type { ChatbotConfig } from '../types';
2
+
3
+ /**
4
+ * Simplified hook for chatbot integration
5
+ * Handles all the configuration automatically
6
+ */
7
+ export function useChatbot(options?: {
8
+ apiUrl?: string;
9
+ title?: string;
10
+ primaryColor?: string;
11
+ }) {
12
+ const config: ChatbotConfig = {
13
+ backendUrl: options?.apiUrl || '/api/chat',
14
+ labels: {
15
+ title: options?.title || 'Chat Support',
16
+ placeholder: 'Type your message...',
17
+ sendButton: 'Send',
18
+ welcomeMessage: 'Hello! How can I help you?',
19
+ },
20
+ position: 'bottom-right',
21
+ primaryColor: options?.primaryColor || '#6B46C1',
22
+ autoOpen: false,
23
+ showTimestamp: true,
24
+ };
25
+
26
+ return { config };
27
+ }
package/index.tsx CHANGED
@@ -1,5 +1,9 @@
1
- export { default as Chatbot } from './components/Chatbot';
2
- export type { ChatbotConfig, Message, ChatbotProps } from './types';
3
-
4
- export { default as AdminSetup } from './components/AdminSetup';
5
- export type { DatabaseType, DatabaseConnection, ColumnSelection, DatabaseConfig, CollectionColumnMapping, AdminSetupProps } from './types/admin';
1
+ export { default as Chatbot } from './components/Chatbot';
2
+ export type { ChatbotConfig, Message, ChatbotProps } from './types';
3
+
4
+ export { default as AdminSetup } from './components/AdminSetup';
5
+ export type { DatabaseType, DatabaseConnection, ColumnSelection, DatabaseConfig, CollectionColumnMapping, AdminSetupProps } from './types/admin';
6
+
7
+ // Simplified hooks for easier usage
8
+ export { useChatbot } from './hooks/useChatbot';
9
+ export { useAdminSetup } from './hooks/useAdminSetup';
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "nextjs-chatbot-ui",
3
-
4
- "version": "1.4.0",
3
+ "version": "1.4.1",
5
4
  "description": "A configurable chatbot UI component for Next.js with Tailwind CSS",
6
5
  "main": "./index.tsx",
7
6
  "module": "./index.tsx",
@@ -24,18 +23,28 @@
24
23
  "import": "./types/index.ts",
25
24
  "require": "./types/index.ts",
26
25
  "default": "./types/index.ts"
26
+ },
27
+ "./hooks/useChatbot": {
28
+ "import": "./hooks/useChatbot.ts",
29
+ "require": "./hooks/useChatbot.ts",
30
+ "default": "./hooks/useChatbot.ts"
31
+ },
32
+ "./hooks/useAdminSetup": {
33
+ "import": "./hooks/useAdminSetup.ts",
34
+ "require": "./hooks/useAdminSetup.ts",
35
+ "default": "./hooks/useAdminSetup.ts"
27
36
  }
28
37
  },
29
38
  "files": [
30
39
  "components",
31
40
  "types",
32
41
  "utils",
42
+ "hooks",
33
43
  "index.tsx",
34
44
  "README.md"
35
45
  ],
36
46
  "scripts": {
37
47
  "build": "echo 'Package is ready to use. Source files are included.'",
38
- "dev": "next dev",
39
48
  "prepare": "npm run build",
40
49
  "type-check": "tsc --noEmit"
41
50
  },