parent
2006125ade
commit
eada673493
7 changed files with 544 additions and 2 deletions
226
docker/chat/ui/index.html
Normal file
226
docker/chat/ui/index.html
Normal file
|
|
@ -0,0 +1,226 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>disinto-chat</title>
|
||||
<script src="/static/htmx.min.js"></script>
|
||||
<style>
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
|
||||
background: #1a1a2e;
|
||||
color: #eaeaea;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
header {
|
||||
background: #16213e;
|
||||
padding: 1rem 2rem;
|
||||
border-bottom: 1px solid #0f3460;
|
||||
}
|
||||
header h1 {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
main {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
max-width: 900px;
|
||||
margin: 0 auto;
|
||||
width: 100%;
|
||||
padding: 1rem;
|
||||
}
|
||||
#messages {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 1rem;
|
||||
background: #16213e;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
.message {
|
||||
margin-bottom: 1rem;
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: 8px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.message.user {
|
||||
background: #0f3460;
|
||||
margin-left: 2rem;
|
||||
}
|
||||
.message.assistant {
|
||||
background: #1a1a2e;
|
||||
margin-right: 2rem;
|
||||
}
|
||||
.message.system {
|
||||
background: #1a1a2e;
|
||||
font-style: italic;
|
||||
color: #888;
|
||||
text-align: center;
|
||||
}
|
||||
.message .role {
|
||||
font-weight: 600;
|
||||
font-size: 0.875rem;
|
||||
margin-bottom: 0.25rem;
|
||||
opacity: 0.8;
|
||||
}
|
||||
.message .content {
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
.input-area {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
padding: 1rem;
|
||||
background: #16213e;
|
||||
border-radius: 8px;
|
||||
}
|
||||
textarea {
|
||||
flex: 1;
|
||||
background: #1a1a2e;
|
||||
border: 1px solid #0f3460;
|
||||
border-radius: 6px;
|
||||
padding: 0.75rem;
|
||||
color: #eaeaea;
|
||||
font-family: inherit;
|
||||
font-size: 1rem;
|
||||
resize: none;
|
||||
min-height: 80px;
|
||||
}
|
||||
textarea:focus {
|
||||
outline: none;
|
||||
border-color: #e94560;
|
||||
}
|
||||
button {
|
||||
background: #e94560;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
padding: 0.75rem 1.5rem;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
button:hover {
|
||||
background: #d63447;
|
||||
}
|
||||
button:disabled {
|
||||
background: #555;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.loading {
|
||||
opacity: 0.6;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>disinto-chat</h1>
|
||||
</header>
|
||||
<main>
|
||||
<div id="messages">
|
||||
<div class="message system">
|
||||
<div class="role">system</div>
|
||||
<div class="content">Welcome to disinto-chat. Type a message to start chatting with Claude.</div>
|
||||
</div>
|
||||
</div>
|
||||
<form class="input-area" hx-post="/chat" hx-swap="none" hx-target="#messages">
|
||||
<textarea name="message" placeholder="Type your message..." required></textarea>
|
||||
<button type="submit" id="send-btn">Send</button>
|
||||
</form>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
const messagesDiv = document.getElementById('messages');
|
||||
const sendBtn = document.getElementById('send-btn');
|
||||
const textarea = document.querySelector('textarea');
|
||||
|
||||
function addMessage(role, content, streaming = false) {
|
||||
const msgDiv = document.createElement('div');
|
||||
msgDiv.className = `message ${role}`;
|
||||
msgDiv.innerHTML = `
|
||||
<div class="role">${role}</div>
|
||||
<div class="content${streaming ? ' streaming' : ''}">${escapeHtml(content)}</div>
|
||||
`;
|
||||
messagesDiv.appendChild(msgDiv);
|
||||
messagesDiv.scrollTop = messagesDiv.scrollHeight;
|
||||
return msgDiv.querySelector('.content');
|
||||
}
|
||||
|
||||
function escapeHtml(text) {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = text;
|
||||
return div.innerHTML.replace(/\n/g, '<br>');
|
||||
}
|
||||
|
||||
// Handle HTMX swap for streaming responses
|
||||
document.body.addEventListener('htmx:afterSwap', function(event) {
|
||||
const newContent = event.detail.xhr.responseText;
|
||||
// HTMX will handle the swap; we just need to scroll to bottom
|
||||
messagesDiv.scrollTop = messagesDiv.scrollHeight;
|
||||
});
|
||||
|
||||
// Send message handler
|
||||
sendBtn.addEventListener('click', async () => {
|
||||
const message = textarea.value.trim();
|
||||
if (!message) return;
|
||||
|
||||
// Disable input
|
||||
textarea.disabled = true;
|
||||
sendBtn.disabled = true;
|
||||
sendBtn.textContent = 'Sending...';
|
||||
|
||||
// Add user message
|
||||
addMessage('user', message);
|
||||
textarea.value = '';
|
||||
|
||||
try {
|
||||
// Use fetch for better control over streaming
|
||||
const formData = new FormData();
|
||||
formData.append('message', message);
|
||||
|
||||
const response = await fetch('/chat', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
}
|
||||
|
||||
// Read the response as text and add assistant message
|
||||
const content = await response.text();
|
||||
addMessage('assistant', content);
|
||||
|
||||
} catch (error) {
|
||||
addMessage('system', `Error: ${error.message}`);
|
||||
} finally {
|
||||
textarea.disabled = false;
|
||||
sendBtn.disabled = false;
|
||||
sendBtn.textContent = 'Send';
|
||||
textarea.focus();
|
||||
messagesDiv.scrollTop = messagesDiv.scrollHeight;
|
||||
}
|
||||
});
|
||||
|
||||
// Handle Enter key in textarea
|
||||
textarea.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Enter' && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
sendBtn.click();
|
||||
}
|
||||
});
|
||||
|
||||
// Initial focus
|
||||
textarea.focus();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
1
docker/chat/ui/static/htmx.min.js
vendored
Normal file
1
docker/chat/ui/static/htmx.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue