nextjs-chatbot-ui 1.4.0 → 1.5.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 +145 -5
- package/api/chat.ts +97 -0
- package/api/database/collections.ts +80 -0
- package/api/database/columns.ts +80 -0
- package/api/database/process-embeddings.ts +154 -0
- package/api/database/test.ts +67 -0
- package/hooks/useAdminSetup.ts +86 -0
- package/hooks/useChatbot.ts +27 -0
- package/index.tsx +9 -5
- package/package.json +27 -5
- package/scripts/setup.js +550 -0
|
@@ -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,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nextjs-chatbot-ui",
|
|
3
|
-
|
|
4
|
-
"
|
|
5
|
-
"description": "A configurable chatbot UI component for Next.js with Tailwind CSS",
|
|
3
|
+
"version": "1.5.0",
|
|
4
|
+
"description": "A configurable chatbot UI component for Next.js with Tailwind CSS - Complete RAG chatbot with automatic setup",
|
|
6
5
|
"main": "./index.tsx",
|
|
7
6
|
"module": "./index.tsx",
|
|
8
7
|
"types": "./types/index.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"nextjs-chatbot-ui-setup": "./scripts/setup.js"
|
|
10
|
+
},
|
|
9
11
|
"exports": {
|
|
10
12
|
".": {
|
|
11
13
|
"types": "./types/index.ts",
|
|
@@ -24,20 +26,33 @@
|
|
|
24
26
|
"import": "./types/index.ts",
|
|
25
27
|
"require": "./types/index.ts",
|
|
26
28
|
"default": "./types/index.ts"
|
|
29
|
+
},
|
|
30
|
+
"./hooks/useChatbot": {
|
|
31
|
+
"import": "./hooks/useChatbot.ts",
|
|
32
|
+
"require": "./hooks/useChatbot.ts",
|
|
33
|
+
"default": "./hooks/useChatbot.ts"
|
|
34
|
+
},
|
|
35
|
+
"./hooks/useAdminSetup": {
|
|
36
|
+
"import": "./hooks/useAdminSetup.ts",
|
|
37
|
+
"require": "./hooks/useAdminSetup.ts",
|
|
38
|
+
"default": "./hooks/useAdminSetup.ts"
|
|
27
39
|
}
|
|
28
40
|
},
|
|
29
41
|
"files": [
|
|
30
42
|
"components",
|
|
31
43
|
"types",
|
|
32
44
|
"utils",
|
|
45
|
+
"hooks",
|
|
46
|
+
"api",
|
|
47
|
+
"scripts",
|
|
33
48
|
"index.tsx",
|
|
34
49
|
"README.md"
|
|
35
50
|
],
|
|
36
51
|
"scripts": {
|
|
37
52
|
"build": "echo 'Package is ready to use. Source files are included.'",
|
|
38
|
-
"dev": "next dev",
|
|
39
53
|
"prepare": "npm run build",
|
|
40
|
-
"type-check": "tsc --noEmit"
|
|
54
|
+
"type-check": "tsc --noEmit",
|
|
55
|
+
"setup": "node scripts/setup.js"
|
|
41
56
|
},
|
|
42
57
|
"keywords": [
|
|
43
58
|
"chatbot",
|
|
@@ -57,8 +72,15 @@
|
|
|
57
72
|
"dependencies": {
|
|
58
73
|
"clsx": "^2.1.0"
|
|
59
74
|
},
|
|
75
|
+
"optionalDependencies": {
|
|
76
|
+
"mongodb": "^6.0.0",
|
|
77
|
+
"pg": "^8.11.0",
|
|
78
|
+
"chromadb": "^1.8.0",
|
|
79
|
+
"openai": "^4.0.0"
|
|
80
|
+
},
|
|
60
81
|
"devDependencies": {
|
|
61
82
|
"@types/node": "^20.0.0",
|
|
83
|
+
"@types/pg": "^8.10.0",
|
|
62
84
|
"@types/react": "^18.0.0",
|
|
63
85
|
"@types/react-dom": "^18.0.0",
|
|
64
86
|
"autoprefixer": "^10.4.16",
|