agenticaichat 1.0.1 → 1.0.3
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 +83 -26
- package/bin/cli.js +301 -84
- package/dist/core/ChatbotEngine.d.ts +9 -1
- package/dist/core/ChatbotEngine.js +52 -19
- package/dist/core/EngineFactory.d.ts +45 -0
- package/dist/core/EngineFactory.js +126 -0
- package/dist/core/NLToSQLConverter.d.ts +6 -15
- package/dist/core/NLToSQLConverter.js +9 -114
- package/dist/engines/base/DatabaseEngine.d.ts +46 -0
- package/dist/engines/base/DatabaseEngine.js +42 -0
- package/dist/engines/nosql/MongoEngine.d.ts +13 -0
- package/dist/engines/nosql/MongoEngine.js +194 -0
- package/dist/engines/nosql/NoSqlEngine.d.ts +20 -0
- package/dist/engines/nosql/NoSqlEngine.js +29 -0
- package/dist/engines/sql/SqlEngine.d.ts +19 -0
- package/dist/engines/sql/SqlEngine.js +52 -0
- package/dist/engines/sql/dialects/MySQLDialect.d.ts +12 -0
- package/dist/engines/sql/dialects/MySQLDialect.js +109 -0
- package/dist/engines/sql/dialects/PostgresDialect.d.ts +11 -0
- package/dist/engines/sql/dialects/PostgresDialect.js +109 -0
- package/dist/engines/sql/dialects/SQLiteDialect.d.ts +10 -0
- package/dist/engines/sql/dialects/SQLiteDialect.js +101 -0
- package/dist/index.d.ts +17 -4
- package/dist/index.js +44 -8
- package/dist/llm/LLMFactory.d.ts +25 -0
- package/dist/llm/LLMFactory.js +137 -0
- package/dist/llm/providers/ClaudeProvider.d.ts +13 -0
- package/dist/llm/providers/ClaudeProvider.js +132 -0
- package/dist/llm/providers/DeepInfraProvider.d.ts +14 -0
- package/dist/llm/providers/DeepInfraProvider.js +144 -0
- package/dist/llm/providers/GeminiProvider.d.ts +13 -0
- package/dist/llm/providers/GeminiProvider.js +105 -0
- package/dist/llm/providers/GrokProvider.d.ts +14 -0
- package/dist/llm/providers/GrokProvider.js +144 -0
- package/dist/llm/providers/GroqProvider.d.ts +0 -0
- package/dist/llm/providers/GroqProvider.js +148 -0
- package/dist/llm/providers/OpenAIProvider.d.ts +13 -0
- package/dist/llm/providers/OpenAIProvider.js +136 -0
- package/dist/llm/providers/TogetherAIProvider.d.ts +14 -0
- package/dist/llm/providers/TogetherAIProvider.js +144 -0
- package/dist/llm/types.d.ts +34 -0
- package/dist/llm/types.js +2 -0
- package/dist/types/index.d.ts +23 -3
- package/dist/widget/ChatbotWidget.d.ts +1 -1
- package/dist/widget/ChatbotWidget.js +406 -125
- package/package.json +19 -4
- package/scripts/postinstall.js +126 -0
- package/templates/api-route.template.ts +24 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agenticaichat",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "AI-powered chatbot for business analytics with natural language database queries",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,14 +27,18 @@
|
|
|
27
27
|
"files": [
|
|
28
28
|
"dist",
|
|
29
29
|
"bin",
|
|
30
|
-
"templates"
|
|
30
|
+
"templates",
|
|
31
|
+
"scripts"
|
|
31
32
|
],
|
|
32
33
|
"scripts": {
|
|
33
34
|
"build": "tsc",
|
|
34
35
|
"dev": "tsc --watch",
|
|
35
|
-
"clean": "
|
|
36
|
+
"clean": "node -e \"require('fs').rmSync('dist', {recursive: true, force: true})\"",
|
|
36
37
|
"prebuild": "npm run clean",
|
|
37
|
-
"
|
|
38
|
+
"postinstall": "node scripts/postinstall.js",
|
|
39
|
+
"test:engine": "ts-node tests/test.ts",
|
|
40
|
+
"link": "npm run build && npm link",
|
|
41
|
+
"link:example": "cd examples/nextjs-example && npm link agenticaichat"
|
|
38
42
|
},
|
|
39
43
|
"keywords": [
|
|
40
44
|
"ai",
|
|
@@ -59,7 +63,10 @@
|
|
|
59
63
|
},
|
|
60
64
|
"homepage": "https://github.com/Bhaviraj2004/agenticaichat#readme",
|
|
61
65
|
"dependencies": {
|
|
66
|
+
"@anthropic-ai/sdk": "^0.71.2",
|
|
67
|
+
"@google/generative-ai": "^0.24.1",
|
|
62
68
|
"axios": "^1.13.2",
|
|
69
|
+
"better-sqlite3": "^12.5.0",
|
|
63
70
|
"dotenv": "^17.2.3",
|
|
64
71
|
"lucide-react": "^0.559.0",
|
|
65
72
|
"mongodb": "^7.0.0",
|
|
@@ -70,6 +77,7 @@
|
|
|
70
77
|
"react-dom": ">=18.0.0"
|
|
71
78
|
},
|
|
72
79
|
"devDependencies": {
|
|
80
|
+
"@types/better-sqlite3": "^7.6.13",
|
|
73
81
|
"@types/inquirer": "^9.0.0",
|
|
74
82
|
"@types/node": "^20.10.0",
|
|
75
83
|
"@types/pg": "^8.15.6",
|
|
@@ -90,5 +98,12 @@
|
|
|
90
98
|
"engines": {
|
|
91
99
|
"node": ">=18.0.0",
|
|
92
100
|
"npm": ">=9.0.0"
|
|
101
|
+
},
|
|
102
|
+
"optionalDependencies": {
|
|
103
|
+
"@aws-sdk/credential-providers": "^3.962.0",
|
|
104
|
+
"@mongodb-js/zstd": "^7.0.0",
|
|
105
|
+
"gcp-metadata": "^7.0.1",
|
|
106
|
+
"pg-native": "^3.5.2",
|
|
107
|
+
"socks": "^2.8.7"
|
|
93
108
|
}
|
|
94
109
|
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawn } = require('child_process');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
console.log('\n🔍 Postinstall script running...\n');
|
|
8
|
+
|
|
9
|
+
// Check if running in CI/CD environment
|
|
10
|
+
const isCI = !!(
|
|
11
|
+
process.env.CI ||
|
|
12
|
+
process.env.CONTINUOUS_INTEGRATION ||
|
|
13
|
+
process.env.GITHUB_ACTIONS ||
|
|
14
|
+
process.env.GITLAB_CI ||
|
|
15
|
+
process.env.CIRCLECI ||
|
|
16
|
+
process.env.TRAVIS
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
// Check if we're in node_modules (installed as dependency)
|
|
20
|
+
const isInNodeModules = __dirname.includes('node_modules');
|
|
21
|
+
|
|
22
|
+
// Check if config files already exist in target project
|
|
23
|
+
const targetDir = isInNodeModules
|
|
24
|
+
? path.resolve(__dirname, '..', '..', '..') // node_modules/agenticaichat/scripts -> project root
|
|
25
|
+
: process.cwd();
|
|
26
|
+
|
|
27
|
+
const configExists = fs.existsSync(path.join(targetDir, '.env.chatbot')) ||
|
|
28
|
+
fs.existsSync(path.join(targetDir, 'chatbot-config.json'));
|
|
29
|
+
|
|
30
|
+
console.log('📊 Debug Info:');
|
|
31
|
+
console.log(' - Is in node_modules:', isInNodeModules);
|
|
32
|
+
console.log(' - Is CI:', isCI);
|
|
33
|
+
console.log(' - Config exists:', configExists);
|
|
34
|
+
console.log(' - Target directory:', targetDir);
|
|
35
|
+
console.log(' - Script location:', __dirname);
|
|
36
|
+
console.log('');
|
|
37
|
+
|
|
38
|
+
// Skip postinstall in these scenarios
|
|
39
|
+
if (isCI) {
|
|
40
|
+
console.log('📦 CI environment detected, skipping setup wizard.\n');
|
|
41
|
+
process.exit(0);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!isInNodeModules) {
|
|
45
|
+
console.log('🔧 Development mode detected, skipping postinstall.\n');
|
|
46
|
+
console.log('💡 This is normal when running in the package development directory.\n');
|
|
47
|
+
process.exit(0);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (configExists) {
|
|
51
|
+
console.log('✅ AgenticAIChat is already configured!');
|
|
52
|
+
console.log('📝 To reconfigure, run: \x1b[36mnpx agenticai-setup\x1b[0m\n');
|
|
53
|
+
process.exit(0);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Welcome banner
|
|
57
|
+
console.log('\x1b[36m╔════════════════════════════════════════╗\x1b[0m');
|
|
58
|
+
console.log('\x1b[36m║ 🤖 Welcome to AgenticAIChat! ║\x1b[0m');
|
|
59
|
+
console.log('\x1b[36m╚════════════════════════════════════════╝\x1b[0m\n');
|
|
60
|
+
|
|
61
|
+
console.log('\x1b[1mThank you for installing AgenticAIChat!\x1b[0m\n');
|
|
62
|
+
|
|
63
|
+
console.log('\x1b[33mAutomatic setup will run now (interactive terminal required).\x1b[0m');
|
|
64
|
+
console.log('\x1b[2mIf you prefer to skip, press Ctrl+C. You can rerun later with: npx agenticai-setup\x1b[0m\n');
|
|
65
|
+
|
|
66
|
+
// Ensure we can actually prompt the user
|
|
67
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
68
|
+
console.log('⚠️ Non-interactive environment detected. Skipping setup wizard.');
|
|
69
|
+
console.log('📝 Run setup manually when ready: \x1b[36mnpx agenticai-setup\x1b[0m\n');
|
|
70
|
+
process.exit(0);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
console.log('\n🚀 Starting setup wizard...\n');
|
|
74
|
+
|
|
75
|
+
// Find the CLI script - it should be in ../bin/cli.js relative to this script
|
|
76
|
+
const cliPath = path.join(__dirname, '..', 'bin', 'cli.js');
|
|
77
|
+
|
|
78
|
+
if (!fs.existsSync(cliPath)) {
|
|
79
|
+
console.error('\n❌ Error: Setup wizard not found at:', cliPath);
|
|
80
|
+
console.log('📝 Try running manually: \x1b[36mnpx agenticai-setup\x1b[0m\n');
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Change to target directory before running CLI
|
|
85
|
+
process.chdir(targetDir);
|
|
86
|
+
|
|
87
|
+
// Run the setup CLI
|
|
88
|
+
const setupProcess = spawn('node', [cliPath], {
|
|
89
|
+
stdio: 'inherit',
|
|
90
|
+
shell: process.platform === 'win32',
|
|
91
|
+
cwd: targetDir
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
setupProcess.on('error', (err) => {
|
|
95
|
+
console.error('\n❌ Failed to start setup wizard:', err.message);
|
|
96
|
+
console.log('📝 Try running manually: \x1b[36mnpx agenticai-setup\x1b[0m\n');
|
|
97
|
+
process.exit(1);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
setupProcess.on('close', (code) => {
|
|
101
|
+
if (code === 0) {
|
|
102
|
+
console.log('\n\x1b[32m╔════════════════════════════════════════╗\x1b[0m');
|
|
103
|
+
console.log('\x1b[32m║ ✅ Setup Completed Successfully! ║\x1b[0m');
|
|
104
|
+
console.log('\x1b[32m╚════════════════════════════════════════╝\x1b[0m\n');
|
|
105
|
+
|
|
106
|
+
console.log('\x1b[1m📚 Quick Start Guide:\x1b[0m\n');
|
|
107
|
+
console.log('1️⃣ Import the widget in your component:');
|
|
108
|
+
console.log(' \x1b[36mimport { ChatbotWidget } from "agenticaichat";\x1b[0m\n');
|
|
109
|
+
|
|
110
|
+
console.log('2️⃣ Add it to your JSX:');
|
|
111
|
+
console.log(' \x1b[36m<ChatbotWidget />\x1b[0m\n');
|
|
112
|
+
|
|
113
|
+
console.log('3️⃣ Start your dev server:');
|
|
114
|
+
console.log(' \x1b[36mnpm run dev\x1b[0m\n');
|
|
115
|
+
} else if (code !== null) {
|
|
116
|
+
console.log('\n⚠️ Setup was cancelled or encountered an error.');
|
|
117
|
+
console.log('📝 Run setup later: \x1b[36mnpx agenticai-setup\x1b[0m\n');
|
|
118
|
+
}
|
|
119
|
+
process.exit(code || 0);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
process.on('SIGINT', () => {
|
|
123
|
+
console.log('\n\n⚠️ Setup cancelled.');
|
|
124
|
+
console.log('📝 Run setup later: \x1b[36mnpx agenticai-setup\x1b[0m\n');
|
|
125
|
+
process.exit(0);
|
|
126
|
+
});
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
// This is a template file - TypeScript errors are expected here
|
|
3
3
|
// When copied to user's project, 'agenticaichat' will be installed
|
|
4
4
|
import { NextRequest, NextResponse } from 'next/server';
|
|
5
|
-
import { ChatbotEngine } from 'agenticaichat';
|
|
6
|
-
import { ChatbotConfig } from 'agenticaichat';
|
|
5
|
+
import { ChatbotEngine, ChatbotConfig, DatabaseCategory, SupportedDatabaseType, LLMProviderType } from 'agenticaichat';
|
|
7
6
|
|
|
8
7
|
// Initialize chatbot engine
|
|
9
8
|
let chatbotEngine: ChatbotEngine | null = null;
|
|
@@ -12,12 +11,15 @@ async function getEngine(): Promise<ChatbotEngine> {
|
|
|
12
11
|
if (!chatbotEngine) {
|
|
13
12
|
const config: ChatbotConfig = {
|
|
14
13
|
database: {
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
category: (process.env.DB_CATEGORY as DatabaseCategory) || 'sql',
|
|
15
|
+
type: (process.env.DB_TYPE as SupportedDatabaseType) || 'postgresql',
|
|
16
|
+
url: process.env.DATABASE_URL || '',
|
|
17
|
+
database: process.env.DB_NAME
|
|
17
18
|
},
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
llm: {
|
|
20
|
+
provider: (process.env.LLM_PROVIDER as LLMProviderType) || 'openai',
|
|
21
|
+
apiKey: process.env.LLM_API_KEY || '',
|
|
22
|
+
model: process.env.LLM_MODEL || 'gpt-3.5-turbo'
|
|
21
23
|
},
|
|
22
24
|
debug: process.env.NODE_ENV === 'development'
|
|
23
25
|
};
|
|
@@ -41,10 +43,7 @@ export async function POST(request: NextRequest) {
|
|
|
41
43
|
);
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
// Get chatbot engine
|
|
45
46
|
const engine = await getEngine();
|
|
46
|
-
|
|
47
|
-
// Process query
|
|
48
47
|
const response = await engine.processQuery({ query });
|
|
49
48
|
|
|
50
49
|
return NextResponse.json({
|
|
@@ -68,8 +67,19 @@ export async function POST(request: NextRequest) {
|
|
|
68
67
|
}
|
|
69
68
|
|
|
70
69
|
export async function GET(request: NextRequest) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
try {
|
|
71
|
+
const engine = await getEngine();
|
|
72
|
+
const status = engine.getStatus();
|
|
73
|
+
|
|
74
|
+
return NextResponse.json({
|
|
75
|
+
status: 'ok',
|
|
76
|
+
message: 'Chatbot API is running',
|
|
77
|
+
engine: status
|
|
78
|
+
});
|
|
79
|
+
} catch (error) {
|
|
80
|
+
return NextResponse.json({
|
|
81
|
+
status: 'error',
|
|
82
|
+
message: (error as Error).message
|
|
83
|
+
}, { status: 500 });
|
|
84
|
+
}
|
|
75
85
|
}
|