agenticaichat 1.0.0 → 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.
Files changed (48) hide show
  1. package/README.md +83 -26
  2. package/bin/cli.js +301 -84
  3. package/dist/core/ChatbotEngine.d.ts +9 -1
  4. package/dist/core/ChatbotEngine.js +52 -19
  5. package/dist/core/EngineFactory.d.ts +45 -0
  6. package/dist/core/EngineFactory.js +126 -0
  7. package/dist/core/NLToSQLConverter.d.ts +6 -15
  8. package/dist/core/NLToSQLConverter.js +9 -114
  9. package/dist/engines/base/DatabaseEngine.d.ts +46 -0
  10. package/dist/engines/base/DatabaseEngine.js +42 -0
  11. package/dist/engines/nosql/MongoEngine.d.ts +13 -0
  12. package/dist/engines/nosql/MongoEngine.js +194 -0
  13. package/dist/engines/nosql/NoSqlEngine.d.ts +20 -0
  14. package/dist/engines/nosql/NoSqlEngine.js +29 -0
  15. package/dist/engines/sql/SqlEngine.d.ts +19 -0
  16. package/dist/engines/sql/SqlEngine.js +52 -0
  17. package/dist/engines/sql/dialects/MySQLDialect.d.ts +12 -0
  18. package/dist/engines/sql/dialects/MySQLDialect.js +109 -0
  19. package/dist/engines/sql/dialects/PostgresDialect.d.ts +11 -0
  20. package/dist/engines/sql/dialects/PostgresDialect.js +109 -0
  21. package/dist/engines/sql/dialects/SQLiteDialect.d.ts +10 -0
  22. package/dist/engines/sql/dialects/SQLiteDialect.js +101 -0
  23. package/dist/index.d.ts +17 -4
  24. package/dist/index.js +44 -8
  25. package/dist/llm/LLMFactory.d.ts +25 -0
  26. package/dist/llm/LLMFactory.js +137 -0
  27. package/dist/llm/providers/ClaudeProvider.d.ts +13 -0
  28. package/dist/llm/providers/ClaudeProvider.js +132 -0
  29. package/dist/llm/providers/DeepInfraProvider.d.ts +14 -0
  30. package/dist/llm/providers/DeepInfraProvider.js +144 -0
  31. package/dist/llm/providers/GeminiProvider.d.ts +13 -0
  32. package/dist/llm/providers/GeminiProvider.js +105 -0
  33. package/dist/llm/providers/GrokProvider.d.ts +14 -0
  34. package/dist/llm/providers/GrokProvider.js +144 -0
  35. package/dist/llm/providers/GroqProvider.d.ts +0 -0
  36. package/dist/llm/providers/GroqProvider.js +148 -0
  37. package/dist/llm/providers/OpenAIProvider.d.ts +13 -0
  38. package/dist/llm/providers/OpenAIProvider.js +136 -0
  39. package/dist/llm/providers/TogetherAIProvider.d.ts +14 -0
  40. package/dist/llm/providers/TogetherAIProvider.js +144 -0
  41. package/dist/llm/types.d.ts +34 -0
  42. package/dist/llm/types.js +2 -0
  43. package/dist/types/index.d.ts +23 -3
  44. package/dist/widget/ChatbotWidget.d.ts +1 -1
  45. package/dist/widget/ChatbotWidget.js +406 -125
  46. package/package.json +24 -5
  47. package/scripts/postinstall.js +126 -0
  48. 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.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": "rm -rf dist",
36
+ "clean": "node -e \"require('fs').rmSync('dist', {recursive: true, force: true})\"",
36
37
  "prebuild": "npm run clean",
37
- "test:engine": "ts-node tests/test.ts"
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",
@@ -50,12 +54,19 @@
50
54
  ],
51
55
  "author": "Bhaviraj",
52
56
  "license": "MIT",
53
- "repository": {
57
+ "repository": {
54
58
  "type": "git",
55
59
  "url": "https://github.com/Bhaviraj2004/agenticaichat.git"
56
60
  },
61
+ "bugs": {
62
+ "url": "https://github.com/Bhaviraj2004/agenticaichat/issues"
63
+ },
64
+ "homepage": "https://github.com/Bhaviraj2004/agenticaichat#readme",
57
65
  "dependencies": {
66
+ "@anthropic-ai/sdk": "^0.71.2",
67
+ "@google/generative-ai": "^0.24.1",
58
68
  "axios": "^1.13.2",
69
+ "better-sqlite3": "^12.5.0",
59
70
  "dotenv": "^17.2.3",
60
71
  "lucide-react": "^0.559.0",
61
72
  "mongodb": "^7.0.0",
@@ -66,6 +77,7 @@
66
77
  "react-dom": ">=18.0.0"
67
78
  },
68
79
  "devDependencies": {
80
+ "@types/better-sqlite3": "^7.6.13",
69
81
  "@types/inquirer": "^9.0.0",
70
82
  "@types/node": "^20.10.0",
71
83
  "@types/pg": "^8.15.6",
@@ -86,5 +98,12 @@
86
98
  "engines": {
87
99
  "node": ">=18.0.0",
88
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"
89
108
  }
90
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
- type: (process.env.DB_TYPE as any) || 'postgresql',
16
- url: process.env.DATABASE_URL || ''
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
- openai: {
19
- apiKey: process.env.OPENAI_API_KEY || '',
20
- model: (process.env.GPT_MODEL as any) || 'gpt-3.5-turbo'
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
- return NextResponse.json({
72
- status: 'ok',
73
- message: 'Chatbot API is running'
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
  }