-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate-chatbot-optimization.js
More file actions
239 lines (207 loc) Β· 7.83 KB
/
validate-chatbot-optimization.js
File metadata and controls
239 lines (207 loc) Β· 7.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/usr/bin/env node
/**
* Chatbot Optimization Validation Script
* This script validates that the chatbot optimization has been properly implemented
*/
const fs = require('fs');
const path = require('path');
console.log('π Validating Chatbot Optimization Implementation...\n');
// Files to check
const filesToCheck = [
'src/app/component/chatbot/chatbot.jsx',
'src/app/api/chat/route.js',
'src/app/api/health/route.js',
'src/app/component/chatbot/SkeletonLoader.jsx',
'src/app/component/chatbot/TypingIndicator.jsx'
];
let allChecksPassed = true;
// Check if optimized files exist
console.log('π Checking for optimized files...');
filesToCheck.forEach(file => {
const filePath = path.join(__dirname, file);
if (fs.existsSync(filePath)) {
console.log(`β
${file} exists`);
} else {
console.log(`β ${file} missing`);
allChecksPassed = false;
}
});
// Check main page.jsx for integration
console.log('\nπ Checking main page integration...');
const pagePath = path.join(__dirname, 'src/app/page.jsx');
if (fs.existsSync(pagePath)) {
const pageContent = fs.readFileSync(pagePath, 'utf8');
// Check for dynamic import (Next.js lazy loading)
if (pageContent.includes('dynamic') && pageContent.includes("import('./component/chatbot/chatbot')")) {
console.log('β
Next.js dynamic import (lazy loading) found');
} else {
console.log('β Next.js dynamic import missing');
allChecksPassed = false;
}
// Check for SSR false (important for client-side components)
if (pageContent.includes('ssr: false')) {
console.log('β
SSR disabled for chatbot found');
} else {
console.log('β SSR disabled for chatbot missing');
allChecksPassed = false;
}
// Check for chatbot component usage
if (pageContent.includes('<Chatbot />')) {
console.log('β
Chatbot component usage found');
} else {
console.log('β Chatbot component usage missing');
allChecksPassed = false;
}
} else {
console.log('β page.jsx not found');
allChecksPassed = false;
}
// Check API route for Vercel AI SDK usage
console.log('\nπ Checking API route optimization...');
const apiPath = path.join(__dirname, 'src/app/api/chat/route.js');
if (fs.existsSync(apiPath)) {
const apiContent = fs.readFileSync(apiPath, 'utf8');
if (apiContent.includes('streamText') && apiContent.includes('@ai-sdk/google')) {
console.log('β
Vercel AI SDK streaming found in API route');
} else {
console.log('β Vercel AI SDK streaming missing in API route');
allChecksPassed = false;
}
if (apiContent.includes('checkRateLimit') || apiContent.includes('RATE_LIMIT')) {
console.log('β
Rate limiting implementation found');
} else {
console.log('β Rate limiting implementation missing');
allChecksPassed = false;
}
if (apiContent.includes('ChatbotError') || apiContent.includes('error handling')) {
console.log('β
Enhanced error handling found');
} else {
console.log('β Enhanced error handling missing');
allChecksPassed = false;
}
if (apiContent.includes('LeadExtractionSchema') || apiContent.includes('extractLeadFromConversation')) {
console.log('β
Lead capture integration found');
} else {
console.log('β Lead capture integration missing');
allChecksPassed = false;
}
} else {
console.log('β API route not found');
allChecksPassed = false;
}
// Check for error handling improvements
console.log('\nπ Checking error handling improvements...');
const chatbotPath = path.join(__dirname, 'src/app/component/chatbot/chatbot.jsx');
if (fs.existsSync(chatbotPath)) {
const chatbotContent = fs.readFileSync(chatbotPath, 'utf8');
if (chatbotContent.includes('connectionStatus') && chatbotContent.includes('trackError')) {
console.log('β
Connection status and error tracking found');
} else {
console.log('β Connection status and error tracking missing');
allChecksPassed = false;
}
if (chatbotContent.includes('try') && chatbotContent.includes('catch')) {
console.log('β
Try-catch error handling found');
} else {
console.log('β Try-catch error handling missing');
allChecksPassed = false;
}
if (chatbotContent.includes('AbortSignal.timeout')) {
console.log('β
Request timeout handling found');
} else {
console.log('β Request timeout handling missing');
allChecksPassed = false;
}
} else {
console.log('β Chatbot component not found');
allChecksPassed = false;
}
// Check for accessibility improvements
console.log('\nπ Checking accessibility improvements...');
if (fs.existsSync(chatbotPath)) {
const chatbotContent = fs.readFileSync(chatbotPath, 'utf8');
if (chatbotContent.includes('aria-') && chatbotContent.includes('role=')) {
console.log('β
ARIA attributes found');
} else {
console.log('β ARIA attributes missing');
allChecksPassed = false;
}
if (chatbotContent.includes('keydown') || chatbotContent.includes('Escape')) {
console.log('β
Keyboard navigation found');
} else {
console.log('β Keyboard navigation missing');
allChecksPassed = false;
}
if (chatbotContent.includes('prefersReducedMotion')) {
console.log('β
Reduced motion support found');
} else {
console.log('β Reduced motion support missing');
allChecksPassed = false;
}
} else {
console.log('β Chatbot component not found');
allChecksPassed = false;
}
// Check for performance optimizations
console.log('\nπ Checking performance optimizations...');
if (fs.existsSync(chatbotPath)) {
const chatbotContent = fs.readFileSync(chatbotPath, 'utf8');
if (chatbotContent.includes('useMemo') || chatbotContent.includes('useCallback')) {
console.log('β
React optimization hooks found');
} else {
console.log('β React optimization hooks missing');
allChecksPassed = false;
}
if (chatbotContent.includes('useEffect') && chatbotContent.includes('cleanup')) {
console.log('β
Effect cleanup found');
} else {
console.log('β Effect cleanup missing');
allChecksPassed = false;
}
if (chatbotContent.includes('lazy') || chatbotContent.includes('Suspense')) {
console.log('β
Lazy loading implementation found');
} else {
console.log('β Lazy loading implementation missing');
allChecksPassed = false;
}
} else {
console.log('β Chatbot component not found');
allChecksPassed = false;
}
// Check for responsive design improvements
console.log('\nπ Checking responsive design improvements...');
if (fs.existsSync(chatbotPath)) {
const chatbotContent = fs.readFileSync(chatbotPath, 'utf8');
if (chatbotContent.includes('useResponsive') || chatbotContent.includes('isMobile')) {
console.log('β
Responsive design implementation found');
} else {
console.log('β Responsive design implementation missing');
allChecksPassed = false;
}
if (chatbotContent.includes('isTouch') || chatbotContent.includes('prefersReducedMotion')) {
console.log('β
Touch and motion preferences found');
} else {
console.log('β Touch and motion preferences missing');
allChecksPassed = false;
}
} else {
console.log('β Chatbot component not found');
allChecksPassed = false;
}
// Final summary
console.log('\n' + '='.repeat(50));
if (allChecksPassed) {
console.log('π All validation checks passed!');
console.log('β
Chatbot optimization has been successfully implemented');
console.log('β
Vercel AI SDK integration is working');
console.log('β
Performance improvements are in place');
console.log('β
Error handling has been enhanced');
console.log('β
Accessibility improvements are implemented');
console.log('β
Responsive design is optimized');
} else {
console.log('β Some validation checks failed');
console.log('Please review the output above and fix the issues');
}
console.log('='.repeat(50));
// Exit with appropriate code
process.exit(allChecksPassed ? 0 : 1);