agenticaichat 1.0.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 +71 -0
- package/bin/cli.js +222 -0
- package/dist/core/ChatbotEngine.d.ts +28 -0
- package/dist/core/ChatbotEngine.js +95 -0
- package/dist/core/DatabaseConnector.d.ts +55 -0
- package/dist/core/DatabaseConnector.js +229 -0
- package/dist/core/NLToSQLConverter.d.ts +26 -0
- package/dist/core/NLToSQLConverter.js +154 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +18 -0
- package/dist/types/index.d.ts +45 -0
- package/dist/types/index.js +2 -0
- package/dist/utils/logger.d.ts +9 -0
- package/dist/utils/logger.js +24 -0
- package/dist/widget/ChatbotWidget.d.ts +5 -0
- package/dist/widget/ChatbotWidget.js +218 -0
- package/dist/widget/index.d.ts +1 -0
- package/dist/widget/index.js +5 -0
- package/package.json +90 -0
- package/templates/api-route.template.ts +75 -0
- package/templates/chat-page.template.tsx +13 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { OpenAIConfig, DatabaseSchema } from '../types';
|
|
2
|
+
export declare class NLToSQLConverter {
|
|
3
|
+
private openai;
|
|
4
|
+
private model;
|
|
5
|
+
constructor(config: OpenAIConfig);
|
|
6
|
+
/**
|
|
7
|
+
* Convert natural language to SQL
|
|
8
|
+
*/
|
|
9
|
+
convertToSQL(userQuery: string, schema: DatabaseSchema): Promise<string>;
|
|
10
|
+
/**
|
|
11
|
+
* Generate human-readable response
|
|
12
|
+
*/
|
|
13
|
+
generateHumanResponse(userQuery: string, queryResult: any): Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Build SQL generation prompt
|
|
16
|
+
*/
|
|
17
|
+
private buildPrompt;
|
|
18
|
+
/**
|
|
19
|
+
* Format schema for prompt
|
|
20
|
+
*/
|
|
21
|
+
private formatSchemaForPrompt;
|
|
22
|
+
/**
|
|
23
|
+
* Validate SQL query for security
|
|
24
|
+
*/
|
|
25
|
+
validateSQL(sql: string): boolean;
|
|
26
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NLToSQLConverter = void 0;
|
|
7
|
+
const openai_1 = __importDefault(require("openai"));
|
|
8
|
+
const logger_1 = require("../utils/logger");
|
|
9
|
+
class NLToSQLConverter {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.openai = new openai_1.default({
|
|
12
|
+
apiKey: config.apiKey
|
|
13
|
+
});
|
|
14
|
+
this.model = config.model;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Convert natural language to SQL
|
|
18
|
+
*/
|
|
19
|
+
async convertToSQL(userQuery, schema) {
|
|
20
|
+
try {
|
|
21
|
+
logger_1.logger.info('Converting NL to SQL...');
|
|
22
|
+
const schemaDescription = this.formatSchemaForPrompt(schema);
|
|
23
|
+
const prompt = this.buildPrompt(userQuery, schemaDescription);
|
|
24
|
+
const response = await this.openai.chat.completions.create({
|
|
25
|
+
model: this.model,
|
|
26
|
+
messages: [
|
|
27
|
+
{
|
|
28
|
+
role: 'system',
|
|
29
|
+
content: 'You are an expert SQL query generator. Generate ONLY valid SQL queries without any explanation or markdown.'
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
role: 'user',
|
|
33
|
+
content: prompt
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
temperature: 0.2,
|
|
37
|
+
max_tokens: 500
|
|
38
|
+
});
|
|
39
|
+
const sqlQuery = response.choices[0]?.message?.content?.trim() || '';
|
|
40
|
+
// Remove markdown code blocks if present
|
|
41
|
+
const cleanedSQL = sqlQuery
|
|
42
|
+
.replace(/```sql\n?/g, '')
|
|
43
|
+
.replace(/```\n?/g, '')
|
|
44
|
+
.trim();
|
|
45
|
+
logger_1.logger.debug_log('Generated SQL:', cleanedSQL);
|
|
46
|
+
return cleanedSQL;
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
logger_1.logger.error('NL to SQL conversion failed', error);
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Generate human-readable response
|
|
55
|
+
*/
|
|
56
|
+
async generateHumanResponse(userQuery, queryResult) {
|
|
57
|
+
try {
|
|
58
|
+
logger_1.logger.info('Generating human response...');
|
|
59
|
+
const prompt = `
|
|
60
|
+
User asked: "${userQuery}"
|
|
61
|
+
|
|
62
|
+
Database returned this result:
|
|
63
|
+
${JSON.stringify(queryResult, null, 2)}
|
|
64
|
+
|
|
65
|
+
Please provide a clear, conversational answer in Hindi/English mix (Hinglish) that explains this data to a business owner. Be specific with numbers.
|
|
66
|
+
`;
|
|
67
|
+
const response = await this.openai.chat.completions.create({
|
|
68
|
+
model: this.model,
|
|
69
|
+
messages: [
|
|
70
|
+
{
|
|
71
|
+
role: 'system',
|
|
72
|
+
content: 'You are a helpful business analytics assistant. Explain data clearly in Hinglish (Hindi-English mix).'
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
role: 'user',
|
|
76
|
+
content: prompt
|
|
77
|
+
}
|
|
78
|
+
],
|
|
79
|
+
temperature: 0.7,
|
|
80
|
+
max_tokens: 300
|
|
81
|
+
});
|
|
82
|
+
const answer = response.choices[0]?.message?.content?.trim() || 'Sorry, I could not generate a response.';
|
|
83
|
+
logger_1.logger.debug_log('Generated response:', answer);
|
|
84
|
+
return answer;
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
logger_1.logger.error('Response generation failed', error);
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Build SQL generation prompt
|
|
93
|
+
*/
|
|
94
|
+
buildPrompt(userQuery, schemaDescription) {
|
|
95
|
+
return `
|
|
96
|
+
You are a SQL expert. Generate a SQL query based on the user's question.
|
|
97
|
+
|
|
98
|
+
Database Schema:
|
|
99
|
+
${schemaDescription}
|
|
100
|
+
|
|
101
|
+
User Question: "${userQuery}"
|
|
102
|
+
|
|
103
|
+
Rules:
|
|
104
|
+
1. Return ONLY the SQL query, nothing else
|
|
105
|
+
2. Use correct table and column names from the schema
|
|
106
|
+
3. Add WHERE clauses for date filtering when needed
|
|
107
|
+
4. Use SUM, COUNT, AVG for aggregations
|
|
108
|
+
5. Handle both singular and plural forms (sales/sale, orders/order)
|
|
109
|
+
6. Use CURRENT_DATE, CURRENT_MONTH for time-based queries
|
|
110
|
+
7. Make sure the query is syntactically correct
|
|
111
|
+
|
|
112
|
+
SQL Query:
|
|
113
|
+
`;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Format schema for prompt
|
|
117
|
+
*/
|
|
118
|
+
formatSchemaForPrompt(schema) {
|
|
119
|
+
let description = '';
|
|
120
|
+
for (const table of schema.tables) {
|
|
121
|
+
description += `\nTable: ${table.name}\n`;
|
|
122
|
+
description += 'Columns:\n';
|
|
123
|
+
for (const column of table.columns) {
|
|
124
|
+
description += ` - ${column.name} (${column.type})${column.nullable ? ' [nullable]' : ''}\n`;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return description;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Validate SQL query for security
|
|
131
|
+
*/
|
|
132
|
+
validateSQL(sql) {
|
|
133
|
+
const dangerousKeywords = [
|
|
134
|
+
'DROP',
|
|
135
|
+
'DELETE',
|
|
136
|
+
'TRUNCATE',
|
|
137
|
+
'ALTER',
|
|
138
|
+
'CREATE',
|
|
139
|
+
'GRANT',
|
|
140
|
+
'REVOKE',
|
|
141
|
+
'INSERT',
|
|
142
|
+
'UPDATE'
|
|
143
|
+
];
|
|
144
|
+
const upperSQL = sql.toUpperCase();
|
|
145
|
+
for (const keyword of dangerousKeywords) {
|
|
146
|
+
if (upperSQL.includes(keyword)) {
|
|
147
|
+
logger_1.logger.warn(`Dangerous SQL keyword detected: ${keyword}`);
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.NLToSQLConverter = NLToSQLConverter;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { ChatbotWidget } from './widget';
|
|
2
|
+
export type { ChatbotWidgetProps } from './widget/ChatbotWidget';
|
|
3
|
+
export { DatabaseConnector } from './core/DatabaseConnector';
|
|
4
|
+
export { NLToSQLConverter } from './core/NLToSQLConverter';
|
|
5
|
+
export { ChatbotEngine } from './core/ChatbotEngine';
|
|
6
|
+
export type { DatabaseType, DatabaseConfig, DatabaseSchema, TableSchema, ColumnSchema, OpenAIConfig, ChatMessage, QueryRequest, QueryResponse, ChatbotConfig } from './types';
|
|
7
|
+
export { Logger, logger } from './utils/logger';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logger = exports.Logger = exports.ChatbotEngine = exports.NLToSQLConverter = exports.DatabaseConnector = exports.ChatbotWidget = void 0;
|
|
4
|
+
// Client-side exports (safe for browser)
|
|
5
|
+
var widget_1 = require("./widget");
|
|
6
|
+
Object.defineProperty(exports, "ChatbotWidget", { enumerable: true, get: function () { return widget_1.ChatbotWidget; } });
|
|
7
|
+
// Server-side exports (Node.js only)
|
|
8
|
+
// These should only be imported in API routes or server components
|
|
9
|
+
var DatabaseConnector_1 = require("./core/DatabaseConnector");
|
|
10
|
+
Object.defineProperty(exports, "DatabaseConnector", { enumerable: true, get: function () { return DatabaseConnector_1.DatabaseConnector; } });
|
|
11
|
+
var NLToSQLConverter_1 = require("./core/NLToSQLConverter");
|
|
12
|
+
Object.defineProperty(exports, "NLToSQLConverter", { enumerable: true, get: function () { return NLToSQLConverter_1.NLToSQLConverter; } });
|
|
13
|
+
var ChatbotEngine_1 = require("./core/ChatbotEngine");
|
|
14
|
+
Object.defineProperty(exports, "ChatbotEngine", { enumerable: true, get: function () { return ChatbotEngine_1.ChatbotEngine; } });
|
|
15
|
+
// Utils
|
|
16
|
+
var logger_1 = require("./utils/logger");
|
|
17
|
+
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
|
|
18
|
+
Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return logger_1.logger; } });
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export type DatabaseType = 'postgresql' | 'mysql' | 'mongodb';
|
|
2
|
+
export interface DatabaseConfig {
|
|
3
|
+
type: DatabaseType;
|
|
4
|
+
url: string;
|
|
5
|
+
host?: string;
|
|
6
|
+
port?: number;
|
|
7
|
+
username?: string;
|
|
8
|
+
password?: string;
|
|
9
|
+
database?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface DatabaseSchema {
|
|
12
|
+
tables: TableSchema[];
|
|
13
|
+
}
|
|
14
|
+
export interface TableSchema {
|
|
15
|
+
name: string;
|
|
16
|
+
columns: ColumnSchema[];
|
|
17
|
+
}
|
|
18
|
+
export interface ColumnSchema {
|
|
19
|
+
name: string;
|
|
20
|
+
type: string;
|
|
21
|
+
nullable: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface OpenAIConfig {
|
|
24
|
+
apiKey: string;
|
|
25
|
+
model: 'gpt-3.5-turbo' | 'gpt-4';
|
|
26
|
+
}
|
|
27
|
+
export interface ChatMessage {
|
|
28
|
+
role: 'system' | 'user' | 'assistant';
|
|
29
|
+
content: string;
|
|
30
|
+
}
|
|
31
|
+
export interface QueryRequest {
|
|
32
|
+
query: string;
|
|
33
|
+
context?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface QueryResponse {
|
|
36
|
+
answer: string;
|
|
37
|
+
sql?: string;
|
|
38
|
+
data?: any;
|
|
39
|
+
error?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface ChatbotConfig {
|
|
42
|
+
database: DatabaseConfig;
|
|
43
|
+
openai: OpenAIConfig;
|
|
44
|
+
debug?: boolean;
|
|
45
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class Logger {
|
|
2
|
+
private debug;
|
|
3
|
+
constructor(debug?: boolean);
|
|
4
|
+
info(message: string, ...args: any[]): void;
|
|
5
|
+
error(message: string, error?: Error): void;
|
|
6
|
+
debug_log(message: string, ...args: any[]): void;
|
|
7
|
+
warn(message: string, ...args: any[]): void;
|
|
8
|
+
}
|
|
9
|
+
export declare const logger: Logger;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logger = exports.Logger = void 0;
|
|
4
|
+
class Logger {
|
|
5
|
+
constructor(debug = false) {
|
|
6
|
+
this.debug = debug;
|
|
7
|
+
}
|
|
8
|
+
info(message, ...args) {
|
|
9
|
+
console.log(`[INFO] ${message}`, ...args);
|
|
10
|
+
}
|
|
11
|
+
error(message, error) {
|
|
12
|
+
console.error(`[ERROR] ${message}`, error);
|
|
13
|
+
}
|
|
14
|
+
debug_log(message, ...args) {
|
|
15
|
+
if (this.debug) {
|
|
16
|
+
console.log(`[DEBUG] ${message}`, ...args);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
warn(message, ...args) {
|
|
20
|
+
console.warn(`[WARN] ${message}`, ...args);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.Logger = Logger;
|
|
24
|
+
exports.logger = new Logger();
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.ChatbotWidget = void 0;
|
|
37
|
+
const react_1 = __importStar(require("react"));
|
|
38
|
+
const lucide_react_1 = require("lucide-react");
|
|
39
|
+
const ChatbotWidget = ({ fullScreen = false }) => {
|
|
40
|
+
const [isOpen, setIsOpen] = (0, react_1.useState)(fullScreen);
|
|
41
|
+
const [messages, setMessages] = (0, react_1.useState)([
|
|
42
|
+
{
|
|
43
|
+
id: 1,
|
|
44
|
+
type: 'bot',
|
|
45
|
+
text: 'नमस्ते! 👋 मैं आपके बिजनेस के बारे में सवालों का जवाब दे सकता हूँ।'
|
|
46
|
+
}
|
|
47
|
+
]);
|
|
48
|
+
const [input, setInput] = (0, react_1.useState)('');
|
|
49
|
+
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
50
|
+
const messagesEndRef = (0, react_1.useRef)(null);
|
|
51
|
+
// Auto-scroll to bottom
|
|
52
|
+
(0, react_1.useEffect)(() => {
|
|
53
|
+
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
|
|
54
|
+
}, [messages]);
|
|
55
|
+
const handleSend = async () => {
|
|
56
|
+
if (!input.trim() || loading)
|
|
57
|
+
return;
|
|
58
|
+
// Add user message
|
|
59
|
+
const userMessage = {
|
|
60
|
+
id: messages.length + 1,
|
|
61
|
+
type: 'user',
|
|
62
|
+
text: input
|
|
63
|
+
};
|
|
64
|
+
setMessages(prev => [...prev, userMessage]);
|
|
65
|
+
const currentInput = input;
|
|
66
|
+
setInput('');
|
|
67
|
+
setLoading(true);
|
|
68
|
+
try {
|
|
69
|
+
// Call backend API
|
|
70
|
+
const response = await fetch('/api/chatbot/query', {
|
|
71
|
+
method: 'POST',
|
|
72
|
+
headers: {
|
|
73
|
+
'Content-Type': 'application/json',
|
|
74
|
+
},
|
|
75
|
+
body: JSON.stringify({ query: currentInput })
|
|
76
|
+
});
|
|
77
|
+
if (!response.ok) {
|
|
78
|
+
throw new Error('API request failed');
|
|
79
|
+
}
|
|
80
|
+
const data = await response.json();
|
|
81
|
+
const botMessage = {
|
|
82
|
+
id: messages.length + 2,
|
|
83
|
+
type: 'bot',
|
|
84
|
+
text: data.success ? data.answer : 'Sorry, I could not process your query.'
|
|
85
|
+
};
|
|
86
|
+
setMessages(prev => [...prev, botMessage]);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
console.error('Chatbot error:', error);
|
|
90
|
+
const errorMessage = {
|
|
91
|
+
id: messages.length + 2,
|
|
92
|
+
type: 'bot',
|
|
93
|
+
text: '❌ Sorry, कुछ गड़बड़ी हुई। Please try again.'
|
|
94
|
+
};
|
|
95
|
+
setMessages(prev => [...prev, errorMessage]);
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
setLoading(false);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
// Floating button view
|
|
102
|
+
if (!fullScreen && !isOpen) {
|
|
103
|
+
return (react_1.default.createElement("button", { onClick: () => setIsOpen(true), style: {
|
|
104
|
+
position: 'fixed',
|
|
105
|
+
bottom: '20px',
|
|
106
|
+
right: '20px',
|
|
107
|
+
width: '60px',
|
|
108
|
+
height: '60px',
|
|
109
|
+
borderRadius: '50%',
|
|
110
|
+
background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
|
|
111
|
+
border: 'none',
|
|
112
|
+
cursor: 'pointer',
|
|
113
|
+
display: 'flex',
|
|
114
|
+
alignItems: 'center',
|
|
115
|
+
justifyContent: 'center',
|
|
116
|
+
color: 'white',
|
|
117
|
+
boxShadow: '0 4px 12px rgba(102, 126, 234, 0.4)',
|
|
118
|
+
zIndex: 9999,
|
|
119
|
+
transition: 'transform 0.2s'
|
|
120
|
+
}, onMouseOver: (e) => e.currentTarget.style.transform = 'scale(1.1)', onMouseOut: (e) => e.currentTarget.style.transform = 'scale(1)' },
|
|
121
|
+
react_1.default.createElement(lucide_react_1.MessageCircle, { size: 28 })));
|
|
122
|
+
}
|
|
123
|
+
// Chat box view
|
|
124
|
+
return (react_1.default.createElement("div", { style: {
|
|
125
|
+
position: 'fixed',
|
|
126
|
+
bottom: fullScreen ? 0 : '20px',
|
|
127
|
+
right: fullScreen ? 0 : '20px',
|
|
128
|
+
width: fullScreen ? '100vw' : '400px',
|
|
129
|
+
height: fullScreen ? '100vh' : '600px',
|
|
130
|
+
background: 'white',
|
|
131
|
+
borderRadius: fullScreen ? 0 : '12px',
|
|
132
|
+
boxShadow: '0 5px 40px rgba(0, 0, 0, 0.16)',
|
|
133
|
+
display: 'flex',
|
|
134
|
+
flexDirection: 'column',
|
|
135
|
+
zIndex: 9999,
|
|
136
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
|
|
137
|
+
} },
|
|
138
|
+
react_1.default.createElement("div", { style: {
|
|
139
|
+
background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
|
|
140
|
+
color: 'white',
|
|
141
|
+
padding: '16px',
|
|
142
|
+
borderRadius: fullScreen ? 0 : '12px 12px 0 0',
|
|
143
|
+
display: 'flex',
|
|
144
|
+
justifyContent: 'space-between',
|
|
145
|
+
alignItems: 'center'
|
|
146
|
+
} },
|
|
147
|
+
react_1.default.createElement("h3", { style: { margin: 0, fontSize: '16px' } }, "\uD83E\uDD16 AI Assistant"),
|
|
148
|
+
!fullScreen && (react_1.default.createElement("button", { onClick: () => setIsOpen(false), style: {
|
|
149
|
+
background: 'none',
|
|
150
|
+
border: 'none',
|
|
151
|
+
color: 'white',
|
|
152
|
+
cursor: 'pointer',
|
|
153
|
+
display: 'flex',
|
|
154
|
+
alignItems: 'center',
|
|
155
|
+
justifyContent: 'center',
|
|
156
|
+
padding: '4px'
|
|
157
|
+
} },
|
|
158
|
+
react_1.default.createElement(lucide_react_1.X, { size: 20 })))),
|
|
159
|
+
react_1.default.createElement("div", { style: {
|
|
160
|
+
flex: 1,
|
|
161
|
+
overflowY: 'auto',
|
|
162
|
+
padding: '16px',
|
|
163
|
+
display: 'flex',
|
|
164
|
+
flexDirection: 'column',
|
|
165
|
+
gap: '12px',
|
|
166
|
+
background: '#f9f9f9'
|
|
167
|
+
} },
|
|
168
|
+
messages.map(msg => (react_1.default.createElement("div", { key: msg.id, style: {
|
|
169
|
+
maxWidth: '80%',
|
|
170
|
+
padding: '10px 14px',
|
|
171
|
+
borderRadius: '8px',
|
|
172
|
+
alignSelf: msg.type === 'user' ? 'flex-end' : 'flex-start',
|
|
173
|
+
background: msg.type === 'user' ? '#667eea' : 'white',
|
|
174
|
+
color: msg.type === 'user' ? 'white' : '#333',
|
|
175
|
+
boxShadow: '0 2px 4px rgba(0,0,0,0.1)',
|
|
176
|
+
wordWrap: 'break-word',
|
|
177
|
+
animation: 'fadeIn 0.3s ease'
|
|
178
|
+
} }, msg.text))),
|
|
179
|
+
loading && (react_1.default.createElement("div", { style: {
|
|
180
|
+
alignSelf: 'flex-start',
|
|
181
|
+
fontStyle: 'italic',
|
|
182
|
+
color: '#999',
|
|
183
|
+
padding: '8px'
|
|
184
|
+
} }, "Typing...")),
|
|
185
|
+
react_1.default.createElement("div", { ref: messagesEndRef })),
|
|
186
|
+
react_1.default.createElement("div", { style: {
|
|
187
|
+
padding: '12px',
|
|
188
|
+
borderTop: '1px solid #eee',
|
|
189
|
+
display: 'flex',
|
|
190
|
+
gap: '8px',
|
|
191
|
+
background: 'white',
|
|
192
|
+
borderRadius: fullScreen ? 0 : '0 0 12px 12px'
|
|
193
|
+
} },
|
|
194
|
+
react_1.default.createElement("input", { type: "text", value: input, onChange: (e) => setInput(e.target.value), onKeyPress: (e) => e.key === 'Enter' && handleSend(), placeholder: "\u0905\u092A\u0928\u093E \u0938\u0935\u093E\u0932 \u092A\u0942\u091B\u094B...", disabled: loading, style: {
|
|
195
|
+
flex: 1,
|
|
196
|
+
padding: '10px 16px',
|
|
197
|
+
border: '1px solid #ddd',
|
|
198
|
+
borderRadius: '20px',
|
|
199
|
+
outline: 'none',
|
|
200
|
+
fontSize: '14px',
|
|
201
|
+
transition: 'border-color 0.2s'
|
|
202
|
+
}, onFocus: (e) => e.currentTarget.style.borderColor = '#667eea', onBlur: (e) => e.currentTarget.style.borderColor = '#ddd' }),
|
|
203
|
+
react_1.default.createElement("button", { onClick: handleSend, disabled: loading || !input.trim(), style: {
|
|
204
|
+
width: '40px',
|
|
205
|
+
height: '40px',
|
|
206
|
+
borderRadius: '50%',
|
|
207
|
+
background: loading || !input.trim() ? '#ccc' : '#667eea',
|
|
208
|
+
border: 'none',
|
|
209
|
+
color: 'white',
|
|
210
|
+
cursor: loading || !input.trim() ? 'not-allowed' : 'pointer',
|
|
211
|
+
display: 'flex',
|
|
212
|
+
alignItems: 'center',
|
|
213
|
+
justifyContent: 'center',
|
|
214
|
+
transition: 'background 0.2s'
|
|
215
|
+
} },
|
|
216
|
+
react_1.default.createElement(lucide_react_1.Send, { size: 18 })))));
|
|
217
|
+
};
|
|
218
|
+
exports.ChatbotWidget = ChatbotWidget;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ChatbotWidget } from './ChatbotWidget';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChatbotWidget = void 0;
|
|
4
|
+
var ChatbotWidget_1 = require("./ChatbotWidget");
|
|
5
|
+
Object.defineProperty(exports, "ChatbotWidget", { enumerable: true, get: function () { return ChatbotWidget_1.ChatbotWidget; } });
|
package/package.json
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "agenticaichat",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "AI-powered chatbot for business analytics with natural language database queries",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./widget": {
|
|
14
|
+
"types": "./dist/widget/index.d.ts",
|
|
15
|
+
"import": "./dist/widget/index.js",
|
|
16
|
+
"require": "./dist/widget/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./server": {
|
|
19
|
+
"types": "./dist/core/index.d.ts",
|
|
20
|
+
"import": "./dist/core/index.js",
|
|
21
|
+
"require": "./dist/core/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"bin": {
|
|
25
|
+
"agenticai-setup": "./bin/cli.js"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"bin",
|
|
30
|
+
"templates"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc",
|
|
34
|
+
"dev": "tsc --watch",
|
|
35
|
+
"clean": "rm -rf dist",
|
|
36
|
+
"prebuild": "npm run clean",
|
|
37
|
+
"test:engine": "ts-node tests/test.ts"
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"ai",
|
|
41
|
+
"chatbot",
|
|
42
|
+
"analytics",
|
|
43
|
+
"database",
|
|
44
|
+
"nl-to-sql",
|
|
45
|
+
"openai",
|
|
46
|
+
"nextjs",
|
|
47
|
+
"react",
|
|
48
|
+
"typescript",
|
|
49
|
+
"business-intelligence"
|
|
50
|
+
],
|
|
51
|
+
"author": "Bhaviraj",
|
|
52
|
+
"license": "MIT",
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "https://github.com/Bhaviraj2004/agenticaichat.git"
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"axios": "^1.13.2",
|
|
59
|
+
"dotenv": "^17.2.3",
|
|
60
|
+
"lucide-react": "^0.559.0",
|
|
61
|
+
"mongodb": "^7.0.0",
|
|
62
|
+
"mysql2": "^3.15.3",
|
|
63
|
+
"openai": "^6.10.0",
|
|
64
|
+
"pg": "^8.16.3",
|
|
65
|
+
"react": ">=18.0.0",
|
|
66
|
+
"react-dom": ">=18.0.0"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@types/inquirer": "^9.0.0",
|
|
70
|
+
"@types/node": "^20.10.0",
|
|
71
|
+
"@types/pg": "^8.15.6",
|
|
72
|
+
"@types/react": "^18.2.0",
|
|
73
|
+
"@types/react-dom": "^18.2.0",
|
|
74
|
+
"chalk": "^4.1.2",
|
|
75
|
+
"commander": "^11.1.0",
|
|
76
|
+
"inquirer": "^8.2.6",
|
|
77
|
+
"ora": "^5.4.1",
|
|
78
|
+
"ts-node": "^10.9.2",
|
|
79
|
+
"typescript": "^5.3.0"
|
|
80
|
+
},
|
|
81
|
+
"peerDependencies": {
|
|
82
|
+
"next": ">=13.0.0",
|
|
83
|
+
"react": ">=18.0.0",
|
|
84
|
+
"react-dom": ">=18.0.0"
|
|
85
|
+
},
|
|
86
|
+
"engines": {
|
|
87
|
+
"node": ">=18.0.0",
|
|
88
|
+
"npm": ">=9.0.0"
|
|
89
|
+
}
|
|
90
|
+
}
|