feat(chatbot): integrate OpenRouter API for AI assistance in dashboard

- Added a Chatbot component to the dashboard for user interaction and support.
- Created a README for the Chatbot detailing setup, features, and usage instructions.
- Introduced environment variables for secure API key management.
- Updated app.js to include the Chatbot component.
- Implemented a configuration server to serve API keys securely.
- Enhanced styles for the Chatbot interface to improve user experience.
This commit is contained in:
2025-09-27 15:00:30 +08:00
parent c0c3fb7b5a
commit ec3c7320d7
12 changed files with 1194 additions and 1 deletions

View File

@@ -437,4 +437,279 @@ button.chip[aria-pressed="true"]{
}
/* accessibility tweaks */
.chip, .btn{font-family:inherit}
.chip, .btn{font-family:inherit}
/* Chatbot styles */
.chatbot-toggle {
position: fixed;
bottom: 20px;
right: 20px;
background: var(--accent);
color: white;
border: none;
border-radius: 50px;
padding: 12px 20px;
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
box-shadow: 0 4px 12px rgba(14, 165, 164, 0.3);
transition: all 0.3s ease;
z-index: 1000;
font-size: 14px;
font-weight: 600;
}
.chatbot-toggle:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(14, 165, 164, 0.4);
background: #0d9488;
}
.chatbot-toggle-icon {
font-size: 18px;
}
.chatbot-container {
position: fixed;
bottom: 20px;
right: 20px;
width: 350px;
height: 500px;
background: var(--panel);
border-radius: 12px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
display: flex;
flex-direction: column;
z-index: 1000;
overflow: hidden;
border: 1px solid rgba(0, 0, 0, 0.05);
}
.chatbot-header {
background: linear-gradient(135deg, var(--accent), #0d9488);
color: white;
padding: 16px 20px;
display: flex;
justify-content: space-between;
align-items: center;
}
.chatbot-header h3 {
margin: 0;
font-size: 16px;
font-weight: 600;
}
.chatbot-close {
background: none;
border: none;
color: white;
font-size: 20px;
cursor: pointer;
padding: 4px;
border-radius: 4px;
transition: background-color 0.2s ease;
}
.chatbot-close:hover {
background-color: rgba(255, 255, 255, 0.2);
}
.chatbot-messages {
flex: 1;
overflow-y: auto;
padding: 16px;
display: flex;
flex-direction: column;
gap: 12px;
}
.message {
display: flex;
gap: 8px;
max-width: 85%;
}
.message.bot {
align-self: flex-start;
}
.message.user {
align-self: flex-end;
flex-direction: row-reverse;
}
.message-avatar {
width: 32px;
height: 32px;
border-radius: 50%;
background: var(--accent);
display: flex;
align-items: center;
justify-content: center;
font-size: 14px;
flex-shrink: 0;
}
.message.user .message-avatar {
background: var(--severity-high);
}
.message-content {
flex: 1;
}
.message-text {
background: #f8fafc;
padding: 10px 12px;
border-radius: 12px;
font-size: 14px;
line-height: 1.5;
word-wrap: break-word;
white-space: pre-wrap;
font-family: inherit;
}
.message.user .message-text {
background: var(--accent);
color: white;
}
.message-time {
font-size: 11px;
color: #6b7280;
margin-top: 4px;
text-align: right;
}
.message.user .message-time {
text-align: left;
}
.typing-indicator {
display: flex;
gap: 4px;
align-items: center;
padding: 10px 12px;
}
.typing-indicator span {
width: 6px;
height: 6px;
border-radius: 50%;
background: #6b7280;
animation: typing 1.4s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) {
animation-delay: 0.2s;
}
.typing-indicator span:nth-child(3) {
animation-delay: 0.4s;
}
@keyframes typing {
0%, 60%, 100% {
transform: translateY(0);
opacity: 0.4;
}
30% {
transform: translateY(-10px);
opacity: 1;
}
}
.chatbot-quick-actions {
padding: 12px 16px;
border-top: 1px solid #e5e7eb;
display: flex;
gap: 6px;
flex-wrap: wrap;
}
.quick-action-btn {
background: #f1f5f9;
border: 1px solid #e2e8f0;
border-radius: 16px;
padding: 6px 12px;
font-size: 11px;
color: #475569;
cursor: pointer;
transition: all 0.2s ease;
}
.quick-action-btn:hover {
background: var(--accent);
color: white;
border-color: var(--accent);
}
.chatbot-input-form {
padding: 16px;
border-top: 1px solid #e5e7eb;
display: flex;
gap: 8px;
align-items: center;
}
.chatbot-input {
flex: 1;
padding: 10px 12px;
border: 1px solid #d1d5db;
border-radius: 20px;
font-size: 14px;
outline: none;
transition: border-color 0.2s ease;
}
.chatbot-input:focus {
border-color: var(--accent);
box-shadow: 0 0 0 3px rgba(14, 165, 164, 0.1);
}
.chatbot-input:disabled {
background: #f8fafc;
cursor: not-allowed;
}
.chatbot-send-btn {
background: var(--accent);
color: white;
border: none;
border-radius: 20px;
padding: 10px 16px;
font-size: 14px;
font-weight: 600;
cursor: pointer;
transition: background-color 0.2s ease;
min-width: 60px;
}
.chatbot-send-btn:hover:not(:disabled) {
background: #0d9488;
}
.chatbot-send-btn:disabled {
background: #9ca3af;
cursor: not-allowed;
}
/* Mobile responsiveness for chatbot */
@media (max-width: 768px) {
.chatbot-container {
width: calc(100vw - 40px);
height: 400px;
bottom: 10px;
right: 10px;
left: 10px;
}
.chatbot-toggle {
bottom: 10px;
right: 10px;
padding: 10px 16px;
font-size: 13px;
}
}