-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathindex.html
More file actions
678 lines (610 loc) · 25.8 KB
/
index.html
File metadata and controls
678 lines (610 loc) · 25.8 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Chatbot Demo</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
<script src="config.js"></script>
<style>
:root {
--primary-color: #FF0000;
--secondary-color: #000000;
--background-color: #f5f5f5;
--chat-bubble-user: #FFF0F0;
--chat-bubble-bot: #FFFFFF;
--text-color: #333333;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 0;
background-color: var(--background-color);
height: 100vh;
overflow: hidden;
background-image: url('/static/image.png');
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.page-header {
position: fixed;
top: 20px;
left: 20px;
display: flex;
align-items: center;
z-index: 1000;
}
.page-logo {
width: 300px; /* or whatever fits */
height: auto;
margin-right: 8px;
}
.page-title {
color: #ffffff; /* stands out on dark BG */
font-size: 22px;
font-weight: bold;
text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
/* User Selection Styles */
.user-selection {
position: fixed;
top: 20px;
right: 20px;
background: white;
padding: 15px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
z-index: 1000;
}
.user-selection select {
padding: 8px 12px;
border: 1px solid #ddd;
border-radius: 5px;
font-size: 14px;
width: 150px;
}
/* Chat Widget Styles */
.chat-widget {
position: fixed;
bottom: 20px;
right: 20px;
z-index: 1000;
}
.chat-bubble {
width: 60px;
height: 60px;
background: var(--primary-color);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
box-shadow: 0 2px 10px rgba(0,0,0,0.2);
transition: transform 0.3s ease;
border: 2px solid var(--secondary-color);
}
.chat-bubble:hover {
transform: scale(1.05);
}
.chat-bubble i {
color: white;
font-size: 24px;
}
.chat-container {
position: fixed;
bottom: 90px;
right: 20px;
width: 450px;
height: 600px;
background: rgba(255, 255, 255, 0.9);
border-radius: 15px;
box-shadow: 0 5px 20px rgba(0,0,0,0.15);
display: flex;
flex-direction: column;
overflow: hidden;
backdrop-filter: blur(5px);
transition: all 0.3s ease;
opacity: 1;
visibility: visible;
}
.chat-container.hidden {
opacity: 0;
visibility: hidden;
transform: translateY(20px);
pointer-events: none;
}
.chat-header {
background: var(--primary-color);
color: white;
padding: 15px;
display: flex;
justify-content: space-between;
align-items: center;
border-bottom: 3px solid var(--secondary-color);
}
.chat-messages {
flex-grow: 1;
padding: 20px;
overflow-y: auto;
}
.message {
display: flex;
align-items: center;
margin-bottom: 15px;
gap: 8px;
}
.message.bot {
justify-content: flex-start;
margin-right: auto;
flex-direction: row;
}
.message.user {
margin-right: 0;
justify-content: flex-end;
flex-direction: row;
}
/* the icon container */
.message-icon {
font-size: 20px;
color: #ff0000;
line-height: 1;
margin: 0 8px;
color: var(--secondary-color);
}
.message-content {
padding: 10px 15px;
border-radius: 15px;
font-size: 18px;
line-height: 1.4;
background: var(--chat-bubble-bot);
box-shadow: 0 1px 2px rgba(0,0,0,0.1);
max-width: 70%;
overflow-x: auto;
white-space: pre-wrap;
word-wrap: break-word;
margin-left: 0;
margin-right: 0;
text-align: left;
}
.message.user .message-content {
background: var(--chat-bubble-user);
max-width: 60%;
align-self: flex-end;
margin-left: auto;
margin-right: 0;
}
/* Table styles */
.message-content table {
border-collapse: collapse;
width: 100%;
margin: 10px 0;
font-size: 14px;
background: white;
}
.message-content th,
.message-content td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
.message-content th {
background-color: #f5f5f5;
font-weight: bold;
}
.message-content tr:nth-child(even) {
background-color: #f9f9f9;
}
.message-content tr:hover {
background-color: #f5f5f5;
}
/* Code block styles */
.message-content pre {
background: #f5f5f5;
padding: 10px;
border-radius: 5px;
overflow-x: auto;
margin: 10px 0;
}
.message-content code {
font-family: 'Courier New', Courier, monospace;
font-size: 14px;
}
#messageInput {
font-size: 18px;
}
.chat-input {
padding: 15px;
border-top: 1px solid #eee;
display: flex;
gap: 10px;
}
.chat-input input {
flex-grow: 1;
padding: 10px;
border: 1px solid #ddd;
border-radius: 20px;
outline: none;
}
.chat-input button {
background: var(--primary-color);
color: white;
border: none;
padding: 10px 15px;
border-radius: 20px;
cursor: pointer;
border: 1px solid var(--secondary-color);
}
.chat-input button:hover {
background: var(--secondary-color);
color: var(--primary-color);
}
/* Settings Panel */
.settings-panel {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: white;
padding: 20px;
border-radius: 15px;
box-shadow: 0 5px 20px rgba(0,0,0,0.15);
display: none;
z-index: 2000;
}
.theme-options {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 10px;
margin-top: 15px;
}
.theme-color {
width: 40px;
height: 40px;
border-radius: 50%;
cursor: pointer;
border: 2px solid transparent;
}
.theme-color.active {
border-color: #333;
}
/* Minimize/Maximize Animation */
.minimized {
display: none !important;
}
</style>
</head>
<body>
<!-- User Selection -->
<!-- User Selection -->
<div class="user-selection">
<!-- keep the same id so the JavaScript continues to work -->
<input type="text"
id="userSelect"
placeholder="Enter metadata to filter..."
style="padding:8px 12px;border:1px solid #ddd;border-radius:5px;font-size:14px;width:150px;" />
</div>
<div class="page-header">
<img src="/static/oracle-white.png" alt="Oracle Logo" class="page-logo">
<span class="page-title">Developer Coaching</span>
</div>
<!-- Chat Widget -->
<div class="chat-widget">
<div class="chat-bubble" id="chatBubble">
<i class="fas fa-comments"></i>
</div>
<div class="chat-container" id="chatContainer">
<div class="chat-header">
<span>AI Assistant</span>
<div>
<button id="settingsBtn" style="background: none; border: none; color: white; cursor: pointer;">
<i class="fas fa-cog"></i>
</button>
<button id="minimizeBtn" style="background: none; border: none; color: white; cursor: pointer;">
<i class="fas fa-minus"></i>
</button>
</div>
</div>
<div class="chat-messages" id="chatMessages">
<!-- Removed initial bot welcome message to avoid duplication -->
</div>
<div class="chat-input">
<input type="text" placeholder="Type your message..." id="messageInput">
<button id="sendBtn">
<i class="fas fa-paper-plane"></i>
</button>
</div>
</div>
</div>
<!-- Settings Panel -->
<div class="settings-panel" id="settingsPanel">
<h3>Settings</h3>
<div>
<label>Background Image:</label>
<input type="file" accept="image/*" id="wallpaperInput">
</div>
<div>
<label>Theme Color:</label>
<div class="theme-options">
<div class="theme-color" style="background: #FF0000; border: 2px solid #000000;" data-theme="oracle" title="Oracle Theme"></div>
<div class="theme-color" style="background: #2196F3;" data-theme="blue"></div>
<div class="theme-color" style="background: #4CAF50;" data-theme="green"></div>
<div class="theme-color" style="background: #9C27B0;" data-theme="purple"></div>
<div class="theme-color" style="background: #FF5722;" data-theme="orange"></div>
<div class="theme-color" style="background: #E91E63;" data-theme="pink"></div>
<div class="theme-color" style="background: #607D8B;" data-theme="grey"></div>
<div class="theme-color" style="background: #795548;" data-theme="brown"></div>
</div>
</div>
<div style="margin-top: 15px;">
<label>Chat Transparency:</label>
<input type="range" id="transparencySlider" min="0.1" max="1" step="0.1" value="0.9" style="width: 100%;">
<div style="text-align: center; font-size: 12px; color: #666;" id="transparencyValue">90%</div>
</div>
<div style="margin-top: 15px;">
<label>Max Response Length (tokens):</label>
<input type="number" id="maxTokensInput" min="100" max="4000" step="100" value="1000" style="width: 100%;">
<div style="text-align: center; font-size: 12px; color: #666;">Lower values = shorter responses</div>
</div>
</div>
<!-- Load scripts at the end of body -->
<script src="config.js"></script>
<script>
// Wait for DOM to be fully loaded
window.addEventListener('load', function() {
console.log('Window loaded');
// Initialize configuration
const chatConfig = new ChatConfig();
console.log('Chat config initialized');
// Get all required elements
const chatBubble = document.getElementById('chatBubble');
const chatContainer = document.getElementById('chatContainer');
const minimizeBtn = document.getElementById('minimizeBtn');
const settingsBtn = document.getElementById('settingsBtn');
const settingsPanel = document.getElementById('settingsPanel');
const messageInput = document.getElementById('messageInput');
const sendBtn = document.getElementById('sendBtn');
const chatMessages = document.getElementById('chatMessages');
const userSelect = document.getElementById('userSelect');
const maxTokensInput = document.getElementById('maxTokensInput');
// Verify all elements are found
const elements = {
chatBubble, chatContainer, minimizeBtn, settingsBtn,
settingsPanel, messageInput, sendBtn, chatMessages,
userSelect, maxTokensInput
};
Object.entries(elements).forEach(([name, element]) => {
if (!element) {
console.error(`Element not found: ${name}`);
} else {
console.log(`Element found: ${name}`);
}
});
// Chat bubble click handler
if (chatBubble) {
chatBubble.addEventListener('click', function(e) {
console.log('Chat bubble clicked');
e.stopPropagation();
chatContainer.classList.toggle('hidden');
});
}
// Minimize button click handler
if (minimizeBtn) {
minimizeBtn.addEventListener('click', function(e) {
console.log('Minimize button clicked');
e.stopPropagation();
chatContainer.classList.add('hidden');
});
}
// Settings button click handler
if (settingsBtn) {
settingsBtn.addEventListener('click', function(e) {
console.log('Settings button clicked');
e.stopPropagation();
settingsPanel.style.display = settingsPanel.style.display === 'none' ? 'block' : 'none';
});
}
// Close settings panel when clicking outside
document.addEventListener('click', function(e) {
if (!settingsPanel.contains(e.target) && e.target !== settingsBtn) {
settingsPanel.style.display = 'none';
}
});
// Send message function
async function sendMessage() {
console.log('Sending message');
const message = messageInput.value.trim();
if (message) {
// Add user message to chat
const messageElement = document.createElement('div');
messageElement.className = 'message user';
messageElement.innerHTML = `<div class="message-content">${message}</div><div class="message-icon"><i class="fas fa-user"></i></div>`;
chatMessages.appendChild(messageElement);
messageInput.value = '';
chatMessages.scrollTop = chatMessages.scrollHeight;
try {
// Send message to backend
const response = await fetch('/chat', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
message: message,
user: chatConfig.config.lastUser,
max_tokens: parseInt(maxTokensInput.value)
})
});
const data = await response.json();
// Process the message to handle tables and code blocks
let processedMessage = data.message;
// Check if the message is a SQL result (JSON format)
try {
const jsonData = JSON.parse(processedMessage);
if (jsonData.executionResult && Array.isArray(jsonData.executionResult)) {
// Convert SQL result to HTML table
let tableHtml = '<table>';
// Add headers
if (jsonData.executionResult.length > 0) {
tableHtml += '<tr>';
Object.keys(jsonData.executionResult[0]).forEach(key => {
tableHtml += `<th>${key.replace(/_/g, ' ').toUpperCase()}</th>`;
});
tableHtml += '</tr>';
}
// Add rows
jsonData.executionResult.forEach(row => {
tableHtml += '<tr>';
Object.values(row).forEach(value => {
tableHtml += `<td>${value}</td>`;
});
tableHtml += '</tr>';
});
tableHtml += '</table>';
processedMessage = tableHtml;
}
} catch (e) {
// If it's not a JSON SQL result, check for markdown table
if (processedMessage.includes('|') && processedMessage.includes('-')) {
// Convert markdown table to HTML table
const lines = processedMessage.split('\n').filter(line => line.trim());
let tableHtml = '<table>';
let isInTable = false;
lines.forEach(line => {
if (line.includes('|') && !line.includes('---')) {
if (!isInTable) {
tableHtml = '<table>';
isInTable = true;
}
const cells = line.split('|').filter(cell => cell.trim());
tableHtml += '<tr>';
cells.forEach(cell => {
const tag = line === lines[0] ? 'th' : 'td';
tableHtml += `<${tag}>${cell.trim()}</${tag}>`;
});
tableHtml += '</tr>';
} else if (isInTable && !line.includes('|')) {
tableHtml += '</table>';
isInTable = false;
}
});
if (isInTable) {
tableHtml += '</table>';
}
processedMessage = processedMessage.replace(/\|.*\|[\s\S]*?\|/g, tableHtml);
}
}
// Clean up text formatting
processedMessage = processedMessage
.replace(/^\s+/gm, '') // Remove leading spaces
.replace(/\n\s*\n/g, '\n') // Remove multiple empty lines
.trim(); // Remove leading/trailing whitespace
// Add bot response to chat
const botMessageElement = document.createElement('div');
botMessageElement.className = 'message bot';
botMessageElement.innerHTML = `<div class="message-icon"><i class="fas fa-robot"></i></div><div class="message-content">${processedMessage}</div>`;
chatMessages.appendChild(botMessageElement);
chatMessages.scrollTop = chatMessages.scrollHeight;
// If we got back a QR code, render it right after the text
if (data.qr_image_base64) {
const qrWrapper = document.createElement('div');
qrWrapper.className = 'message bot';
qrWrapper.innerHTML = `<div class="message-icon"><i class="fas fa-robot"></i></div><div class="message-content"><img src="data:image/png;base64,${data.qr_image_base64}" alt="QR Code" style="max-width: 100%; display: block; margin-top: 8px;" /></div>`;
chatMessages.appendChild(qrWrapper);
chatMessages.scrollTop = chatMessages.scrollHeight;
}
} catch (error) {
console.error('Error:', error);
const errorElement = document.createElement('div');
errorElement.className = 'message bot';
errorElement.innerHTML = `<div class="message-content">Sorry, there was an error processing your message. Please try again.</div>`;
chatMessages.appendChild(errorElement);
chatMessages.scrollTop = chatMessages.scrollHeight;
}
}
}
// Send button click handler
if (sendBtn) {
sendBtn.addEventListener('click', function(e) {
console.log('Send button clicked');
e.stopPropagation();
sendMessage();
});
}
// Enter key handler
if (messageInput) {
messageInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
console.log('Enter key pressed');
e.stopPropagation();
sendMessage();
}
});
}
// User selection handler
if (userSelect) {
userSelect.addEventListener('change', function(e) {
console.log('User changed:', e.target.value);
chatConfig.setLastUser(e.target.value);
// Clear chat messages when user changes
chatMessages.innerHTML = '';
const welcomeMessage = document.createElement('div');
welcomeMessage.className = 'message bot';
welcomeMessage.innerHTML = `<div class="message-icon"><i class="fas fa-robot"></i></div><div class="message-content">Hello! How can I help you today?</div>`;
chatMessages.appendChild(welcomeMessage);
});
}
// Theme colors handler
const themeColors = document.querySelectorAll('.theme-color');
themeColors.forEach(color => {
color.addEventListener('click', function(e) {
console.log('Theme color clicked:', color.dataset.theme);
e.stopPropagation();
themeColors.forEach(c => c.classList.remove('active'));
color.classList.add('active');
const isOracle = color.dataset.theme === 'oracle';
chatConfig.setTheme(color.style.background, isOracle);
});
});
// Transparency slider handler
const transparencySlider = document.getElementById('transparencySlider');
const transparencyValue = document.getElementById('transparencyValue');
if (transparencySlider) {
transparencySlider.addEventListener('input', function(e) {
console.log('Transparency changed:', e.target.value);
const value = parseFloat(e.target.value);
transparencyValue.textContent = `${Math.round(value * 100)}%`;
chatConfig.setTransparency(value);
});
}
// Wallpaper upload handler
const wallpaperInput = document.getElementById('wallpaperInput');
if (wallpaperInput) {
wallpaperInput.addEventListener('change', function(e) {
console.log('Wallpaper file selected');
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
chatConfig.setWallpaper(e.target.result);
};
reader.readAsDataURL(file);
}
});
}
// Max tokens input handler
if (maxTokensInput) {
maxTokensInput.addEventListener('change', function(e) {
const value = parseInt(e.target.value);
if (value >= 100 && value <= 4000) {
chatConfig.setMaxTokens(value);
}
});
}
// Initialize chat container as hidden
chatContainer.classList.add('hidden');
console.log('Initial setup complete');
});
</script>
</body>
</html>