mirror of
https://github.com/blackboxprogramming/blackroad.io.git
synced 2026-03-17 01:57:09 -05:00
Co-authored-by: blackboxprogramming <118287761+blackboxprogramming@users.noreply.github.com>
214 lines
6.6 KiB
HTML
214 lines
6.6 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>BlackRoad Chat - AI Powered</title>
|
||
<style>
|
||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||
:root { --gradient: linear-gradient(135deg, #FF9D00, #FF6B00, #FF0066, #D600AA, #7700FF, #0066FF); }
|
||
body {
|
||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||
background: #02030a;
|
||
color: white;
|
||
min-height: 100vh;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
.navbar {
|
||
background: rgba(0,0,0,0.5);
|
||
backdrop-filter: blur(20px);
|
||
padding: 16px 32px;
|
||
border-bottom: 1px solid rgba(255,255,255,0.1);
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
}
|
||
.navbar h1 {
|
||
background: var(--gradient);
|
||
-webkit-background-clip: text;
|
||
-webkit-text-fill-color: transparent;
|
||
font-size: 24px;
|
||
font-weight: 900;
|
||
}
|
||
.user-info {
|
||
background: rgba(255,255,255,0.1);
|
||
padding: 8px 16px;
|
||
border-radius: 20px;
|
||
font-size: 14px;
|
||
}
|
||
.container {
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
max-width: 1000px;
|
||
width: 100%;
|
||
margin: 0 auto;
|
||
padding: 24px;
|
||
}
|
||
.chat-messages {
|
||
flex: 1;
|
||
overflow-y: auto;
|
||
padding: 24px;
|
||
background: rgba(255,255,255,0.02);
|
||
border-radius: 16px;
|
||
margin-bottom: 24px;
|
||
}
|
||
.message {
|
||
margin-bottom: 16px;
|
||
padding: 16px;
|
||
border-radius: 12px;
|
||
}
|
||
.message.user {
|
||
background: rgba(119, 0, 255, 0.2);
|
||
margin-left: 64px;
|
||
}
|
||
.message.assistant {
|
||
background: rgba(255, 157, 0, 0.2);
|
||
margin-right: 64px;
|
||
}
|
||
.message strong {
|
||
display: block;
|
||
margin-bottom: 8px;
|
||
opacity: 0.7;
|
||
font-size: 14px;
|
||
}
|
||
.input-area {
|
||
display: flex;
|
||
gap: 16px;
|
||
}
|
||
input {
|
||
flex: 1;
|
||
padding: 16px;
|
||
border-radius: 12px;
|
||
border: 1px solid rgba(255,255,255,0.1);
|
||
background: rgba(255,255,255,0.05);
|
||
color: white;
|
||
font-size: 16px;
|
||
}
|
||
input:focus { outline: none; border-color: #7700FF; }
|
||
button {
|
||
padding: 16px 32px;
|
||
border-radius: 12px;
|
||
border: none;
|
||
background: var(--gradient);
|
||
color: white;
|
||
font-size: 16px;
|
||
font-weight: 700;
|
||
cursor: pointer;
|
||
transition: transform 0.2s;
|
||
}
|
||
button:hover { transform: scale(1.05); }
|
||
button:disabled { opacity: 0.5; cursor: not-allowed; }
|
||
.loading {
|
||
text-align: center;
|
||
padding: 16px;
|
||
opacity: 0.7;
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="navbar">
|
||
<h1>BlackRoad Chat</h1>
|
||
<div class="user-info" id="userInfo">Not logged in</div>
|
||
</div>
|
||
<div class="container">
|
||
<div class="chat-messages" id="chatMessages">
|
||
<div class="message assistant">
|
||
<strong>BlackRoad AI (powered by Ollama)</strong>
|
||
<p>Hello! I'm running on your local Ollama instance. Use <strong>@ollama</strong>, <strong>@copilot</strong>, <strong>@lucidia</strong>, or <strong>@blackboxprogramming</strong> to talk directly to your local hardware — no external providers.</p>
|
||
</div>
|
||
</div>
|
||
<div class="input-area">
|
||
<input type="text" id="messageInput" placeholder="Type your message… use @ollama, @copilot, @lucidia, or @blackboxprogramming to talk to your local Ollama" />
|
||
<button onclick="sendMessage()" id="sendBtn">Send</button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- BlackRoad Unified API -->
|
||
<script src="/blackroad-api.js"></script>
|
||
<script>
|
||
const chatMessages = document.getElementById('chatMessages');
|
||
const messageInput = document.getElementById('messageInput');
|
||
const sendBtn = document.getElementById('sendBtn');
|
||
let conversationId = null;
|
||
let ollamaHistory = [];
|
||
|
||
// @ mentions that route to local Ollama
|
||
const OLLAMA_MENTION = /@(copilot|lucidia|blackboxprogramming|ollama)\b/i;
|
||
|
||
// Check auth status
|
||
async function checkAuth() {
|
||
if (!window.blackroad.isAuthenticated()) {
|
||
document.getElementById('userInfo').textContent = 'Guest Mode';
|
||
return;
|
||
}
|
||
try {
|
||
const user = await window.blackroad.loadCurrentUser();
|
||
document.getElementById('userInfo').textContent = user?.name || user?.email || 'User';
|
||
} catch (error) {
|
||
console.error('Auth check failed:', error);
|
||
}
|
||
}
|
||
|
||
async function sendMessage() {
|
||
const message = messageInput.value.trim();
|
||
if (!message) return;
|
||
|
||
// Add user message to chat
|
||
addMessage('user', 'You', message);
|
||
messageInput.value = '';
|
||
sendBtn.disabled = true;
|
||
|
||
// Show loading
|
||
const loadingId = addMessage('assistant', 'BlackRoad AI', '<div class="loading">Thinking…</div>');
|
||
|
||
const usesOllama = OLLAMA_MENTION.test(message);
|
||
|
||
try {
|
||
let responseText;
|
||
if (usesOllama) {
|
||
// Route directly to local Ollama – no external provider
|
||
responseText = await window.blackroad.ollamaChat(message, 'llama3', ollamaHistory);
|
||
ollamaHistory.push({ role: 'user', content: message });
|
||
ollamaHistory.push({ role: 'assistant', content: responseText });
|
||
document.getElementById(loadingId).remove();
|
||
addMessage('assistant', '🦙 Ollama (local)', responseText);
|
||
} else {
|
||
// Route through backend (which also calls Ollama)
|
||
const data = await window.blackroad.chat(message, conversationId);
|
||
conversationId = data.conversation_id;
|
||
document.getElementById(loadingId).remove();
|
||
const label = data.provider === 'ollama' ? '🦙 Ollama (local)' : 'BlackRoad AI';
|
||
addMessage('assistant', label, data.message || 'I received your message!');
|
||
}
|
||
} catch (error) {
|
||
document.getElementById(loadingId).remove();
|
||
addMessage('assistant', 'BlackRoad AI', 'Sorry, I encountered an error. Please try again.');
|
||
} finally {
|
||
sendBtn.disabled = false;
|
||
}
|
||
}
|
||
|
||
function addMessage(type, sender, text) {
|
||
const id = 'msg-' + Date.now();
|
||
const msgDiv = document.createElement('div');
|
||
msgDiv.id = id;
|
||
msgDiv.className = `message ${type}`;
|
||
msgDiv.innerHTML = `<strong>${sender}</strong><p>${text}</p>`;
|
||
chatMessages.appendChild(msgDiv);
|
||
chatMessages.scrollTop = chatMessages.scrollHeight;
|
||
return id;
|
||
}
|
||
|
||
// Enter key to send
|
||
messageInput.addEventListener('keypress', (e) => {
|
||
if (e.key === 'Enter') sendMessage();
|
||
});
|
||
|
||
// Check auth on load
|
||
checkAuth();
|
||
</script>
|
||
</body>
|
||
</html>
|