add viewer
This commit is contained in:
394
static/viewer.html
Normal file
394
static/viewer.html
Normal file
@@ -0,0 +1,394 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Conversation Viewer</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
/* Left Sidebar - Conversation List */
|
||||
.sidebar {
|
||||
width: 300px;
|
||||
background-color: #2c3e50;
|
||||
color: white;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border-right: 1px solid #34495e;
|
||||
}
|
||||
|
||||
.sidebar-header {
|
||||
padding: 20px;
|
||||
background-color: #34495e;
|
||||
border-bottom: 1px solid #2c3e50;
|
||||
}
|
||||
|
||||
.sidebar-header h1 {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.conversation-list {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.conversation-item {
|
||||
padding: 12px 15px;
|
||||
margin-bottom: 8px;
|
||||
background-color: #34495e;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
border: 2px solid transparent;
|
||||
}
|
||||
|
||||
.conversation-item:hover {
|
||||
background-color: #3d566e;
|
||||
transform: translateX(2px);
|
||||
}
|
||||
|
||||
.conversation-item.active {
|
||||
background-color: #3498db;
|
||||
border-color: #2980b9;
|
||||
}
|
||||
|
||||
.conversation-id {
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
margin-bottom: 4px;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.conversation-meta {
|
||||
font-size: 12px;
|
||||
opacity: 0.8;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.message-count {
|
||||
background-color: rgba(255, 255, 255, 0.2);
|
||||
padding: 2px 8px;
|
||||
border-radius: 12px;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
/* Main Content Area */
|
||||
.main-content {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
.chat-header {
|
||||
padding: 20px;
|
||||
background-color: #ecf0f1;
|
||||
border-bottom: 1px solid #bdc3c7;
|
||||
}
|
||||
|
||||
.chat-header h2 {
|
||||
font-size: 18px;
|
||||
color: #2c3e50;
|
||||
}
|
||||
|
||||
.chat-header .conversation-id-display {
|
||||
font-size: 14px;
|
||||
color: #7f8c8d;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.messages-container {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 20px;
|
||||
background: linear-gradient(to bottom, #f8f9fa, #ffffff);
|
||||
}
|
||||
|
||||
.message {
|
||||
margin-bottom: 16px;
|
||||
display: flex;
|
||||
animation: fadeIn 0.3s ease-in;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(10px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.message.human {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.message.ai,
|
||||
.message.tool {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.message-bubble {
|
||||
max-width: 70%;
|
||||
padding: 12px 16px;
|
||||
border-radius: 18px;
|
||||
word-wrap: break-word;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.message.human .message-bubble {
|
||||
background-color: #3498db;
|
||||
color: white;
|
||||
border-bottom-right-radius: 4px;
|
||||
}
|
||||
|
||||
.message.ai .message-bubble {
|
||||
background-color: #e8f5e9;
|
||||
color: #2c3e50;
|
||||
border-bottom-left-radius: 4px;
|
||||
}
|
||||
|
||||
.message.tool .message-bubble {
|
||||
background-color: #fff3e0;
|
||||
color: #2c3e50;
|
||||
border-bottom-left-radius: 4px;
|
||||
border-left: 3px solid #ff9800;
|
||||
}
|
||||
|
||||
.message-type-label {
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
margin-bottom: 4px;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.message-content {
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.message-time {
|
||||
font-size: 11px;
|
||||
opacity: 0.6;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
color: #95a5a6;
|
||||
}
|
||||
|
||||
.empty-state-icon {
|
||||
font-size: 48px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.loading {
|
||||
text-align: center;
|
||||
padding: 40px;
|
||||
color: #7f8c8d;
|
||||
}
|
||||
|
||||
.error {
|
||||
background-color: #fee;
|
||||
color: #c33;
|
||||
padding: 12px;
|
||||
margin: 10px;
|
||||
border-radius: 4px;
|
||||
border-left: 4px solid #c33;
|
||||
}
|
||||
|
||||
/* Scrollbar styling */
|
||||
.conversation-list::-webkit-scrollbar,
|
||||
.messages-container::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
}
|
||||
|
||||
.conversation-list::-webkit-scrollbar-track,
|
||||
.messages-container::-webkit-scrollbar-track {
|
||||
background: #2c3e50;
|
||||
}
|
||||
|
||||
.conversation-list::-webkit-scrollbar-thumb {
|
||||
background: #34495e;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.messages-container::-webkit-scrollbar-track {
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.messages-container::-webkit-scrollbar-thumb {
|
||||
background: #bdc3c7;
|
||||
border-radius: 4px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<!-- Left Sidebar -->
|
||||
<div class="sidebar">
|
||||
<div class="sidebar-header">
|
||||
<h1>💬 Conversations</h1>
|
||||
</div>
|
||||
<div class="conversation-list" id="conversationList">
|
||||
<div class="loading">Loading conversations...</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Main Content -->
|
||||
<div class="main-content">
|
||||
<div class="chat-header">
|
||||
<h2>Conversation Messages</h2>
|
||||
<div class="conversation-id-display" id="conversationIdDisplay">Select a conversation to view messages</div>
|
||||
</div>
|
||||
<div class="messages-container" id="messagesContainer">
|
||||
<div class="empty-state">
|
||||
<div class="empty-state-icon">👈</div>
|
||||
<div>Select a conversation from the left to view messages</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const API_BASE = window.location.origin;
|
||||
let currentConversationId = null;
|
||||
|
||||
// Load conversations on page load
|
||||
async function loadConversations() {
|
||||
const listEl = document.getElementById('conversationList');
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/api/conversations`);
|
||||
if (!response.ok) throw new Error('Failed to load conversations');
|
||||
|
||||
const conversations = await response.json();
|
||||
|
||||
if (conversations.length === 0) {
|
||||
listEl.innerHTML = '<div class="loading">No conversations found</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
listEl.innerHTML = conversations.map(conv => `
|
||||
<div class="conversation-item" data-id="${conv.conversation_id}">
|
||||
<div class="conversation-id">${conv.conversation_id}</div>
|
||||
<div class="conversation-meta">
|
||||
<span>${formatDate(conv.last_updated)}</span>
|
||||
<span class="message-count">${conv.message_count} msgs</span>
|
||||
</div>
|
||||
</div>
|
||||
`).join('');
|
||||
|
||||
// Add click handlers
|
||||
listEl.querySelectorAll('.conversation-item').forEach(item => {
|
||||
item.addEventListener('click', () => {
|
||||
const convId = item.dataset.id;
|
||||
selectConversation(convId);
|
||||
});
|
||||
});
|
||||
|
||||
// Select first conversation by default
|
||||
if (conversations.length > 0) {
|
||||
selectConversation(conversations[0].conversation_id);
|
||||
}
|
||||
} catch (error) {
|
||||
listEl.innerHTML = `<div class="error">Error loading conversations: ${error.message}</div>`;
|
||||
console.error('Error loading conversations:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Select a conversation and load its messages
|
||||
async function selectConversation(conversationId) {
|
||||
currentConversationId = conversationId;
|
||||
|
||||
// Update UI
|
||||
document.querySelectorAll('.conversation-item').forEach(item => {
|
||||
item.classList.toggle('active', item.dataset.id === conversationId);
|
||||
});
|
||||
|
||||
document.getElementById('conversationIdDisplay').textContent = conversationId;
|
||||
|
||||
const container = document.getElementById('messagesContainer');
|
||||
container.innerHTML = '<div class="loading">Loading messages...</div>';
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/api/conversations/${conversationId}/messages`);
|
||||
if (!response.ok) throw new Error('Failed to load messages');
|
||||
|
||||
const messages = await response.json();
|
||||
|
||||
if (messages.length === 0) {
|
||||
container.innerHTML = '<div class="empty-state"><div>No messages in this conversation</div></div>';
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = messages.map(msg => {
|
||||
const isHuman = msg.message_type === 'human';
|
||||
const isTool = msg.message_type === 'tool';
|
||||
const alignClass = isHuman ? 'human' : (isTool ? 'tool' : 'ai');
|
||||
const typeLabel = isTool ? 'Tool' : (isHuman ? 'You' : 'AI');
|
||||
|
||||
return `
|
||||
<div class="message ${alignClass}">
|
||||
<div class="message-bubble">
|
||||
<div class="message-type-label">${typeLabel}</div>
|
||||
<div class="message-content">${escapeHtml(msg.content)}</div>
|
||||
<div class="message-time">${formatDate(msg.created_at)}</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}).join('');
|
||||
|
||||
// Scroll to bottom
|
||||
container.scrollTop = container.scrollHeight;
|
||||
} catch (error) {
|
||||
container.innerHTML = `<div class="error">Error loading messages: ${error.message}</div>`;
|
||||
console.error('Error loading messages:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Utility functions
|
||||
function formatDate(dateString) {
|
||||
if (!dateString) return 'Unknown';
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleString('en-US', {
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
});
|
||||
}
|
||||
|
||||
function escapeHtml(text) {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = text;
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
// Initialize on page load
|
||||
loadConversations();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user