agenticaichat 1.0.6 → 1.0.7
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 +78 -241
- package/bin/cli.js +9 -45
- package/dist/adapters/angular/index.d.ts +1 -0
- package/dist/adapters/angular/index.js +80 -0
- package/dist/adapters/next/index.d.ts +1 -0
- package/dist/adapters/next/index.js +50 -0
- package/dist/adapters/react/index.d.ts +1 -0
- package/dist/adapters/react/index.js +8 -0
- package/dist/adapters/vue/index.d.ts +1 -0
- package/dist/adapters/vue/index.js +89 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +3 -5
- package/package.json +25 -11
- package/dist/adapters/angular.d.ts +0 -9
- package/dist/adapters/angular.js +0 -6
- package/dist/adapters/react.d.ts +0 -1
- package/dist/adapters/react.js +0 -8
- package/dist/adapters/vue.d.ts +0 -9
- package/dist/adapters/vue.js +0 -6
- package/dist/web-component/AgenticAIChatbot.js +0 -219
- package/dist/web-component/index.js +0 -2
- package/src/web-component/AgenticAIChatbot.js +0 -219
- package/src/web-component/index.js +0 -2
- /package/dist/{widget → shared}/ChatbotWidget.d.ts +0 -0
- /package/dist/{widget → shared}/ChatbotWidget.js +0 -0
- /package/dist/{widget → shared}/index.d.ts +0 -0
- /package/dist/{widget → shared}/index.js +0 -0
package/README.md
CHANGED
|
@@ -1,291 +1,128 @@
|
|
|
1
1
|
# AgenticAIChat
|
|
2
|
-
AI
|
|
2
|
+
AI chatbot for business data. Ask questions in normal English or Hindi.
|
|
3
3
|
|
|
4
|
-
##
|
|
5
|
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
- Configuration files generated for you (`.env.chatbot`, `chatbot-config.json`)
|
|
12
|
-
- Fully typed TypeScript package
|
|
13
|
-
|
|
14
|
-
## Requirements
|
|
4
|
+
## What it does
|
|
5
|
+
- Quick 5-minute setup
|
|
6
|
+
- Ask questions in English or Hindi
|
|
7
|
+
- Works with PostgreSQL, MySQL, SQLite, Turso, MongoDB
|
|
8
|
+
- Ready for React, Angular, Vue, Next.js
|
|
9
|
+
- Same design in all frameworks
|
|
10
|
+
- Auto-creates config files
|
|
15
11
|
|
|
12
|
+
## What you need
|
|
16
13
|
- Node.js 18+ and npm 9+
|
|
17
|
-
- React 18+
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
- React 18+ for React/Next.js apps
|
|
15
|
+
- Angular 12+ for Angular apps
|
|
16
|
+
- Vue 3+ for Vue apps
|
|
20
17
|
|
|
21
|
-
|
|
18
|
+
## Install and Setup
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
### Step 1: Install
|
|
21
|
+
```bash
|
|
22
|
+
npm install agenticaichat
|
|
26
23
|
```
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
import 'agenticaichat/web-component';
|
|
25
|
+
### Step 2: Setup
|
|
26
|
+
Run this command:
|
|
27
|
+
```bash
|
|
28
|
+
npx agenticai-setup
|
|
33
29
|
```
|
|
34
30
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
AgenticAIChat offers two ways to integrate the chatbot:
|
|
31
|
+
The setup will ask:
|
|
32
|
+
- Your database details (type, host, user, password)
|
|
33
|
+
- Your AI API key (OpenAI, Google, etc.)
|
|
34
|
+
- Which framework you use (React, Angular, Vue, Next.js)
|
|
40
35
|
|
|
41
|
-
|
|
42
|
-
- Fully designed UI with animations and chat history
|
|
43
|
-
- Best for dashboards and full-page experiences
|
|
44
|
-
- Uses React internally
|
|
45
|
-
- Ideal for Next.js apps
|
|
36
|
+
It will create files and tell you what to do next.
|
|
46
37
|
|
|
47
|
-
|
|
48
|
-
- Works in React, Angular, Vue, Next.js, Svelte, plain HTML
|
|
49
|
-
- No framework dependencies
|
|
50
|
-
- Perfect for embedding on external websites
|
|
51
|
-
- Lightweight and self-contained
|
|
38
|
+
## How to Use in Different Frameworks
|
|
52
39
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
Add the widget to any page or component:
|
|
40
|
+
### Next.js (Easiest)
|
|
41
|
+
Setup creates:
|
|
42
|
+
- API file: `app/api/chatbot/route.ts`
|
|
43
|
+
- Chat page: `app/chat/page.tsx`
|
|
58
44
|
|
|
45
|
+
Use in your code:
|
|
59
46
|
```tsx
|
|
60
|
-
// app/dashboard/page.tsx
|
|
61
47
|
import { ChatbotWidget } from 'agenticaichat';
|
|
62
48
|
|
|
63
|
-
export default function
|
|
64
|
-
return
|
|
65
|
-
<div>
|
|
66
|
-
<h1>Dashboard</h1>
|
|
67
|
-
<ChatbotWidget />
|
|
68
|
-
</div>
|
|
69
|
-
);
|
|
49
|
+
export default function MyPage() {
|
|
50
|
+
return <ChatbotWidget />;
|
|
70
51
|
}
|
|
71
52
|
```
|
|
72
53
|
|
|
73
|
-
|
|
74
|
-
|
|
54
|
+
### React (Vite, CRA, etc.)
|
|
55
|
+
Setup gives you the widget. Use it:
|
|
75
56
|
```tsx
|
|
76
|
-
// app/chat/page.tsx
|
|
77
57
|
import { ChatbotWidget } from 'agenticaichat';
|
|
78
58
|
|
|
79
|
-
|
|
80
|
-
return <ChatbotWidget
|
|
81
|
-
}
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
Start your Next.js app:
|
|
85
|
-
|
|
86
|
-
```bash
|
|
87
|
-
npm run dev
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
## Setting up the Backend API
|
|
91
|
-
|
|
92
|
-
For all frameworks, you need a backend endpoint that handles chatbot queries. The setup wizard generates configuration files, but you must implement the API route yourself unless using Next.js.
|
|
93
|
-
|
|
94
|
-
1. Run the setup wizard to generate `.env.chatbot` and `chatbot-config.json`:
|
|
95
|
-
|
|
96
|
-
```bash
|
|
97
|
-
npx agenticai-setup
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
2. Create an HTTP POST endpoint at `/api/chatbot/query` (or any path you choose).
|
|
101
|
-
|
|
102
|
-
Use the template from `templates/api-route.template.ts` as a guide. Load environment variables from `.env.chatbot` and use the `ChatbotEngine` from `agenticaichat/core`.
|
|
103
|
-
|
|
104
|
-
Example (Node.js/Express):
|
|
105
|
-
|
|
106
|
-
```javascript
|
|
107
|
-
const express = require('express');
|
|
108
|
-
const { ChatbotEngine } = require('agenticaichat/core');
|
|
109
|
-
require('dotenv').config({ path: '.env.chatbot' });
|
|
110
|
-
|
|
111
|
-
const app = express();
|
|
112
|
-
app.use(express.json());
|
|
113
|
-
|
|
114
|
-
app.post('/api/chatbot/query', async (req, res) => {
|
|
115
|
-
const { query } = req.body;
|
|
116
|
-
const engine = new ChatbotEngine();
|
|
117
|
-
try {
|
|
118
|
-
const result = await engine.processQuery(query);
|
|
119
|
-
res.json(result);
|
|
120
|
-
} catch (error) {
|
|
121
|
-
res.status(500).json({ error: error.message });
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
app.listen(3000);
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
For Next.js, the wizard generates this automatically.
|
|
129
|
-
|
|
130
|
-
**Important: Enable CORS**
|
|
131
|
-
If your frontend and backend are on different domains or ports, enable CORS in your backend:
|
|
132
|
-
```
|
|
133
|
-
Access-Control-Allow-Origin: *
|
|
134
|
-
```
|
|
135
|
-
Or restrict to your specific domain for security.
|
|
136
|
-
|
|
137
|
-
## Setup for Angular
|
|
138
|
-
|
|
139
|
-
**Recommended:** Use the universal Web Component for easiest integration. See the Web Component section above.
|
|
140
|
-
|
|
141
|
-
If you prefer a custom Angular component:
|
|
142
|
-
|
|
143
|
-
1. Install the package and run setup:
|
|
144
|
-
|
|
145
|
-
```bash
|
|
146
|
-
npm install agenticaichat
|
|
147
|
-
npx agenticai-setup
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
2. Set up the backend API as described above (e.g., using Express or your preferred Node.js framework).
|
|
151
|
-
|
|
152
|
-
3. In your Angular app, create a chatbot component:
|
|
153
|
-
|
|
154
|
-
```typescript
|
|
155
|
-
// chatbot.component.ts
|
|
156
|
-
import { Component } from '@angular/core';
|
|
157
|
-
import { HttpClient } from '@angular/common/http';
|
|
158
|
-
import { AngularChatRequest, AngularChatResponse } from 'agenticaichat/angular';
|
|
159
|
-
|
|
160
|
-
@Component({
|
|
161
|
-
selector: 'app-chatbot',
|
|
162
|
-
template: `
|
|
163
|
-
<div>
|
|
164
|
-
<input [(ngModel)]="query" placeholder="Ask a question..." />
|
|
165
|
-
<button (click)="ask()">Ask</button>
|
|
166
|
-
<div *ngIf="response">{{ response.answer }}</div>
|
|
167
|
-
</div>
|
|
168
|
-
`
|
|
169
|
-
})
|
|
170
|
-
export class ChatbotComponent {
|
|
171
|
-
query = '';
|
|
172
|
-
response: AngularChatResponse | null = null;
|
|
173
|
-
|
|
174
|
-
constructor(private http: HttpClient) {}
|
|
175
|
-
|
|
176
|
-
ask() {
|
|
177
|
-
const request: AngularChatRequest = { query: this.query };
|
|
178
|
-
this.http.post<AngularChatResponse>('/api/chatbot/query', request)
|
|
179
|
-
.subscribe(res => this.response = res);
|
|
180
|
-
}
|
|
59
|
+
function MyApp() {
|
|
60
|
+
return <ChatbotWidget />;
|
|
181
61
|
}
|
|
182
62
|
```
|
|
183
63
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
**Recommended:** Use the universal Web Component for easiest integration. See the Web Component section above.
|
|
189
|
-
|
|
190
|
-
If you prefer a custom Vue component:
|
|
191
|
-
|
|
192
|
-
1. Install the package and run setup:
|
|
64
|
+
### Angular
|
|
65
|
+
Setup creates:
|
|
66
|
+
- Service file: `src/app/services/chatbot.service.ts`
|
|
67
|
+
- Component file: `src/app/components/chatbot.component.ts`
|
|
193
68
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
69
|
+
Add to your HTML:
|
|
70
|
+
```html
|
|
71
|
+
<app-chatbot></app-chatbot>
|
|
197
72
|
```
|
|
198
73
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
74
|
+
### Vue
|
|
75
|
+
Setup creates:
|
|
76
|
+
- Composable file: `src/composables/useChatbot.js`
|
|
77
|
+
- Component file: `src/components/Chatbot.vue`
|
|
202
78
|
|
|
79
|
+
Use in your template:
|
|
203
80
|
```vue
|
|
204
|
-
|
|
205
|
-
<template>
|
|
206
|
-
<div>
|
|
207
|
-
<input v-model="query" placeholder="Ask a question..." />
|
|
208
|
-
<button @click="ask">Ask</button>
|
|
209
|
-
<div v-if="response">{{ response.answer }}</div>
|
|
210
|
-
</div>
|
|
211
|
-
</template>
|
|
212
|
-
|
|
213
|
-
<script setup lang="ts">
|
|
214
|
-
import { ref } from 'vue';
|
|
215
|
-
import { VueChatRequest, VueChatResponse } from 'agenticaichat/vue';
|
|
216
|
-
|
|
217
|
-
const query = ref('');
|
|
218
|
-
const response = ref<VueChatResponse | null>(null);
|
|
219
|
-
|
|
220
|
-
const ask = async () => {
|
|
221
|
-
const request: VueChatRequest = { query: query.value };
|
|
222
|
-
const res = await fetch('/api/chatbot/query', {
|
|
223
|
-
method: 'POST',
|
|
224
|
-
headers: { 'Content-Type': 'application/json' },
|
|
225
|
-
body: JSON.stringify(request)
|
|
226
|
-
});
|
|
227
|
-
response.value = await res.json();
|
|
228
|
-
};
|
|
229
|
-
</script>
|
|
81
|
+
<Chatbot />
|
|
230
82
|
```
|
|
231
83
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
-
|
|
237
|
-
-
|
|
238
|
-
-
|
|
239
|
-
- Configure CORS/auth so the widget can call your endpoint from the browser.
|
|
240
|
-
|
|
241
|
-
Frontend usage stays the same:
|
|
242
|
-
|
|
243
|
-
```tsx
|
|
244
|
-
import { ChatbotWidget } from 'agenticaichat';
|
|
245
|
-
|
|
246
|
-
export default function Page() {
|
|
247
|
-
return <ChatbotWidget apiPath="/api/chatbot/query" />;
|
|
248
|
-
}
|
|
249
|
-
```
|
|
84
|
+
## Same Design Everywhere
|
|
85
|
+
All frameworks use the same chat design:
|
|
86
|
+
- Chat bubble
|
|
87
|
+
- Message list
|
|
88
|
+
- Input box
|
|
89
|
+
- Send button
|
|
90
|
+
- Same colors and style
|
|
250
91
|
|
|
251
|
-
##
|
|
92
|
+
## Files Created
|
|
93
|
+
- `.env.chatbot` - Your secret keys
|
|
94
|
+
- `chatbot-config.json` - Settings
|
|
95
|
+
- `.gitignore` - Keeps secrets safe
|
|
252
96
|
|
|
253
|
-
|
|
254
|
-
-
|
|
255
|
-
-
|
|
97
|
+
## Need Help?
|
|
98
|
+
- Check the setup output for next steps
|
|
99
|
+
- All frameworks work the same way
|
|
100
|
+
- Design looks identical everywhere
|
|
256
101
|
|
|
257
|
-
##
|
|
102
|
+
## How It Works
|
|
258
103
|
|
|
259
104
|
```
|
|
260
|
-
|
|
105
|
+
Your App (React/Angular/Vue/Next.js)
|
|
261
106
|
|
|
|
262
107
|
V
|
|
263
|
-
|
|
108
|
+
Framework Adapter (auto-loaded)
|
|
109
|
+
|
|
|
110
|
+
V
|
|
111
|
+
ChatbotWidget (same design)
|
|
264
112
|
|
|
|
265
113
|
V
|
|
266
114
|
Your Backend API (/api/chatbot/query)
|
|
267
115
|
|
|
|
268
116
|
V
|
|
269
|
-
ChatbotEngine →
|
|
117
|
+
ChatbotEngine → Database → AI
|
|
270
118
|
```
|
|
271
119
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
## Troubleshooting
|
|
120
|
+
Each framework gets its own adapter that loads the same ChatbotWidget.
|
|
275
121
|
|
|
276
|
-
|
|
277
|
-
-
|
|
278
|
-
-
|
|
279
|
-
|
|
280
|
-
## Contributing
|
|
281
|
-
|
|
282
|
-
Contributions are welcome. Please open an issue or pull request with details and reproduction steps.
|
|
122
|
+
## Problems?
|
|
123
|
+
- Run `npx agenticai-setup` again
|
|
124
|
+
- Check that your framework is supported
|
|
125
|
+
- Make sure Node.js 18+ is installed
|
|
283
126
|
|
|
284
127
|
## License
|
|
285
|
-
|
|
286
|
-
MIT License
|
|
287
|
-
|
|
288
|
-
## Support
|
|
289
|
-
|
|
290
|
-
- GitHub: [Issues](https://github.com/Bhaviraj2004/agenticaichat/issues)
|
|
291
|
-
- Email: bhaviraj001@gmail.com
|
|
128
|
+
MIT License
|
package/bin/cli.js
CHANGED
|
@@ -384,51 +384,15 @@ CHATBOT_ENABLED=true
|
|
|
384
384
|
spinner.text = 'Created chatbot-config.json';
|
|
385
385
|
|
|
386
386
|
// Create frontend scaffolding based on selected framework
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
path.join(__dirname, '..', 'templates', 'api-route.txt'),
|
|
397
|
-
'utf8'
|
|
398
|
-
);
|
|
399
|
-
|
|
400
|
-
const apiPath = path.join(apiDir, 'route.ts');
|
|
401
|
-
fs.writeFileSync(apiPath, apiTemplate);
|
|
402
|
-
spinner.text = 'Created API route: app/api/chatbot/query/route.ts';
|
|
403
|
-
} catch (error) {
|
|
404
|
-
spinner.warn('Could not create API route automatically');
|
|
405
|
-
console.log(chalk.yellow('\nℹ️ You can manually create the API route later'));
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
try {
|
|
409
|
-
const chatDir = path.join(process.cwd(), 'app', 'chat');
|
|
410
|
-
if (!fs.existsSync(chatDir)) {
|
|
411
|
-
fs.mkdirSync(chatDir, { recursive: true });
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
const chatTemplate = fs.readFileSync(
|
|
415
|
-
path.join(__dirname, '..', 'templates', 'chat-page.txt'),
|
|
416
|
-
'utf8'
|
|
417
|
-
);
|
|
418
|
-
|
|
419
|
-
const chatPath = path.join(chatDir, 'page.tsx');
|
|
420
|
-
fs.writeFileSync(chatPath, chatTemplate);
|
|
421
|
-
spinner.text = 'Created chat page: app/chat/page.tsx';
|
|
422
|
-
} catch (error) {
|
|
423
|
-
spinner.warn('Could not create chat page automatically');
|
|
424
|
-
console.log(chalk.yellow('\nℹ️ You can manually create the chat page later'));
|
|
425
|
-
}
|
|
426
|
-
} else {
|
|
427
|
-
// Non-React frameworks: keep backend-only scaffolding, user builds UI
|
|
428
|
-
spinner.text = 'Backend configured (HTTP API). Frontend adapter to be implemented in your framework.';
|
|
429
|
-
console.log(chalk.yellow('\nℹ️ Frontend note:'));
|
|
430
|
-
console.log(chalk.gray(' - Use the /api/chatbot/query HTTP endpoint from your Angular/Vue/other component.'));
|
|
431
|
-
console.log(chalk.gray(' - See README for framework-specific adapter guidance.\n'));
|
|
387
|
+
try {
|
|
388
|
+
const adapterPath = `./adapters/${frontendAnswers.framework}/index.js`;
|
|
389
|
+
const adapter = require(path.join(__dirname, '..', 'dist', 'adapters', frontendAnswers.framework, 'index.js'));
|
|
390
|
+
const setupFunctionName = `setup${frontendAnswers.framework.charAt(0).toUpperCase() + frontendAnswers.framework.slice(1)}`;
|
|
391
|
+
await adapter[setupFunctionName]();
|
|
392
|
+
spinner.text = `${frontendAnswers.framework} adapter setup complete`;
|
|
393
|
+
} catch (error) {
|
|
394
|
+
spinner.warn(`Could not load ${frontendAnswers.framework} adapter: ${error.message}`);
|
|
395
|
+
console.log(chalk.yellow('\nℹ️ You can manually set up the frontend integration later'));
|
|
432
396
|
}
|
|
433
397
|
|
|
434
398
|
// Update .gitignore
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function setupAngular(): Promise<void>;
|
|
@@ -0,0 +1,80 @@
|
|
|
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.setupAngular = setupAngular;
|
|
7
|
+
// Angular Adapter - Generate service and component
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
async function setupAngular() {
|
|
11
|
+
const cwd = process.cwd();
|
|
12
|
+
// Generate service
|
|
13
|
+
const serviceDir = path_1.default.join(cwd, 'src', 'app', 'services');
|
|
14
|
+
const serviceFile = path_1.default.join(serviceDir, 'chatbot.service.ts');
|
|
15
|
+
if (!fs_1.default.existsSync(serviceDir)) {
|
|
16
|
+
fs_1.default.mkdirSync(serviceDir, { recursive: true });
|
|
17
|
+
}
|
|
18
|
+
const serviceContent = `import { Injectable } from '@angular/core';
|
|
19
|
+
import { HttpClient } from '@angular/common/http';
|
|
20
|
+
import { Observable } from 'rxjs';
|
|
21
|
+
|
|
22
|
+
@Injectable({
|
|
23
|
+
providedIn: 'root'
|
|
24
|
+
})
|
|
25
|
+
export class ChatbotService {
|
|
26
|
+
constructor(private http: HttpClient) {}
|
|
27
|
+
|
|
28
|
+
sendQuery(query: string): Observable<any> {
|
|
29
|
+
return this.http.post('/api/chatbot/query', { query });
|
|
30
|
+
}
|
|
31
|
+
}`;
|
|
32
|
+
fs_1.default.writeFileSync(serviceFile, serviceContent);
|
|
33
|
+
// Generate component
|
|
34
|
+
const componentDir = path_1.default.join(cwd, 'src', 'app', 'components', 'chatbot');
|
|
35
|
+
const componentFile = path_1.default.join(componentDir, 'chatbot.component.ts');
|
|
36
|
+
const templateFile = path_1.default.join(componentDir, 'chatbot.component.html');
|
|
37
|
+
if (!fs_1.default.existsSync(componentDir)) {
|
|
38
|
+
fs_1.default.mkdirSync(componentDir, { recursive: true });
|
|
39
|
+
}
|
|
40
|
+
const componentContent = `import { Component } from '@angular/core';
|
|
41
|
+
import { ChatbotService } from '../../services/chatbot.service';
|
|
42
|
+
|
|
43
|
+
@Component({
|
|
44
|
+
selector: 'app-chatbot',
|
|
45
|
+
templateUrl: './chatbot.component.html'
|
|
46
|
+
})
|
|
47
|
+
export class ChatbotComponent {
|
|
48
|
+
messages: any[] = [];
|
|
49
|
+
newMessage = '';
|
|
50
|
+
|
|
51
|
+
constructor(private chatbotService: ChatbotService) {}
|
|
52
|
+
|
|
53
|
+
sendMessage() {
|
|
54
|
+
if (!this.newMessage.trim()) return;
|
|
55
|
+
|
|
56
|
+
this.messages.push({ text: this.newMessage, sender: 'user' });
|
|
57
|
+
this.chatbotService.sendQuery(this.newMessage).subscribe(
|
|
58
|
+
response => {
|
|
59
|
+
this.messages.push({ text: response.answer, sender: 'bot' });
|
|
60
|
+
},
|
|
61
|
+
error => {
|
|
62
|
+
this.messages.push({ text: 'Error: ' + error.message, sender: 'bot' });
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
this.newMessage = '';
|
|
66
|
+
}
|
|
67
|
+
}`;
|
|
68
|
+
const templateContent = `<div class="chat-container">
|
|
69
|
+
<div class="chat-messages">
|
|
70
|
+
<div *ngFor="let message of messages" [class]="message.sender">
|
|
71
|
+
{{ message.text }}
|
|
72
|
+
</div>
|
|
73
|
+
</div>
|
|
74
|
+
<input [(ngModel)]="newMessage" (keyup.enter)="sendMessage()" placeholder="Ask a question..." />
|
|
75
|
+
<button (click)="sendMessage()">Send</button>
|
|
76
|
+
</div>`;
|
|
77
|
+
fs_1.default.writeFileSync(componentFile, componentContent);
|
|
78
|
+
fs_1.default.writeFileSync(templateFile, templateContent);
|
|
79
|
+
console.log('Angular setup complete. Service and component generated.');
|
|
80
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function setupNext(): Promise<void>;
|
|
@@ -0,0 +1,50 @@
|
|
|
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.setupNext = setupNext;
|
|
7
|
+
// Next.js Adapter - Auto-generate API route and page
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
async function setupNext() {
|
|
11
|
+
const cwd = process.cwd();
|
|
12
|
+
// Generate API route
|
|
13
|
+
const apiDir = path_1.default.join(cwd, 'app', 'api', 'chatbot');
|
|
14
|
+
const apiFile = path_1.default.join(apiDir, 'route.ts');
|
|
15
|
+
if (!fs_1.default.existsSync(apiDir)) {
|
|
16
|
+
fs_1.default.mkdirSync(apiDir, { recursive: true });
|
|
17
|
+
}
|
|
18
|
+
const apiContent = `import { ChatbotEngine } from 'agenticaichat/core';
|
|
19
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
20
|
+
|
|
21
|
+
export async function POST(request: NextRequest) {
|
|
22
|
+
try {
|
|
23
|
+
const { query } = await request.json();
|
|
24
|
+
const engine = new ChatbotEngine();
|
|
25
|
+
const result = await engine.processQuery(query);
|
|
26
|
+
return NextResponse.json(result);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
return NextResponse.json({ error: error.message }, { status: 500 });
|
|
29
|
+
}
|
|
30
|
+
}`;
|
|
31
|
+
fs_1.default.writeFileSync(apiFile, apiContent);
|
|
32
|
+
// Generate chat page
|
|
33
|
+
const chatDir = path_1.default.join(cwd, 'app', 'chat');
|
|
34
|
+
const pageFile = path_1.default.join(chatDir, 'page.tsx');
|
|
35
|
+
if (!fs_1.default.existsSync(chatDir)) {
|
|
36
|
+
fs_1.default.mkdirSync(chatDir, { recursive: true });
|
|
37
|
+
}
|
|
38
|
+
const pageContent = `import { ChatbotWidget } from 'agenticaichat';
|
|
39
|
+
|
|
40
|
+
export default function ChatPage() {
|
|
41
|
+
return (
|
|
42
|
+
<div>
|
|
43
|
+
<h1>Chat with AI</h1>
|
|
44
|
+
<ChatbotWidget />
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
}`;
|
|
48
|
+
fs_1.default.writeFileSync(pageFile, pageContent);
|
|
49
|
+
console.log('Next.js setup complete. API route and chat page generated.');
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function setupReact(): Promise<void>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// React Adapter - Direct widget usage
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.setupReact = setupReact;
|
|
5
|
+
async function setupReact() {
|
|
6
|
+
// For React frameworks, just provide usage instructions
|
|
7
|
+
console.log('React setup complete. Use: import { ChatbotWidget } from "agenticaichat";');
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function setupVue(): Promise<void>;
|
|
@@ -0,0 +1,89 @@
|
|
|
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.setupVue = setupVue;
|
|
7
|
+
// Vue Adapter - Generate composable and component
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
async function setupVue() {
|
|
11
|
+
const cwd = process.cwd();
|
|
12
|
+
// Generate composable
|
|
13
|
+
const composableDir = path_1.default.join(cwd, 'src', 'composables');
|
|
14
|
+
const composableFile = path_1.default.join(composableDir, 'useChatbot.js');
|
|
15
|
+
if (!fs_1.default.existsSync(composableDir)) {
|
|
16
|
+
fs_1.default.mkdirSync(composableDir, { recursive: true });
|
|
17
|
+
}
|
|
18
|
+
const composableContent = `import { ref } from 'vue';
|
|
19
|
+
|
|
20
|
+
export function useChatbot() {
|
|
21
|
+
const messages = ref([]);
|
|
22
|
+
const loading = ref(false);
|
|
23
|
+
|
|
24
|
+
const sendQuery = async (query) => {
|
|
25
|
+
loading.value = true;
|
|
26
|
+
messages.value.push({ text: query, sender: 'user' });
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
const response = await fetch('/api/chatbot/query', {
|
|
30
|
+
method: 'POST',
|
|
31
|
+
headers: { 'Content-Type': 'application/json' },
|
|
32
|
+
body: JSON.stringify({ query })
|
|
33
|
+
});
|
|
34
|
+
const data = await response.json();
|
|
35
|
+
messages.value.push({ text: data.answer, sender: 'bot' });
|
|
36
|
+
} catch (error) {
|
|
37
|
+
messages.value.push({ text: 'Error: ' + error.message, sender: 'bot' });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
loading.value = false;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return { messages, loading, sendQuery };
|
|
44
|
+
}`;
|
|
45
|
+
fs_1.default.writeFileSync(composableFile, composableContent);
|
|
46
|
+
// Generate component
|
|
47
|
+
const componentDir = path_1.default.join(cwd, 'src', 'components');
|
|
48
|
+
const componentFile = path_1.default.join(componentDir, 'Chatbot.vue');
|
|
49
|
+
if (!fs_1.default.existsSync(componentDir)) {
|
|
50
|
+
fs_1.default.mkdirSync(componentDir, { recursive: true });
|
|
51
|
+
}
|
|
52
|
+
const componentContent = `<template>
|
|
53
|
+
<div class="chat-container">
|
|
54
|
+
<div class="chat-messages">
|
|
55
|
+
<div v-for="message in messages" :key="message.id" :class="message.sender">
|
|
56
|
+
{{ message.text }}
|
|
57
|
+
</div>
|
|
58
|
+
<div v-if="loading" class="loading">Typing...</div>
|
|
59
|
+
</div>
|
|
60
|
+
<input v-model="newMessage" @keyup.enter="sendMessage" placeholder="Ask a question..." />
|
|
61
|
+
<button @click="sendMessage" :disabled="loading">Send</button>
|
|
62
|
+
</div>
|
|
63
|
+
</template>
|
|
64
|
+
|
|
65
|
+
<script setup>
|
|
66
|
+
import { ref } from 'vue';
|
|
67
|
+
import { useChatbot } from '../composables/useChatbot.js';
|
|
68
|
+
|
|
69
|
+
const { messages, loading, sendQuery } = useChatbot();
|
|
70
|
+
const newMessage = ref('');
|
|
71
|
+
|
|
72
|
+
const sendMessage = () => {
|
|
73
|
+
if (!newMessage.value.trim()) return;
|
|
74
|
+
sendQuery(newMessage.value);
|
|
75
|
+
newMessage.value = '';
|
|
76
|
+
};
|
|
77
|
+
</script>
|
|
78
|
+
|
|
79
|
+
<style scoped>
|
|
80
|
+
.chat-container { /* Add your styles */ }
|
|
81
|
+
.chat-messages { height: 300px; overflow-y: auto; }
|
|
82
|
+
.message { margin: 10px; padding: 10px; border-radius: 10px; }
|
|
83
|
+
.user { background: #007bff; color: white; margin-left: auto; }
|
|
84
|
+
.bot { background: #f1f1f1; }
|
|
85
|
+
.loading { font-style: italic; color: #666; }
|
|
86
|
+
</style>`;
|
|
87
|
+
fs_1.default.writeFileSync(componentFile, componentContent);
|
|
88
|
+
console.log('Vue setup complete. Composable and component generated.');
|
|
89
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export { ChatbotWidget } from './
|
|
2
|
-
export { ReactChatbotWidget } from './adapters/react';
|
|
1
|
+
export { ChatbotWidget } from './shared';
|
|
3
2
|
export { ChatbotEngine } from './core/ChatbotEngine';
|
|
4
3
|
export { EngineFactory } from './core/EngineFactory';
|
|
5
4
|
export { DatabaseEngine } from './engines/base/DatabaseEngine';
|
package/dist/index.js
CHANGED
|
@@ -14,14 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.logger = exports.Logger = exports.DeepInfraProvider = exports.TogetherAIProvider = exports.GrokProvider = exports.ClaudeProvider = exports.GeminiProvider = exports.OpenAIProvider = exports.LLMFactory = exports.MongoEngine = exports.SQLiteDialect = exports.MySQLDialect = exports.PostgresDialect = exports.NoSqlEngine = exports.SqlEngine = exports.DatabaseEngine = exports.EngineFactory = exports.ChatbotEngine = exports.
|
|
17
|
+
exports.logger = exports.Logger = exports.DeepInfraProvider = exports.TogetherAIProvider = exports.GrokProvider = exports.ClaudeProvider = exports.GeminiProvider = exports.OpenAIProvider = exports.LLMFactory = exports.MongoEngine = exports.SQLiteDialect = exports.MySQLDialect = exports.PostgresDialect = exports.NoSqlEngine = exports.SqlEngine = exports.DatabaseEngine = exports.EngineFactory = exports.ChatbotEngine = exports.ChatbotWidget = void 0;
|
|
18
18
|
// ============================================
|
|
19
19
|
// CLIENT-SIDE EXPORTS (Safe for browser)
|
|
20
20
|
// ============================================
|
|
21
|
-
var
|
|
22
|
-
Object.defineProperty(exports, "ChatbotWidget", { enumerable: true, get: function () { return
|
|
23
|
-
var react_1 = require("./adapters/react");
|
|
24
|
-
Object.defineProperty(exports, "ReactChatbotWidget", { enumerable: true, get: function () { return react_1.ReactChatbotWidget; } });
|
|
21
|
+
var shared_1 = require("./shared");
|
|
22
|
+
Object.defineProperty(exports, "ChatbotWidget", { enumerable: true, get: function () { return shared_1.ChatbotWidget; } });
|
|
25
23
|
// ============================================
|
|
26
24
|
// SERVER-SIDE EXPORTS (Node.js only)
|
|
27
25
|
// ============================================
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agenticaichat",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
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",
|
|
@@ -11,18 +11,34 @@
|
|
|
11
11
|
"require": "./dist/index.js"
|
|
12
12
|
},
|
|
13
13
|
"./widget": {
|
|
14
|
-
"types": "./dist/
|
|
15
|
-
"import": "./dist/
|
|
16
|
-
"require": "./dist/
|
|
14
|
+
"types": "./dist/shared/index.d.ts",
|
|
15
|
+
"import": "./dist/shared/index.js",
|
|
16
|
+
"require": "./dist/shared/index.js"
|
|
17
17
|
},
|
|
18
18
|
"./server": {
|
|
19
19
|
"types": "./dist/core/index.d.ts",
|
|
20
20
|
"import": "./dist/core/index.js",
|
|
21
21
|
"require": "./dist/core/index.js"
|
|
22
22
|
},
|
|
23
|
-
"./
|
|
24
|
-
"
|
|
25
|
-
"
|
|
23
|
+
"./adapters/react": {
|
|
24
|
+
"types": "./dist/adapters/react/index.d.ts",
|
|
25
|
+
"import": "./dist/adapters/react/index.js",
|
|
26
|
+
"require": "./dist/adapters/react/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./adapters/angular": {
|
|
29
|
+
"types": "./dist/adapters/angular/index.d.ts",
|
|
30
|
+
"import": "./dist/adapters/angular/index.js",
|
|
31
|
+
"require": "./dist/adapters/angular/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./adapters/vue": {
|
|
34
|
+
"types": "./dist/adapters/vue/index.d.ts",
|
|
35
|
+
"import": "./dist/adapters/vue/index.js",
|
|
36
|
+
"require": "./dist/adapters/vue/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./adapters/next": {
|
|
39
|
+
"types": "./dist/adapters/next/index.d.ts",
|
|
40
|
+
"import": "./dist/adapters/next/index.js",
|
|
41
|
+
"require": "./dist/adapters/next/index.js"
|
|
26
42
|
}
|
|
27
43
|
},
|
|
28
44
|
"bin": {
|
|
@@ -32,12 +48,10 @@
|
|
|
32
48
|
"dist",
|
|
33
49
|
"bin",
|
|
34
50
|
"templates",
|
|
35
|
-
"scripts"
|
|
36
|
-
"src/web-component"
|
|
51
|
+
"scripts"
|
|
37
52
|
],
|
|
38
53
|
"scripts": {
|
|
39
|
-
"build": "tsc
|
|
40
|
-
"build:web-component": "if not exist dist\\web-component mkdir dist\\web-component && copy src\\web-component\\* dist\\web-component\\",
|
|
54
|
+
"build": "tsc",
|
|
41
55
|
"dev": "tsc --watch",
|
|
42
56
|
"clean": "node -e \"require('fs').rmSync('dist', {recursive: true, force: true})\"",
|
|
43
57
|
"prebuild": "npm run clean",
|
package/dist/adapters/angular.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Placeholder types and helper for Angular adapters.
|
|
3
|
-
// Angular users should create their own component/service that calls the HTTP API:
|
|
4
|
-
// POST /api/chatbot/query { query: string }
|
|
5
|
-
// and handles the JSON response.
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist/adapters/react.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { ChatbotWidget as ReactChatbotWidget } from '../widget';
|
package/dist/adapters/react.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ReactChatbotWidget = void 0;
|
|
4
|
-
// Thin alias so future adapters can share a consistent naming scheme.
|
|
5
|
-
// React users should continue to import from "agenticaichat" directly,
|
|
6
|
-
// but this adapter is exposed for symmetry with Angular/Vue.
|
|
7
|
-
var widget_1 = require("../widget");
|
|
8
|
-
Object.defineProperty(exports, "ReactChatbotWidget", { enumerable: true, get: function () { return widget_1.ChatbotWidget; } });
|
package/dist/adapters/vue.d.ts
DELETED
package/dist/adapters/vue.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Placeholder types and helper for Vue adapters.
|
|
3
|
-
// Vue users should create their own component/composable that calls the HTTP API:
|
|
4
|
-
// POST /api/chatbot/query { query: string }
|
|
5
|
-
// and handles the JSON response.
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
class AgenticAIChatbot extends HTMLElement {
|
|
2
|
-
constructor() {
|
|
3
|
-
super();
|
|
4
|
-
this.attachShadow({ mode: 'open' });
|
|
5
|
-
this.apiUrl = this.getAttribute('api') || '/api/chatbot/query';
|
|
6
|
-
this.messages = [];
|
|
7
|
-
this.isOpen = false;
|
|
8
|
-
this.isTyping = false;
|
|
9
|
-
this.render();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
connectedCallback() {
|
|
13
|
-
this.setupEventListeners();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
render() {
|
|
17
|
-
this.shadowRoot.innerHTML = `
|
|
18
|
-
<style>
|
|
19
|
-
:host {
|
|
20
|
-
position: fixed;
|
|
21
|
-
bottom: 20px;
|
|
22
|
-
right: 20px;
|
|
23
|
-
z-index: 9999;
|
|
24
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
.chat-container {
|
|
28
|
-
display: ${this.isOpen ? 'block' : 'none'};
|
|
29
|
-
width: 350px;
|
|
30
|
-
height: 500px;
|
|
31
|
-
background: white;
|
|
32
|
-
border-radius: 12px;
|
|
33
|
-
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
|
|
34
|
-
overflow: hidden;
|
|
35
|
-
position: relative;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
.chat-header {
|
|
39
|
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
40
|
-
color: white;
|
|
41
|
-
padding: 16px;
|
|
42
|
-
font-weight: 600;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
.chat-messages {
|
|
46
|
-
height: 380px;
|
|
47
|
-
overflow-y: auto;
|
|
48
|
-
padding: 16px;
|
|
49
|
-
background: #f8f9fa;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
.message {
|
|
53
|
-
margin-bottom: 12px;
|
|
54
|
-
padding: 8px 12px;
|
|
55
|
-
border-radius: 8px;
|
|
56
|
-
max-width: 80%;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
.message.user {
|
|
60
|
-
background: #007bff;
|
|
61
|
-
color: white;
|
|
62
|
-
margin-left: auto;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
.message.bot {
|
|
66
|
-
background: white;
|
|
67
|
-
color: #333;
|
|
68
|
-
border: 1px solid #e9ecef;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
.typing {
|
|
72
|
-
display: ${this.isTyping ? 'block' : 'none'};
|
|
73
|
-
font-style: italic;
|
|
74
|
-
color: #666;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
.chat-input {
|
|
78
|
-
padding: 16px;
|
|
79
|
-
background: white;
|
|
80
|
-
border-top: 1px solid #e9ecef;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
.input-group {
|
|
84
|
-
display: flex;
|
|
85
|
-
gap: 8px;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
input {
|
|
89
|
-
flex: 1;
|
|
90
|
-
padding: 8px 12px;
|
|
91
|
-
border: 1px solid #ddd;
|
|
92
|
-
border-radius: 6px;
|
|
93
|
-
outline: none;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
button {
|
|
97
|
-
padding: 8px 16px;
|
|
98
|
-
background: #007bff;
|
|
99
|
-
color: white;
|
|
100
|
-
border: none;
|
|
101
|
-
border-radius: 6px;
|
|
102
|
-
cursor: pointer;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
button:hover {
|
|
106
|
-
background: #0056b3;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
.chat-toggle {
|
|
110
|
-
width: 60px;
|
|
111
|
-
height: 60px;
|
|
112
|
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
113
|
-
border-radius: 50%;
|
|
114
|
-
border: none;
|
|
115
|
-
color: white;
|
|
116
|
-
font-size: 24px;
|
|
117
|
-
cursor: pointer;
|
|
118
|
-
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
|
|
119
|
-
display: flex;
|
|
120
|
-
align-items: center;
|
|
121
|
-
justify-content: center;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
.chat-toggle:hover {
|
|
125
|
-
transform: scale(1.05);
|
|
126
|
-
}
|
|
127
|
-
</style>
|
|
128
|
-
|
|
129
|
-
<div class="chat-container">
|
|
130
|
-
<div class="chat-header">
|
|
131
|
-
🤖 AgenticAI Chatbot
|
|
132
|
-
</div>
|
|
133
|
-
<div class="chat-messages" id="messages">
|
|
134
|
-
${this.messages.map(msg => `
|
|
135
|
-
<div class="message ${msg.sender}">
|
|
136
|
-
${msg.text}
|
|
137
|
-
</div>
|
|
138
|
-
`).join('')}
|
|
139
|
-
<div class="message bot typing" id="typing">Typing...</div>
|
|
140
|
-
</div>
|
|
141
|
-
<div class="chat-input">
|
|
142
|
-
<div class="input-group">
|
|
143
|
-
<input type="text" id="messageInput" placeholder="Ask me anything..." />
|
|
144
|
-
<button id="sendButton">Send</button>
|
|
145
|
-
</div>
|
|
146
|
-
</div>
|
|
147
|
-
</div>
|
|
148
|
-
|
|
149
|
-
<button class="chat-toggle" id="toggleButton">
|
|
150
|
-
${this.isOpen ? '✕' : '💬'}
|
|
151
|
-
</button>
|
|
152
|
-
`;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
setupEventListeners() {
|
|
156
|
-
const toggleButton = this.shadowRoot.getElementById('toggleButton');
|
|
157
|
-
const sendButton = this.shadowRoot.getElementById('sendButton');
|
|
158
|
-
const messageInput = this.shadowRoot.getElementById('messageInput');
|
|
159
|
-
|
|
160
|
-
toggleButton.addEventListener('click', () => {
|
|
161
|
-
this.isOpen = !this.isOpen;
|
|
162
|
-
this.render();
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
sendButton.addEventListener('click', () => this.sendMessage());
|
|
166
|
-
messageInput.addEventListener('keypress', (e) => {
|
|
167
|
-
if (e.key === 'Enter') this.sendMessage();
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
async sendMessage() {
|
|
172
|
-
const messageInput = this.shadowRoot.getElementById('messageInput');
|
|
173
|
-
const query = messageInput.value.trim();
|
|
174
|
-
if (!query) return;
|
|
175
|
-
|
|
176
|
-
// Add user message
|
|
177
|
-
this.messages.push({ sender: 'user', text: query });
|
|
178
|
-
messageInput.value = '';
|
|
179
|
-
this.render();
|
|
180
|
-
|
|
181
|
-
// Show typing
|
|
182
|
-
this.isTyping = true;
|
|
183
|
-
this.render();
|
|
184
|
-
|
|
185
|
-
try {
|
|
186
|
-
const response = await fetch(this.apiUrl, {
|
|
187
|
-
method: 'POST',
|
|
188
|
-
headers: {
|
|
189
|
-
'Content-Type': 'application/json',
|
|
190
|
-
},
|
|
191
|
-
body: JSON.stringify({ query }),
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
const data = await response.json();
|
|
195
|
-
|
|
196
|
-
// Hide typing
|
|
197
|
-
this.isTyping = false;
|
|
198
|
-
|
|
199
|
-
if (data.error) {
|
|
200
|
-
this.messages.push({ sender: 'bot', text: `Error: ${data.error}` });
|
|
201
|
-
} else {
|
|
202
|
-
this.messages.push({ sender: 'bot', text: data.answer || data.reply || 'No response' });
|
|
203
|
-
}
|
|
204
|
-
} catch (error) {
|
|
205
|
-
this.isTyping = false;
|
|
206
|
-
this.messages.push({ sender: 'bot', text: 'Sorry, I encountered an error. Please try again.' });
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
this.render();
|
|
210
|
-
this.scrollToBottom();
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
scrollToBottom() {
|
|
214
|
-
const messages = this.shadowRoot.getElementById('messages');
|
|
215
|
-
messages.scrollTop = messages.scrollHeight;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
customElements.define('agentica-chatbot', AgenticAIChatbot);
|
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
class AgenticAIChatbot extends HTMLElement {
|
|
2
|
-
constructor() {
|
|
3
|
-
super();
|
|
4
|
-
this.attachShadow({ mode: 'open' });
|
|
5
|
-
this.apiUrl = this.getAttribute('api') || '/api/chatbot/query';
|
|
6
|
-
this.messages = [];
|
|
7
|
-
this.isOpen = false;
|
|
8
|
-
this.isTyping = false;
|
|
9
|
-
this.render();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
connectedCallback() {
|
|
13
|
-
this.setupEventListeners();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
render() {
|
|
17
|
-
this.shadowRoot.innerHTML = `
|
|
18
|
-
<style>
|
|
19
|
-
:host {
|
|
20
|
-
position: fixed;
|
|
21
|
-
bottom: 20px;
|
|
22
|
-
right: 20px;
|
|
23
|
-
z-index: 9999;
|
|
24
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
.chat-container {
|
|
28
|
-
display: ${this.isOpen ? 'block' : 'none'};
|
|
29
|
-
width: 350px;
|
|
30
|
-
height: 500px;
|
|
31
|
-
background: white;
|
|
32
|
-
border-radius: 12px;
|
|
33
|
-
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
|
|
34
|
-
overflow: hidden;
|
|
35
|
-
position: relative;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
.chat-header {
|
|
39
|
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
40
|
-
color: white;
|
|
41
|
-
padding: 16px;
|
|
42
|
-
font-weight: 600;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
.chat-messages {
|
|
46
|
-
height: 380px;
|
|
47
|
-
overflow-y: auto;
|
|
48
|
-
padding: 16px;
|
|
49
|
-
background: #f8f9fa;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
.message {
|
|
53
|
-
margin-bottom: 12px;
|
|
54
|
-
padding: 8px 12px;
|
|
55
|
-
border-radius: 8px;
|
|
56
|
-
max-width: 80%;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
.message.user {
|
|
60
|
-
background: #007bff;
|
|
61
|
-
color: white;
|
|
62
|
-
margin-left: auto;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
.message.bot {
|
|
66
|
-
background: white;
|
|
67
|
-
color: #333;
|
|
68
|
-
border: 1px solid #e9ecef;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
.typing {
|
|
72
|
-
display: ${this.isTyping ? 'block' : 'none'};
|
|
73
|
-
font-style: italic;
|
|
74
|
-
color: #666;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
.chat-input {
|
|
78
|
-
padding: 16px;
|
|
79
|
-
background: white;
|
|
80
|
-
border-top: 1px solid #e9ecef;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
.input-group {
|
|
84
|
-
display: flex;
|
|
85
|
-
gap: 8px;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
input {
|
|
89
|
-
flex: 1;
|
|
90
|
-
padding: 8px 12px;
|
|
91
|
-
border: 1px solid #ddd;
|
|
92
|
-
border-radius: 6px;
|
|
93
|
-
outline: none;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
button {
|
|
97
|
-
padding: 8px 16px;
|
|
98
|
-
background: #007bff;
|
|
99
|
-
color: white;
|
|
100
|
-
border: none;
|
|
101
|
-
border-radius: 6px;
|
|
102
|
-
cursor: pointer;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
button:hover {
|
|
106
|
-
background: #0056b3;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
.chat-toggle {
|
|
110
|
-
width: 60px;
|
|
111
|
-
height: 60px;
|
|
112
|
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
113
|
-
border-radius: 50%;
|
|
114
|
-
border: none;
|
|
115
|
-
color: white;
|
|
116
|
-
font-size: 24px;
|
|
117
|
-
cursor: pointer;
|
|
118
|
-
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
|
|
119
|
-
display: flex;
|
|
120
|
-
align-items: center;
|
|
121
|
-
justify-content: center;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
.chat-toggle:hover {
|
|
125
|
-
transform: scale(1.05);
|
|
126
|
-
}
|
|
127
|
-
</style>
|
|
128
|
-
|
|
129
|
-
<div class="chat-container">
|
|
130
|
-
<div class="chat-header">
|
|
131
|
-
🤖 AgenticAI Chatbot
|
|
132
|
-
</div>
|
|
133
|
-
<div class="chat-messages" id="messages">
|
|
134
|
-
${this.messages.map(msg => `
|
|
135
|
-
<div class="message ${msg.sender}">
|
|
136
|
-
${msg.text}
|
|
137
|
-
</div>
|
|
138
|
-
`).join('')}
|
|
139
|
-
<div class="message bot typing" id="typing">Typing...</div>
|
|
140
|
-
</div>
|
|
141
|
-
<div class="chat-input">
|
|
142
|
-
<div class="input-group">
|
|
143
|
-
<input type="text" id="messageInput" placeholder="Ask me anything..." />
|
|
144
|
-
<button id="sendButton">Send</button>
|
|
145
|
-
</div>
|
|
146
|
-
</div>
|
|
147
|
-
</div>
|
|
148
|
-
|
|
149
|
-
<button class="chat-toggle" id="toggleButton">
|
|
150
|
-
${this.isOpen ? '✕' : '💬'}
|
|
151
|
-
</button>
|
|
152
|
-
`;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
setupEventListeners() {
|
|
156
|
-
const toggleButton = this.shadowRoot.getElementById('toggleButton');
|
|
157
|
-
const sendButton = this.shadowRoot.getElementById('sendButton');
|
|
158
|
-
const messageInput = this.shadowRoot.getElementById('messageInput');
|
|
159
|
-
|
|
160
|
-
toggleButton.addEventListener('click', () => {
|
|
161
|
-
this.isOpen = !this.isOpen;
|
|
162
|
-
this.render();
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
sendButton.addEventListener('click', () => this.sendMessage());
|
|
166
|
-
messageInput.addEventListener('keypress', (e) => {
|
|
167
|
-
if (e.key === 'Enter') this.sendMessage();
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
async sendMessage() {
|
|
172
|
-
const messageInput = this.shadowRoot.getElementById('messageInput');
|
|
173
|
-
const query = messageInput.value.trim();
|
|
174
|
-
if (!query) return;
|
|
175
|
-
|
|
176
|
-
// Add user message
|
|
177
|
-
this.messages.push({ sender: 'user', text: query });
|
|
178
|
-
messageInput.value = '';
|
|
179
|
-
this.render();
|
|
180
|
-
|
|
181
|
-
// Show typing
|
|
182
|
-
this.isTyping = true;
|
|
183
|
-
this.render();
|
|
184
|
-
|
|
185
|
-
try {
|
|
186
|
-
const response = await fetch(this.apiUrl, {
|
|
187
|
-
method: 'POST',
|
|
188
|
-
headers: {
|
|
189
|
-
'Content-Type': 'application/json',
|
|
190
|
-
},
|
|
191
|
-
body: JSON.stringify({ query }),
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
const data = await response.json();
|
|
195
|
-
|
|
196
|
-
// Hide typing
|
|
197
|
-
this.isTyping = false;
|
|
198
|
-
|
|
199
|
-
if (data.error) {
|
|
200
|
-
this.messages.push({ sender: 'bot', text: `Error: ${data.error}` });
|
|
201
|
-
} else {
|
|
202
|
-
this.messages.push({ sender: 'bot', text: data.answer || data.reply || 'No response' });
|
|
203
|
-
}
|
|
204
|
-
} catch (error) {
|
|
205
|
-
this.isTyping = false;
|
|
206
|
-
this.messages.push({ sender: 'bot', text: 'Sorry, I encountered an error. Please try again.' });
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
this.render();
|
|
210
|
-
this.scrollToBottom();
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
scrollToBottom() {
|
|
214
|
-
const messages = this.shadowRoot.getElementById('messages');
|
|
215
|
-
messages.scrollTop = messages.scrollHeight;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
customElements.define('agentica-chatbot', AgenticAIChatbot);
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|