Archived
feat: Major UI/UX improvements and production readiness
CI / backend-test (push) Successful in 4m9s
CI / frontend-test (push) Failing after 3m48s
CI / lint-python (push) Successful in 1m41s
CI / secret-scanning (push) Successful in 1m20s
CI / dependency-scan (push) Successful in 10m50s
CI / workflow-summary (push) Successful in 1m11s
CI / backend-test (push) Successful in 4m9s
CI / frontend-test (push) Failing after 3m48s
CI / lint-python (push) Successful in 1m41s
CI / secret-scanning (push) Successful in 1m20s
CI / dependency-scan (push) Successful in 10m50s
CI / workflow-summary (push) Successful in 1m11s
## Features Added
### Document Reference System
- Implemented numbered document references (@1, @2, etc.) with autocomplete dropdown
- Added fuzzy filename matching for @filename references
- Document filtering now prioritizes numeric refs > filename refs > all documents
- Autocomplete dropdown appears when typing @ with keyboard navigation (Up/Down, Enter/Tab, Escape)
- Document numbers displayed in UI for easy reference
### Conversation Management
- Added conversation rename functionality with inline editing
- Implemented conversation search (by title and content)
- Search box always visible, even when no conversations exist
- Export reports now replace @N references with actual filenames
### UI/UX Improvements
- Removed debug toggle button
- Improved text contrast in dark mode (better visibility)
- Made input textarea expand to full available width
- Fixed file text color for better readability
- Enhanced document display with numbered badges
### Configuration & Timeouts
- Made HTTP client timeouts configurable (connect, write, pool)
- Added .env.example with all configuration options
- Updated timeout documentation
### Developer Experience
- Added `make test-setup` target for automated test conversation creation
- Test setup script supports TEST_MESSAGE and TEST_DOCS env vars
- Improved Makefile with dev and test-setup targets
### Documentation
- Updated ARCHITECTURE.md with all new features
- Created comprehensive deployment documentation
- Added GPU VM setup guides
- Removed unnecessary markdown files (CLAUDE.md, CONTRIBUTING.md, header.jpg)
- Organized documentation in docs/ directory
### GPU VM / Ollama (Stability + GPU Offload)
- Updated GPU VM docs to reflect the working systemd environment for remote Ollama
- Standardized remote Ollama port to 11434 (and added /v1/models verification)
- Documented required env for GPU offload on this VM:
- `OLLAMA_MODELS=/mnt/data/ollama`, `HOME=/mnt/data/ollama/home`
- `OLLAMA_LLM_LIBRARY=cuda_v12` (not `cuda`)
- `LD_LIBRARY_PATH=/usr/local/lib/ollama:/usr/local/lib/ollama/cuda_v12`
## Technical Changes
### Backend
- Enhanced `docs_context.py` with reference parsing (numeric and filename)
- Added `update_conversation_title` to storage.py
- New endpoints: PATCH /api/conversations/{id}/title, GET /api/conversations/search
- Improved report generation with filename substitution
### Frontend
- Removed debugMode state and related code
- Added autocomplete dropdown component
- Implemented search functionality in Sidebar
- Enhanced ChatInterface with autocomplete and improved textarea sizing
- Updated CSS for better contrast and responsive design
## Files Changed
- Backend: config.py, council.py, docs_context.py, main.py, storage.py
- Frontend: App.jsx, ChatInterface.jsx, Sidebar.jsx, and related CSS files
- Documentation: README.md, ARCHITECTURE.md, new docs/ directory
- Configuration: .env.example, Makefile
- Scripts: scripts/test_setup.py
## Breaking Changes
None - all changes are backward compatible
## Testing
- All existing tests pass
- New test-setup script validates conversation creation workflow
- Manual testing of autocomplete, search, and rename features
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
@@ -0,0 +1,16 @@
|
||||
# React + Vite
|
||||
|
||||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
||||
|
||||
Currently, two official plugins are available:
|
||||
|
||||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
|
||||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
||||
|
||||
## React Compiler
|
||||
|
||||
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
||||
|
||||
## Expanding the ESLint configuration
|
||||
|
||||
If you are developing a production application, we recommend using TypeScript with type-aware lint rules enabled. Check out the [TS template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts) for information on how to integrate TypeScript and [`typescript-eslint`](https://typescript-eslint.io) in your project.
|
||||
@@ -0,0 +1,29 @@
|
||||
import js from '@eslint/js'
|
||||
import globals from 'globals'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
import { defineConfig, globalIgnores } from 'eslint/config'
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{js,jsx}'],
|
||||
extends: [
|
||||
js.configs.recommended,
|
||||
reactHooks.configs.flat.recommended,
|
||||
reactRefresh.configs.vite,
|
||||
],
|
||||
languageOptions: {
|
||||
ecmaVersion: 2020,
|
||||
globals: globals.browser,
|
||||
parserOptions: {
|
||||
ecmaVersion: 'latest',
|
||||
ecmaFeatures: { jsx: true },
|
||||
sourceType: 'module',
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
|
||||
},
|
||||
},
|
||||
])
|
||||
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>frontend</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.jsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
Generated
+3649
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"lint": "eslint .",
|
||||
"test": "node --test",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^19.2.0",
|
||||
"react-dom": "^19.2.0",
|
||||
"react-markdown": "^10.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.39.1",
|
||||
"@types/react": "^19.2.5",
|
||||
"@types/react-dom": "^19.2.3",
|
||||
"@vitejs/plugin-react": "^4.3.1",
|
||||
"eslint": "^9.39.1",
|
||||
"eslint-plugin-react-hooks": "^7.0.1",
|
||||
"eslint-plugin-react-refresh": "^0.4.24",
|
||||
"globals": "^16.5.0",
|
||||
"vite": "^5.4.11"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
@@ -0,0 +1,16 @@
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.app {
|
||||
display: flex;
|
||||
height: 100vh;
|
||||
width: 100vw;
|
||||
overflow: hidden;
|
||||
background: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
transition: background-color 0.2s, color 0.2s;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
}
|
||||
@@ -0,0 +1,462 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import Sidebar from './components/Sidebar';
|
||||
import ChatInterface from './components/ChatInterface';
|
||||
import { api } from './api';
|
||||
import './App.css';
|
||||
|
||||
function App() {
|
||||
// Theme state - default to light, or load from localStorage
|
||||
const [theme, setTheme] = useState(() => {
|
||||
const saved = localStorage.getItem('llm-council-theme');
|
||||
if (saved) return saved;
|
||||
const envDefault = (import.meta.env.VITE_DEFAULT_THEME || '').toLowerCase();
|
||||
if (envDefault === 'dark' || envDefault === 'light') return envDefault;
|
||||
return 'light';
|
||||
});
|
||||
const [conversations, setConversations] = useState([]);
|
||||
const [currentConversationId, setCurrentConversationId] = useState(null);
|
||||
const [currentConversation, setCurrentConversation] = useState(null);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [documents, setDocuments] = useState([]);
|
||||
const [isUploadingDoc, setIsUploadingDoc] = useState(false);
|
||||
const [selectedDoc, setSelectedDoc] = useState(null); // {id, filename, bytes}
|
||||
const [selectedDocContent, setSelectedDocContent] = useState('');
|
||||
const [isLoadingDoc, setIsLoadingDoc] = useState(false);
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const [filteredConversations, setFilteredConversations] = useState([]);
|
||||
const [prefillMessage, setPrefillMessage] = useState('');
|
||||
|
||||
// Apply theme class to document root
|
||||
useEffect(() => {
|
||||
document.documentElement.setAttribute('data-theme', theme);
|
||||
localStorage.setItem('llm-council-theme', theme);
|
||||
}, [theme]);
|
||||
|
||||
const toggleTheme = () => {
|
||||
setTheme(prev => prev === 'light' ? 'dark' : 'light');
|
||||
};
|
||||
|
||||
// Load conversations on mount
|
||||
useEffect(() => {
|
||||
loadConversations();
|
||||
}, []);
|
||||
|
||||
// Read message from URL once (used to prefill the textarea; not auto-sent)
|
||||
useEffect(() => {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const msg = urlParams.get('message');
|
||||
if (msg) setPrefillMessage(msg);
|
||||
}, []);
|
||||
|
||||
// Check for conversation ID in URL after conversations load
|
||||
useEffect(() => {
|
||||
if (conversations.length > 0) {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const convIdFromUrl = urlParams.get('conversation');
|
||||
if (convIdFromUrl && !currentConversationId) {
|
||||
const exists = conversations.some(c => c.id === convIdFromUrl);
|
||||
if (exists) {
|
||||
setCurrentConversationId(convIdFromUrl);
|
||||
} else {
|
||||
console.warn('Conversation from URL not found:', convIdFromUrl);
|
||||
alert(`Conversation not found: ${convIdFromUrl}\n\nIt may have been deleted, or you're pointing at a different data directory/server.`);
|
||||
// Remove the invalid param so we don't keep trying.
|
||||
urlParams.delete('conversation');
|
||||
const newQuery = urlParams.toString();
|
||||
const newUrl = `${window.location.pathname}${newQuery ? `?${newQuery}` : ''}${window.location.hash || ''}`;
|
||||
window.history.replaceState({}, '', newUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [conversations, currentConversationId]);
|
||||
|
||||
// Filter conversations based on search
|
||||
useEffect(() => {
|
||||
if (!searchQuery.trim()) {
|
||||
setFilteredConversations(conversations);
|
||||
return;
|
||||
}
|
||||
|
||||
const search = async () => {
|
||||
try {
|
||||
const results = await api.searchConversations(searchQuery);
|
||||
setFilteredConversations(results);
|
||||
} catch (error) {
|
||||
console.error('Search failed:', error);
|
||||
// Fallback to client-side search
|
||||
const query = searchQuery.toLowerCase();
|
||||
const filtered = conversations.filter(conv =>
|
||||
(conv.title || '').toLowerCase().includes(query)
|
||||
);
|
||||
setFilteredConversations(filtered);
|
||||
}
|
||||
};
|
||||
|
||||
const timeoutId = setTimeout(search, 300); // Debounce
|
||||
return () => clearTimeout(timeoutId);
|
||||
}, [searchQuery, conversations]);
|
||||
|
||||
// Load conversation details when selected
|
||||
useEffect(() => {
|
||||
if (currentConversationId) {
|
||||
loadConversation(currentConversationId);
|
||||
loadDocuments(currentConversationId);
|
||||
}
|
||||
}, [currentConversationId]);
|
||||
|
||||
const loadConversations = async () => {
|
||||
try {
|
||||
const convs = await api.listConversations();
|
||||
setConversations(convs);
|
||||
} catch (error) {
|
||||
console.error('Failed to load conversations:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const loadConversation = async (id) => {
|
||||
try {
|
||||
const conv = await api.getConversation(id);
|
||||
setCurrentConversation(conv);
|
||||
} catch (error) {
|
||||
console.error('Failed to load conversation:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const loadDocuments = async (id) => {
|
||||
try {
|
||||
const docs = await api.listDocuments(id);
|
||||
setDocuments(docs);
|
||||
// Clear selection if it no longer exists
|
||||
setSelectedDoc((prev) => {
|
||||
if (!prev) return prev;
|
||||
return docs.some((d) => d.id === prev.id) ? prev : null;
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Failed to load documents:', error);
|
||||
setDocuments([]);
|
||||
}
|
||||
};
|
||||
|
||||
const handleNewConversation = async () => {
|
||||
try {
|
||||
const newConv = await api.createConversation();
|
||||
setConversations([
|
||||
{ id: newConv.id, created_at: newConv.created_at, message_count: 0 },
|
||||
...conversations,
|
||||
]);
|
||||
setCurrentConversationId(newConv.id);
|
||||
} catch (error) {
|
||||
console.error('Failed to create conversation:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSelectConversation = (id) => {
|
||||
setCurrentConversationId(id);
|
||||
};
|
||||
|
||||
const handleSendMessage = async (content) => {
|
||||
if (!currentConversationId) return;
|
||||
|
||||
setIsLoading(true);
|
||||
try {
|
||||
// Optimistically add user message to UI
|
||||
const userMessage = { role: 'user', content };
|
||||
setCurrentConversation((prev) => ({
|
||||
...prev,
|
||||
messages: [...prev.messages, userMessage],
|
||||
}));
|
||||
|
||||
// Create a partial assistant message that will be updated progressively
|
||||
const assistantMessage = {
|
||||
role: 'assistant',
|
||||
stage1: null,
|
||||
stage2: null,
|
||||
stage3: null,
|
||||
metadata: null,
|
||||
loading: {
|
||||
stage1: false,
|
||||
stage2: false,
|
||||
stage3: false,
|
||||
},
|
||||
};
|
||||
|
||||
// Add the partial assistant message
|
||||
setCurrentConversation((prev) => ({
|
||||
...prev,
|
||||
messages: [...prev.messages, assistantMessage],
|
||||
}));
|
||||
|
||||
// Send message with streaming
|
||||
await api.sendMessageStream(currentConversationId, content, (eventType, event) => {
|
||||
console.log('[Stream Event]', eventType, event); // Debug logging
|
||||
switch (eventType) {
|
||||
case 'stage1_start':
|
||||
setCurrentConversation((prev) => {
|
||||
const messages = [...prev.messages];
|
||||
const lastMsg = messages[messages.length - 1];
|
||||
lastMsg.loading.stage1 = true;
|
||||
lastMsg.stage1 = []; // Initialize empty array
|
||||
return { ...prev, messages };
|
||||
});
|
||||
break;
|
||||
|
||||
case 'stage1_response':
|
||||
// Individual response completed - add it immediately
|
||||
setCurrentConversation((prev) => {
|
||||
const messages = [...prev.messages];
|
||||
const lastMsg = messages[messages.length - 1];
|
||||
if (!lastMsg.stage1) lastMsg.stage1 = [];
|
||||
// Check if this model already exists, if so update it, otherwise add it
|
||||
const existingIdx = lastMsg.stage1.findIndex(r => r.model === event.model);
|
||||
if (existingIdx >= 0) {
|
||||
lastMsg.stage1[existingIdx] = event.response;
|
||||
} else {
|
||||
lastMsg.stage1.push(event.response);
|
||||
}
|
||||
return { ...prev, messages };
|
||||
});
|
||||
break;
|
||||
|
||||
case 'stage1_complete':
|
||||
setCurrentConversation((prev) => {
|
||||
const messages = [...prev.messages];
|
||||
const lastMsg = messages[messages.length - 1];
|
||||
lastMsg.stage1 = event.data;
|
||||
if (!lastMsg.metadata) lastMsg.metadata = {};
|
||||
lastMsg.metadata.stage1_metadata = event.metadata;
|
||||
lastMsg.loading.stage1 = false;
|
||||
return { ...prev, messages };
|
||||
});
|
||||
break;
|
||||
|
||||
case 'stage2_start':
|
||||
setCurrentConversation((prev) => {
|
||||
const messages = [...prev.messages];
|
||||
const lastMsg = messages[messages.length - 1];
|
||||
lastMsg.loading.stage2 = true;
|
||||
return { ...prev, messages };
|
||||
});
|
||||
break;
|
||||
|
||||
case 'stage2_complete':
|
||||
setCurrentConversation((prev) => {
|
||||
const messages = [...prev.messages];
|
||||
const lastMsg = messages[messages.length - 1];
|
||||
lastMsg.stage2 = event.data;
|
||||
if (!lastMsg.metadata) lastMsg.metadata = {};
|
||||
lastMsg.metadata = { ...lastMsg.metadata, ...event.metadata };
|
||||
lastMsg.metadata.stage2_metadata = event.metadata.stage2_metadata;
|
||||
lastMsg.loading.stage2 = false;
|
||||
return { ...prev, messages };
|
||||
});
|
||||
break;
|
||||
|
||||
case 'stage3_start':
|
||||
setCurrentConversation((prev) => {
|
||||
const messages = [...prev.messages];
|
||||
const lastMsg = messages[messages.length - 1];
|
||||
lastMsg.loading.stage3 = true;
|
||||
return { ...prev, messages };
|
||||
});
|
||||
break;
|
||||
|
||||
case 'stage3_complete':
|
||||
setCurrentConversation((prev) => {
|
||||
const messages = [...prev.messages];
|
||||
const lastMsg = messages[messages.length - 1];
|
||||
lastMsg.stage3 = event.data;
|
||||
if (!lastMsg.metadata) lastMsg.metadata = {};
|
||||
lastMsg.metadata.stage3_metadata = event.metadata;
|
||||
if (event.metadata?.duration_seconds && lastMsg.metadata.stage1_metadata && lastMsg.metadata.stage2_metadata) {
|
||||
const total = (lastMsg.metadata.stage1_metadata.duration_seconds || 0) +
|
||||
(lastMsg.metadata.stage2_metadata.duration_seconds || 0) +
|
||||
(event.metadata.duration_seconds || 0);
|
||||
lastMsg.metadata.total_duration_seconds = Math.round(total * 100) / 100;
|
||||
}
|
||||
lastMsg.loading.stage3 = false;
|
||||
return { ...prev, messages };
|
||||
});
|
||||
break;
|
||||
|
||||
case 'title_complete':
|
||||
// Reload conversations to get updated title
|
||||
loadConversations();
|
||||
break;
|
||||
|
||||
case 'complete':
|
||||
// Stream complete, reload conversations list and current conversation
|
||||
loadConversations();
|
||||
if (currentConversationId) {
|
||||
// Reload the conversation to get the saved assistant message
|
||||
setTimeout(() => {
|
||||
loadConversation(currentConversationId);
|
||||
}, 100);
|
||||
}
|
||||
setIsLoading(false);
|
||||
break;
|
||||
|
||||
case 'error':
|
||||
console.error('Stream error:', event.message);
|
||||
alert(`Error: ${event.message}`);
|
||||
setIsLoading(false);
|
||||
break;
|
||||
|
||||
case 'stage1_response_failed':
|
||||
// Model failed - show notification
|
||||
setCurrentConversation((prev) => {
|
||||
const messages = [...prev.messages];
|
||||
const lastMsg = messages[messages.length - 1];
|
||||
if (!lastMsg.failed_models) lastMsg.failed_models = [];
|
||||
if (!lastMsg.failed_models.includes(event.model)) {
|
||||
lastMsg.failed_models.push(event.model);
|
||||
}
|
||||
return { ...prev, messages };
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
console.log('Unknown event type:', eventType);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Failed to send message:', error);
|
||||
// Remove optimistic messages on error
|
||||
setCurrentConversation((prev) => ({
|
||||
...prev,
|
||||
messages: prev.messages.slice(0, -2),
|
||||
}));
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleUploadDocument = async (files) => {
|
||||
if (!currentConversationId) return;
|
||||
setIsUploadingDoc(true);
|
||||
try {
|
||||
const list = Array.isArray(files) ? files : [files];
|
||||
if (list.length <= 1) {
|
||||
await api.uploadDocument(currentConversationId, list[0]);
|
||||
} else {
|
||||
await api.uploadDocuments(currentConversationId, list);
|
||||
}
|
||||
await loadDocuments(currentConversationId);
|
||||
} catch (error) {
|
||||
console.error('Failed to upload document:', error);
|
||||
alert(error?.message || 'Failed to upload document');
|
||||
} finally {
|
||||
setIsUploadingDoc(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleViewDocument = async (doc) => {
|
||||
if (!currentConversationId) return;
|
||||
setSelectedDoc(doc);
|
||||
setIsLoadingDoc(true);
|
||||
try {
|
||||
const res = await api.getDocument(currentConversationId, doc.id);
|
||||
setSelectedDocContent(res.content || '');
|
||||
} catch (error) {
|
||||
console.error('Failed to get document:', error);
|
||||
alert(error?.message || 'Failed to load document');
|
||||
setSelectedDoc(null);
|
||||
setSelectedDocContent('');
|
||||
} finally {
|
||||
setIsLoadingDoc(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDeleteDocument = async (doc) => {
|
||||
if (!currentConversationId) return;
|
||||
const ok = confirm(`Delete ${doc.filename}?`);
|
||||
if (!ok) return;
|
||||
|
||||
try {
|
||||
await api.deleteDocument(currentConversationId, doc.id);
|
||||
await loadDocuments(currentConversationId);
|
||||
if (selectedDoc?.id === doc.id) {
|
||||
setSelectedDoc(null);
|
||||
setSelectedDocContent('');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to delete document:', error);
|
||||
alert(error?.message || 'Failed to delete document');
|
||||
}
|
||||
};
|
||||
|
||||
const handleExportReport = async () => {
|
||||
if (!currentConversationId) return;
|
||||
try {
|
||||
await api.exportConversation(currentConversationId);
|
||||
} catch (error) {
|
||||
console.error('Failed to export conversation:', error);
|
||||
alert(error?.message || 'Failed to export conversation');
|
||||
}
|
||||
};
|
||||
|
||||
const handleDeleteConversation = async (conversationId, e) => {
|
||||
e.stopPropagation(); // Prevent selecting the conversation when clicking delete
|
||||
const ok = confirm('Delete this conversation? This cannot be undone.');
|
||||
if (!ok) return;
|
||||
|
||||
try {
|
||||
await api.deleteConversation(conversationId);
|
||||
await loadConversations();
|
||||
if (currentConversationId === conversationId) {
|
||||
setCurrentConversationId(null);
|
||||
setCurrentConversation(null);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to delete conversation:', error);
|
||||
alert(error?.message || 'Failed to delete conversation');
|
||||
}
|
||||
};
|
||||
|
||||
const handleRenameConversation = async (conversationId, newTitle) => {
|
||||
try {
|
||||
await api.updateConversationTitle(conversationId, newTitle);
|
||||
await loadConversations();
|
||||
// Update current conversation if it's the one being renamed
|
||||
if (currentConversationId === conversationId) {
|
||||
await loadConversation(conversationId);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to rename conversation:', error);
|
||||
alert(error?.message || 'Failed to rename conversation');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={`app ${theme}`}>
|
||||
<Sidebar
|
||||
conversations={searchQuery ? filteredConversations : conversations}
|
||||
currentConversationId={currentConversationId}
|
||||
onSelectConversation={handleSelectConversation}
|
||||
onNewConversation={handleNewConversation}
|
||||
onDeleteConversation={handleDeleteConversation}
|
||||
onRenameConversation={handleRenameConversation}
|
||||
theme={theme}
|
||||
onToggleTheme={toggleTheme}
|
||||
searchQuery={searchQuery}
|
||||
onSearchChange={setSearchQuery}
|
||||
/>
|
||||
<ChatInterface
|
||||
conversation={currentConversation}
|
||||
onSendMessage={handleSendMessage}
|
||||
isLoading={isLoading}
|
||||
prefillMessage={prefillMessage}
|
||||
onPrefillConsumed={() => setPrefillMessage('')}
|
||||
documents={documents}
|
||||
isUploadingDoc={isUploadingDoc}
|
||||
onUploadDocument={handleUploadDocument}
|
||||
selectedDoc={selectedDoc}
|
||||
selectedDocContent={selectedDocContent}
|
||||
isLoadingDoc={isLoadingDoc}
|
||||
onViewDocument={handleViewDocument}
|
||||
onDeleteDocument={handleDeleteDocument}
|
||||
onExportReport={handleExportReport}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
@@ -0,0 +1,286 @@
|
||||
/**
|
||||
* API client for the LLM Council backend.
|
||||
*/
|
||||
|
||||
const API_BASE = 'http://localhost:8001';
|
||||
|
||||
export const api = {
|
||||
/**
|
||||
* List all conversations.
|
||||
*/
|
||||
async listConversations() {
|
||||
const response = await fetch(`${API_BASE}/api/conversations`);
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to list conversations');
|
||||
}
|
||||
return response.json();
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a new conversation.
|
||||
*/
|
||||
async createConversation() {
|
||||
const response = await fetch(`${API_BASE}/api/conversations`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({}),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to create conversation');
|
||||
}
|
||||
return response.json();
|
||||
},
|
||||
|
||||
/**
|
||||
* Get a specific conversation.
|
||||
*/
|
||||
async getConversation(conversationId) {
|
||||
const response = await fetch(
|
||||
`${API_BASE}/api/conversations/${conversationId}`
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to get conversation');
|
||||
}
|
||||
return response.json();
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete a conversation.
|
||||
*/
|
||||
async deleteConversation(conversationId) {
|
||||
const response = await fetch(
|
||||
`${API_BASE}/api/conversations/${conversationId}`,
|
||||
{ method: 'DELETE' }
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to delete conversation');
|
||||
}
|
||||
return response.json();
|
||||
},
|
||||
|
||||
/**
|
||||
* Update conversation title.
|
||||
*/
|
||||
async updateConversationTitle(conversationId, title) {
|
||||
const response = await fetch(
|
||||
`${API_BASE}/api/conversations/${conversationId}/title`,
|
||||
{
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ title }),
|
||||
}
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to update conversation title');
|
||||
}
|
||||
return response.json();
|
||||
},
|
||||
|
||||
/**
|
||||
* Search conversations by title and content.
|
||||
*/
|
||||
async searchConversations(query) {
|
||||
const response = await fetch(
|
||||
`${API_BASE}/api/conversations/search?q=${encodeURIComponent(query)}`
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to search conversations');
|
||||
}
|
||||
return response.json();
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* List uploaded markdown documents for a conversation.
|
||||
*/
|
||||
async listDocuments(conversationId) {
|
||||
const response = await fetch(
|
||||
`${API_BASE}/api/conversations/${conversationId}/documents`
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to list documents');
|
||||
}
|
||||
return response.json();
|
||||
},
|
||||
|
||||
/**
|
||||
* Upload a markdown (.md) document for a conversation.
|
||||
*/
|
||||
async uploadDocument(conversationId, file) {
|
||||
// Keep single-file backward compatibility (server accepts "file")
|
||||
const form = new FormData();
|
||||
// Support both File and Blob (handy for tests and some environments)
|
||||
form.append('file', file, file?.name || 'document.md');
|
||||
|
||||
const response = await fetch(
|
||||
`${API_BASE}/api/conversations/${conversationId}/documents`,
|
||||
{
|
||||
method: 'POST',
|
||||
body: form,
|
||||
}
|
||||
);
|
||||
if (!response.ok) {
|
||||
const text = await response.text().catch(() => '');
|
||||
throw new Error(text || 'Failed to upload document');
|
||||
}
|
||||
return response.json();
|
||||
},
|
||||
|
||||
/**
|
||||
* Upload multiple markdown (.md) documents for a conversation in one request.
|
||||
* Returns either { uploaded: [...] } or a single {id, filename, bytes} if only one file was uploaded.
|
||||
*/
|
||||
async uploadDocuments(conversationId, files) {
|
||||
const list = Array.isArray(files) ? files : [files];
|
||||
const form = new FormData();
|
||||
for (const f of list) {
|
||||
form.append('files', f, f?.name || 'document.md');
|
||||
}
|
||||
|
||||
const response = await fetch(
|
||||
`${API_BASE}/api/conversations/${conversationId}/documents`,
|
||||
{
|
||||
method: 'POST',
|
||||
body: form,
|
||||
}
|
||||
);
|
||||
if (!response.ok) {
|
||||
const text = await response.text().catch(() => '');
|
||||
throw new Error(text || 'Failed to upload documents');
|
||||
}
|
||||
return response.json();
|
||||
},
|
||||
|
||||
/**
|
||||
* Fetch a document's markdown content.
|
||||
*/
|
||||
async getDocument(conversationId, docId) {
|
||||
const response = await fetch(
|
||||
`${API_BASE}/api/conversations/${conversationId}/documents/${docId}`
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to get document');
|
||||
}
|
||||
return response.json();
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete a document.
|
||||
*/
|
||||
async deleteDocument(conversationId, docId) {
|
||||
const response = await fetch(
|
||||
`${API_BASE}/api/conversations/${conversationId}/documents/${docId}`,
|
||||
{ method: 'DELETE' }
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to delete document');
|
||||
}
|
||||
return response.json();
|
||||
},
|
||||
|
||||
/**
|
||||
* Export conversation as markdown report.
|
||||
*/
|
||||
async exportConversation(conversationId) {
|
||||
const response = await fetch(
|
||||
`${API_BASE}/api/conversations/${conversationId}/export`
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to export conversation');
|
||||
}
|
||||
const blob = await response.blob();
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
const contentDisposition = response.headers.get('Content-Disposition');
|
||||
if (contentDisposition) {
|
||||
const filenameMatch = contentDisposition.match(/filename="(.+)"/);
|
||||
if (filenameMatch) {
|
||||
a.download = filenameMatch[1];
|
||||
}
|
||||
} else {
|
||||
a.download = `conversation_${conversationId}.md`;
|
||||
}
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
document.body.removeChild(a);
|
||||
},
|
||||
|
||||
/**
|
||||
* Send a message in a conversation.
|
||||
*/
|
||||
async sendMessage(conversationId, content) {
|
||||
const response = await fetch(
|
||||
`${API_BASE}/api/conversations/${conversationId}/message`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ content }),
|
||||
}
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to send message');
|
||||
}
|
||||
return response.json();
|
||||
},
|
||||
|
||||
/**
|
||||
* Send a message and receive streaming updates.
|
||||
* @param {string} conversationId - The conversation ID
|
||||
* @param {string} content - The message content
|
||||
* @param {function} onEvent - Callback function for each event: (eventType, data) => void
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async sendMessageStream(conversationId, content, onEvent) {
|
||||
const response = await fetch(
|
||||
`${API_BASE}/api/conversations/${conversationId}/message/stream`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ content }),
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to send message');
|
||||
}
|
||||
|
||||
const reader = response.body.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) {
|
||||
console.log('[Stream] Done reading');
|
||||
break;
|
||||
}
|
||||
|
||||
const chunk = decoder.decode(value);
|
||||
const lines = chunk.split('\n');
|
||||
|
||||
for (const line of lines) {
|
||||
if (line.startsWith('data: ')) {
|
||||
const data = line.slice(6);
|
||||
try {
|
||||
const event = JSON.parse(data);
|
||||
console.log('[Stream] Received event:', event.type);
|
||||
onEvent(event.type, event);
|
||||
} catch (e) {
|
||||
console.error('Failed to parse SSE event:', e, 'Raw data:', data);
|
||||
}
|
||||
} else if (line.trim()) {
|
||||
console.log('[Stream] Non-data line:', line);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
@@ -0,0 +1,460 @@
|
||||
.chat-interface {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
background: var(--bg-primary);
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.docs-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 14px 16px;
|
||||
border-bottom: 1px solid var(--border-light);
|
||||
background: var(--bg-tertiary);
|
||||
transition: background-color 0.2s, border-color 0.2s;
|
||||
}
|
||||
|
||||
.docs-left {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.docs-title {
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.4px;
|
||||
text-transform: uppercase;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.docs-subtitle {
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.docs-right {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.docs-export-btn,
|
||||
.docs-upload-btn {
|
||||
padding: 10px 14px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--border-color);
|
||||
background: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
transition: background-color 0.2s, border-color 0.2s;
|
||||
}
|
||||
|
||||
.docs-export-btn:hover,
|
||||
.docs-upload-btn:hover {
|
||||
background: var(--hover-bg);
|
||||
}
|
||||
|
||||
.docs-upload-btn:disabled,
|
||||
.docs-export-btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.docs-list {
|
||||
padding: 10px 16px;
|
||||
border-bottom: 1px solid var(--border-light);
|
||||
background: var(--bg-primary);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
transition: background-color 0.2s, border-color 0.2s;
|
||||
}
|
||||
|
||||
.doc-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
font-size: 13px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.doc-name-btn {
|
||||
font-weight: 700;
|
||||
border: 1px solid transparent;
|
||||
background: transparent;
|
||||
padding: 4px 8px;
|
||||
border-radius: 8px;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.doc-number {
|
||||
font-weight: 600;
|
||||
color: #4a90e2;
|
||||
font-size: 12px;
|
||||
background: rgba(74, 144, 226, 0.1);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.doc-name-btn:hover {
|
||||
background: var(--hover-bg);
|
||||
}
|
||||
|
||||
.doc-name-btn.active {
|
||||
border-color: var(--border-hover);
|
||||
background: var(--hover-bg-light);
|
||||
}
|
||||
|
||||
.doc-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.doc-bytes {
|
||||
color: var(--text-secondary);
|
||||
font-variant-numeric: tabular-nums;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.doc-delete-btn {
|
||||
padding: 6px 10px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--border-color);
|
||||
background: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
cursor: pointer;
|
||||
font-weight: 600;
|
||||
transition: background-color 0.2s, border-color 0.2s;
|
||||
}
|
||||
|
||||
.doc-delete-btn:hover {
|
||||
border-color: #ffb4b4;
|
||||
background: #fff5f5;
|
||||
}
|
||||
|
||||
.doc-preview {
|
||||
border-bottom: 1px solid var(--border-light);
|
||||
background: var(--bg-primary);
|
||||
transition: background-color 0.2s, border-color 0.2s;
|
||||
}
|
||||
|
||||
.doc-preview-header {
|
||||
padding: 10px 16px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
border-bottom: 1px solid var(--border-light);
|
||||
}
|
||||
|
||||
.doc-preview-title {
|
||||
font-weight: 800;
|
||||
font-size: 13px;
|
||||
color: var(--text-primary);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.doc-preview-meta {
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.doc-preview-body {
|
||||
padding: 12px 16px;
|
||||
max-height: 240px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.doc-preview-loading {
|
||||
color: var(--text-secondary);
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.messages-container {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
color: var(--text-secondary);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.empty-state h2 {
|
||||
margin: 0 0 8px 0;
|
||||
font-size: 24px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.empty-state p {
|
||||
margin: 0;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.message-group {
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
|
||||
.user-message,
|
||||
.assistant-message {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.message-label {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary);
|
||||
margin-bottom: 8px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.user-message .message-content {
|
||||
background: var(--hover-bg-light);
|
||||
padding: 16px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--border-hover);
|
||||
color: var(--text-primary);
|
||||
transition: background-color 0.2s, border-color 0.2s;
|
||||
line-height: 1.6;
|
||||
max-width: 80%;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.loading-indicator {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 16px;
|
||||
color: var(--text-secondary);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.stage-loading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 16px;
|
||||
margin: 12px 0;
|
||||
background: var(--bg-secondary);
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--border-color);
|
||||
color: var(--text-secondary);
|
||||
font-size: 14px;
|
||||
font-style: italic;
|
||||
transition: background-color 0.2s, border-color 0.2s;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border: 2px solid #e0e0e0;
|
||||
border-top-color: #4a90e2;
|
||||
border-radius: 50%;
|
||||
animation: spin 0.8s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
.input-form {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
gap: 12px;
|
||||
padding: 24px;
|
||||
border-top: 1px solid var(--border-color);
|
||||
background: var(--bg-secondary);
|
||||
transition: background-color 0.2s, border-color 0.2s;
|
||||
}
|
||||
|
||||
.input-wrapper {
|
||||
flex: 1;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.message-input {
|
||||
width: 100%;
|
||||
padding: 16px;
|
||||
background: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 8px;
|
||||
transition: background-color 0.2s, border-color 0.2s, color 0.2s;
|
||||
font-size: 16px;
|
||||
font-family: inherit;
|
||||
line-height: 1.6;
|
||||
outline: none;
|
||||
resize: vertical;
|
||||
min-height: 120px;
|
||||
max-height: 400px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.message-input:focus {
|
||||
border-color: #4a90e2;
|
||||
box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
|
||||
}
|
||||
|
||||
.message-input:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
background: var(--bg-secondary);
|
||||
}
|
||||
|
||||
.send-button {
|
||||
padding: 14px 28px;
|
||||
background: #4a90e2;
|
||||
border: 1px solid #4a90e2;
|
||||
border-radius: 8px;
|
||||
color: #fff;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
white-space: nowrap;
|
||||
align-self: flex-end;
|
||||
}
|
||||
|
||||
.send-button:hover:not(:disabled) {
|
||||
background: #357abd;
|
||||
border-color: #357abd;
|
||||
}
|
||||
|
||||
.send-button:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
background: #ccc;
|
||||
border-color: #ccc;
|
||||
}
|
||||
|
||||
.debug-console {
|
||||
border-top: 2px solid var(--border-color);
|
||||
background: var(--bg-secondary);
|
||||
max-height: 300px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
transition: background-color 0.2s, border-color 0.2s;
|
||||
}
|
||||
|
||||
.debug-console-header {
|
||||
padding: 8px 12px;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.debug-console-header button {
|
||||
padding: 4px 8px;
|
||||
font-size: 11px;
|
||||
background: var(--bg-primary);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 4px;
|
||||
color: var(--text-primary);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.debug-console-content {
|
||||
flex: 1;
|
||||
overflow: auto;
|
||||
padding: 12px;
|
||||
font-size: 11px;
|
||||
font-family: monospace;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.debug-console-content pre {
|
||||
margin: 0;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.input-wrapper {
|
||||
flex: 1;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.autocomplete-dropdown {
|
||||
position: absolute;
|
||||
background: var(--bg-primary);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||
z-index: 1000;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
min-width: 300px;
|
||||
bottom: calc(100% + 8px);
|
||||
left: 0;
|
||||
}
|
||||
|
||||
.autocomplete-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 10px 12px;
|
||||
cursor: pointer;
|
||||
border-bottom: 1px solid var(--border-light);
|
||||
transition: background-color 0.15s;
|
||||
}
|
||||
|
||||
.autocomplete-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.autocomplete-item:hover,
|
||||
.autocomplete-item.selected {
|
||||
background: var(--hover-bg);
|
||||
}
|
||||
|
||||
.autocomplete-number {
|
||||
font-weight: 600;
|
||||
color: #4a90e2;
|
||||
font-size: 13px;
|
||||
background: rgba(74, 144, 226, 0.1);
|
||||
padding: 3px 8px;
|
||||
border-radius: 4px;
|
||||
flex-shrink: 0;
|
||||
min-width: 32px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.autocomplete-filename {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-size: 14px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
@@ -0,0 +1,424 @@
|
||||
import { useState, useEffect, useRef } from 'react';
|
||||
import ReactMarkdown from 'react-markdown';
|
||||
import Stage1 from './Stage1';
|
||||
import Stage2 from './Stage2';
|
||||
import Stage3 from './Stage3';
|
||||
import './ChatInterface.css';
|
||||
|
||||
export default function ChatInterface({
|
||||
conversation,
|
||||
onSendMessage,
|
||||
isLoading,
|
||||
prefillMessage = '',
|
||||
onPrefillConsumed,
|
||||
documents = [],
|
||||
isUploadingDoc = false,
|
||||
onUploadDocument,
|
||||
selectedDoc = null,
|
||||
selectedDocContent = '',
|
||||
isLoadingDoc = false,
|
||||
onViewDocument,
|
||||
onDeleteDocument,
|
||||
onExportReport,
|
||||
}) {
|
||||
const [input, setInput] = useState('');
|
||||
const [showAutocomplete, setShowAutocomplete] = useState(false);
|
||||
const [selectedAutocompleteIndex, setSelectedAutocompleteIndex] = useState(0);
|
||||
const messagesEndRef = useRef(null);
|
||||
const fileInputRef = useRef(null);
|
||||
const messageInputRef = useRef(null);
|
||||
const autocompleteRef = useRef(null);
|
||||
|
||||
const scrollToBottom = () => {
|
||||
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
scrollToBottom();
|
||||
}, [conversation]);
|
||||
|
||||
// Auto-focus input when a new conversation is created or selected
|
||||
useEffect(() => {
|
||||
if (conversation && !isLoading) {
|
||||
// Small delay to ensure the textarea is rendered
|
||||
const timer = setTimeout(() => {
|
||||
messageInputRef.current?.focus();
|
||||
}, 100);
|
||||
return () => clearTimeout(timer);
|
||||
}
|
||||
}, [conversation?.id, isLoading]);
|
||||
|
||||
// Prefill input (e.g. from make test-setup URL param). Never overrides non-empty input.
|
||||
useEffect(() => {
|
||||
if (!conversation?.id) return;
|
||||
if (!prefillMessage) return;
|
||||
if (input.trim() !== '') return;
|
||||
|
||||
setInput(prefillMessage);
|
||||
onPrefillConsumed?.();
|
||||
// Ensure caret at end
|
||||
setTimeout(() => {
|
||||
const el = messageInputRef.current;
|
||||
if (!el) return;
|
||||
el.focus();
|
||||
const end = el.value.length;
|
||||
el.setSelectionRange(end, end);
|
||||
}, 0);
|
||||
}, [conversation?.id, prefillMessage, input, onPrefillConsumed]);
|
||||
|
||||
// Close autocomplete when clicking outside
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (event) => {
|
||||
if (
|
||||
autocompleteRef.current &&
|
||||
!autocompleteRef.current.contains(event.target) &&
|
||||
messageInputRef.current &&
|
||||
!messageInputRef.current.contains(event.target)
|
||||
) {
|
||||
setShowAutocomplete(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (showAutocomplete) {
|
||||
document.addEventListener('mousedown', handleClickOutside);
|
||||
return () => {
|
||||
document.removeEventListener('mousedown', handleClickOutside);
|
||||
};
|
||||
}
|
||||
}, [showAutocomplete]);
|
||||
|
||||
const handleSubmit = (e) => {
|
||||
e.preventDefault();
|
||||
if (input.trim() && !isLoading) {
|
||||
onSendMessage(input);
|
||||
setInput('');
|
||||
}
|
||||
};
|
||||
|
||||
const handleKeyDown = (e) => {
|
||||
// Handle autocomplete navigation
|
||||
if (showAutocomplete) {
|
||||
if (e.key === 'ArrowDown') {
|
||||
e.preventDefault();
|
||||
setSelectedAutocompleteIndex((prev) =>
|
||||
Math.min(prev + 1, documents.length - 1)
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (e.key === 'ArrowUp') {
|
||||
e.preventDefault();
|
||||
setSelectedAutocompleteIndex((prev) => Math.max(prev - 1, 0));
|
||||
return;
|
||||
}
|
||||
if (e.key === 'Enter' || e.key === 'Tab') {
|
||||
e.preventDefault();
|
||||
insertDocumentReference(selectedAutocompleteIndex);
|
||||
return;
|
||||
}
|
||||
if (e.key === 'Escape') {
|
||||
e.preventDefault();
|
||||
setShowAutocomplete(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Submit on Enter (without Shift)
|
||||
if (e.key === 'Enter' && !e.shiftKey && !showAutocomplete) {
|
||||
e.preventDefault();
|
||||
handleSubmit(e);
|
||||
}
|
||||
};
|
||||
|
||||
const insertDocumentReference = (index) => {
|
||||
const ref = `@${index + 1}`;
|
||||
const textarea = messageInputRef.current;
|
||||
if (!textarea) return;
|
||||
|
||||
const cursorPos = textarea.selectionStart;
|
||||
const textBefore = input.substring(0, cursorPos);
|
||||
const textAfter = input.substring(cursorPos);
|
||||
|
||||
// Find the @ symbol position
|
||||
const atPos = textBefore.lastIndexOf('@');
|
||||
if (atPos === -1) return;
|
||||
|
||||
// Replace from @ to cursor with the reference
|
||||
const newText = input.substring(0, atPos) + ref + ' ' + textAfter;
|
||||
setInput(newText);
|
||||
setShowAutocomplete(false);
|
||||
|
||||
// Set cursor position after the inserted reference
|
||||
setTimeout(() => {
|
||||
const newCursorPos = atPos + ref.length + 1;
|
||||
textarea.setSelectionRange(newCursorPos, newCursorPos);
|
||||
textarea.focus();
|
||||
}, 0);
|
||||
};
|
||||
|
||||
const handleInputChange = (e) => {
|
||||
const value = e.target.value;
|
||||
setInput(value);
|
||||
|
||||
const cursorPos = e.target.selectionStart;
|
||||
const textBefore = value.substring(0, cursorPos);
|
||||
const lastAt = textBefore.lastIndexOf('@');
|
||||
|
||||
// Check if we're typing after an @ symbol
|
||||
if (lastAt !== -1) {
|
||||
const textAfterAt = textBefore.substring(lastAt + 1);
|
||||
// Only show autocomplete if there's no space or newline after @
|
||||
if (!textAfterAt.match(/[\s\n]/) && documents.length > 0) {
|
||||
setShowAutocomplete(true);
|
||||
setSelectedAutocompleteIndex(0);
|
||||
} else {
|
||||
setShowAutocomplete(false);
|
||||
}
|
||||
} else {
|
||||
setShowAutocomplete(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (!conversation) {
|
||||
return (
|
||||
<div className="chat-interface">
|
||||
<div className="empty-state">
|
||||
<h2>Welcome to LLM Council</h2>
|
||||
<p>Create a new conversation to get started</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const handlePickFile = () => {
|
||||
if (!fileInputRef.current) return;
|
||||
fileInputRef.current.value = '';
|
||||
fileInputRef.current.click();
|
||||
};
|
||||
|
||||
const handleFileChange = async (e) => {
|
||||
const selected = Array.from(e.target.files || []);
|
||||
if (selected.length === 0) return;
|
||||
const nonMd = selected.find((f) => !f.name.toLowerCase().endsWith('.md'));
|
||||
if (nonMd) {
|
||||
alert('Only .md files are supported');
|
||||
return;
|
||||
}
|
||||
if (onUploadDocument) {
|
||||
await onUploadDocument(selected);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="chat-interface">
|
||||
<div className="docs-bar">
|
||||
<div className="docs-left">
|
||||
<div className="docs-title">Documents</div>
|
||||
<div className="docs-subtitle">
|
||||
{documents.length === 0
|
||||
? 'No .md files attached'
|
||||
: `${documents.length} attached`}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="docs-right">
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
multiple
|
||||
accept=".md,text/markdown"
|
||||
style={{ display: 'none' }}
|
||||
onChange={handleFileChange}
|
||||
/>
|
||||
{onExportReport && conversation?.messages?.length > 0 && (
|
||||
<button
|
||||
type="button"
|
||||
className="docs-export-btn"
|
||||
onClick={() => onExportReport()}
|
||||
disabled={isLoading}
|
||||
title="Export conversation as markdown report"
|
||||
>
|
||||
📄 Export Report
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
className="docs-upload-btn"
|
||||
onClick={handlePickFile}
|
||||
disabled={isUploadingDoc || isLoading}
|
||||
>
|
||||
{isUploadingDoc ? 'Uploading…' : 'Upload .md'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{documents.length > 0 && (
|
||||
<div className="docs-list">
|
||||
{documents.map((d, index) => (
|
||||
<div key={d.id} className="doc-item">
|
||||
<button
|
||||
type="button"
|
||||
className={`doc-name-btn ${selectedDoc?.id === d.id ? 'active' : ''}`}
|
||||
onClick={() => onViewDocument && onViewDocument(d)}
|
||||
title="View document"
|
||||
>
|
||||
<span className="doc-number">@{index + 1}</span> {d.filename}
|
||||
</button>
|
||||
<div className="doc-actions">
|
||||
<span className="doc-bytes">{d.bytes} bytes</span>
|
||||
<button
|
||||
type="button"
|
||||
className="doc-delete-btn"
|
||||
onClick={() => onDeleteDocument && onDeleteDocument(d)}
|
||||
title="Remove document"
|
||||
>
|
||||
Remove
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{selectedDoc && (
|
||||
<div className="doc-preview">
|
||||
<div className="doc-preview-header">
|
||||
<div className="doc-preview-title">{selectedDoc.filename}</div>
|
||||
<div className="doc-preview-meta">{selectedDoc.bytes} bytes</div>
|
||||
</div>
|
||||
<div className="doc-preview-body">
|
||||
{isLoadingDoc ? (
|
||||
<div className="doc-preview-loading">Loading…</div>
|
||||
) : (
|
||||
<div className="markdown-content">
|
||||
<ReactMarkdown>{selectedDocContent}</ReactMarkdown>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="messages-container">
|
||||
{conversation.messages.length === 0 ? (
|
||||
<div className="empty-state">
|
||||
<h2>Start a conversation</h2>
|
||||
<p>Ask a question to consult the LLM Council</p>
|
||||
</div>
|
||||
) : (
|
||||
conversation.messages.map((msg, index) => (
|
||||
<div key={index} className="message-group">
|
||||
{msg.role === 'user' ? (
|
||||
<div className="user-message">
|
||||
<div className="message-label">You</div>
|
||||
<div className="message-content">
|
||||
<div className="markdown-content">
|
||||
<ReactMarkdown>{msg.content}</ReactMarkdown>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="assistant-message">
|
||||
<div className="message-label">LLM Council</div>
|
||||
|
||||
{/* Stage 1 */}
|
||||
{msg.loading?.stage1 && (
|
||||
<div className="stage-loading">
|
||||
<div className="spinner"></div>
|
||||
<span>Running Stage 1: Collecting individual responses...</span>
|
||||
</div>
|
||||
)}
|
||||
{msg.stage1 && (
|
||||
<Stage1
|
||||
responses={msg.stage1}
|
||||
metadata={msg.metadata?.stage1_metadata}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Stage 2 */}
|
||||
{msg.loading?.stage2 && (
|
||||
<div className="stage-loading">
|
||||
<div className="spinner"></div>
|
||||
<span>Running Stage 2: Peer rankings...</span>
|
||||
</div>
|
||||
)}
|
||||
{msg.stage2 && (
|
||||
<Stage2
|
||||
rankings={msg.stage2}
|
||||
labelToModel={msg.metadata?.label_to_model}
|
||||
aggregateRankings={msg.metadata?.aggregate_rankings}
|
||||
metadata={msg.metadata?.stage2_metadata}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Stage 3 */}
|
||||
{msg.loading?.stage3 && (
|
||||
<div className="stage-loading">
|
||||
<div className="spinner"></div>
|
||||
<span>Running Stage 3: Final synthesis...</span>
|
||||
</div>
|
||||
)}
|
||||
{msg.stage3 && (
|
||||
<Stage3
|
||||
finalResponse={msg.stage3}
|
||||
metadata={msg.metadata?.stage3_metadata}
|
||||
totalDuration={msg.metadata?.total_duration_seconds}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
|
||||
{isLoading && (
|
||||
<div className="loading-indicator">
|
||||
<div className="spinner"></div>
|
||||
<span>Consulting the council...</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div ref={messagesEndRef} />
|
||||
</div>
|
||||
|
||||
<form className="input-form" onSubmit={handleSubmit}>
|
||||
<div className="input-wrapper">
|
||||
<textarea
|
||||
ref={messageInputRef}
|
||||
className="message-input"
|
||||
placeholder="Ask your question... (Type @ to reference documents, Shift+Enter for new line, Enter to send)"
|
||||
value={input}
|
||||
onChange={handleInputChange}
|
||||
onKeyDown={handleKeyDown}
|
||||
disabled={isLoading}
|
||||
/>
|
||||
{showAutocomplete && documents.length > 0 && (
|
||||
<div
|
||||
ref={autocompleteRef}
|
||||
className="autocomplete-dropdown"
|
||||
>
|
||||
{documents.map((doc, index) => (
|
||||
<div
|
||||
key={doc.id}
|
||||
className={`autocomplete-item ${
|
||||
selectedAutocompleteIndex === index ? 'selected' : ''
|
||||
}`}
|
||||
onClick={() => insertDocumentReference(index)}
|
||||
onMouseEnter={() => setSelectedAutocompleteIndex(index)}
|
||||
>
|
||||
<span className="autocomplete-number">@{index + 1}</span>
|
||||
<span className="autocomplete-filename">{doc.filename}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<button
|
||||
type="submit"
|
||||
className="send-button"
|
||||
disabled={!input.trim() || isLoading}
|
||||
>
|
||||
Send
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
.sidebar {
|
||||
width: 260px;
|
||||
background: var(--bg-secondary);
|
||||
border-right: 1px solid var(--border-color);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
transition: background-color 0.2s, border-color 0.2s;
|
||||
}
|
||||
|
||||
.sidebar-header {
|
||||
padding: 16px;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.sidebar-header-top {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.sidebar-header-actions {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.sidebar-header h1 {
|
||||
font-size: 18px;
|
||||
margin: 0;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.theme-toggle-btn,
|
||||
.debug-toggle-btn {
|
||||
background: var(--bg-primary);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 6px;
|
||||
padding: 6px 10px;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s, border-color 0.2s;
|
||||
line-height: 1;
|
||||
color: var(--text-primary);
|
||||
min-width: 36px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.theme-toggle-btn:hover,
|
||||
.debug-toggle-btn:hover {
|
||||
background: var(--hover-bg);
|
||||
border-color: var(--active-border);
|
||||
}
|
||||
|
||||
.debug-toggle-btn {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.new-conversation-btn {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
background: #4a90e2;
|
||||
border: 1px solid #4a90e2;
|
||||
border-radius: 6px;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
transition: background 0.2s;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.new-conversation-btn:hover {
|
||||
background: #357abd;
|
||||
border-color: #357abd;
|
||||
}
|
||||
|
||||
.search-box {
|
||||
padding: 12px 16px;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.search-input {
|
||||
width: 100%;
|
||||
padding: 8px 12px;
|
||||
background: var(--bg-primary);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 6px;
|
||||
color: var(--text-primary);
|
||||
font-size: 14px;
|
||||
outline: none;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.search-input:focus {
|
||||
border-color: #4a90e2;
|
||||
box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.1);
|
||||
}
|
||||
|
||||
.search-input::placeholder {
|
||||
color: var(--text-tertiary);
|
||||
}
|
||||
|
||||
.conversation-list {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
.no-conversations {
|
||||
padding: 16px;
|
||||
text-align: center;
|
||||
color: var(--text-tertiary);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.conversation-item {
|
||||
padding: 12px;
|
||||
margin-bottom: 4px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.conversation-item:hover {
|
||||
background: var(--hover-bg);
|
||||
}
|
||||
|
||||
.conversation-item.active {
|
||||
background: var(--hover-bg-light);
|
||||
border: 1px solid #4a90e2;
|
||||
}
|
||||
|
||||
|
||||
.conversation-content {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.conversation-title {
|
||||
color: var(--text-primary);
|
||||
font-size: 14px;
|
||||
margin-bottom: 4px;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
.conversation-meta {
|
||||
color: var(--text-tertiary);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.conversation-actions {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
margin-left: 8px;
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
|
||||
.conversation-item:hover .conversation-actions {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.conversation-delete-btn {
|
||||
background: transparent;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 16px;
|
||||
color: var(--text-secondary);
|
||||
transition: background 0.2s, color 0.2s;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.conversation-delete-btn:hover {
|
||||
background: #fee;
|
||||
color: #c33;
|
||||
}
|
||||
|
||||
.conversation-rename-btn {
|
||||
background: transparent;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
color: var(--text-secondary);
|
||||
transition: background 0.2s, color 0.2s;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.conversation-rename-btn:hover {
|
||||
background: var(--hover-bg);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.conversation-title-edit {
|
||||
width: 100%;
|
||||
padding: 4px 8px;
|
||||
background: var(--bg-primary);
|
||||
border: 1px solid #4a90e2;
|
||||
border-radius: 4px;
|
||||
color: var(--text-primary);
|
||||
font-size: 14px;
|
||||
font-family: inherit;
|
||||
outline: none;
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import './Sidebar.css';
|
||||
|
||||
export default function Sidebar({
|
||||
conversations,
|
||||
currentConversationId,
|
||||
onSelectConversation,
|
||||
onNewConversation,
|
||||
onDeleteConversation,
|
||||
onRenameConversation,
|
||||
theme = 'light',
|
||||
onToggleTheme,
|
||||
searchQuery = '',
|
||||
onSearchChange,
|
||||
}) {
|
||||
const [editingId, setEditingId] = useState(null);
|
||||
const [editValue, setEditValue] = useState('');
|
||||
|
||||
const handleStartEdit = (conv, e) => {
|
||||
e.stopPropagation();
|
||||
setEditingId(conv.id);
|
||||
setEditValue(conv.title || 'New Conversation');
|
||||
};
|
||||
|
||||
const handleSaveEdit = async (convId, e) => {
|
||||
e.stopPropagation();
|
||||
if (onRenameConversation && editValue.trim()) {
|
||||
await onRenameConversation(convId, editValue.trim());
|
||||
}
|
||||
setEditingId(null);
|
||||
setEditValue('');
|
||||
};
|
||||
|
||||
const handleCancelEdit = (e) => {
|
||||
e.stopPropagation();
|
||||
setEditingId(null);
|
||||
setEditValue('');
|
||||
};
|
||||
|
||||
const handleKeyDown = (e, convId) => {
|
||||
if (e.key === 'Enter') {
|
||||
handleSaveEdit(convId, e);
|
||||
} else if (e.key === 'Escape') {
|
||||
handleCancelEdit(e);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="sidebar">
|
||||
<div className="sidebar-header">
|
||||
<div className="sidebar-header-top">
|
||||
<h1>LLM Council</h1>
|
||||
<div className="sidebar-header-actions">
|
||||
{onToggleTheme && (
|
||||
<button
|
||||
className="theme-toggle-btn"
|
||||
onClick={onToggleTheme}
|
||||
title={theme === 'light' ? 'Switch to dark mode' : 'Switch to light mode'}
|
||||
>
|
||||
{theme === 'light' ? '🌙' : '☀️'}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<button className="new-conversation-btn" onClick={onNewConversation}>
|
||||
+ New Conversation
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="search-box">
|
||||
<input
|
||||
type="text"
|
||||
className="search-input"
|
||||
placeholder="Search conversations..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => onSearchChange && onSearchChange(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="conversation-list">
|
||||
{conversations.length === 0 ? (
|
||||
<div className="no-conversations">No conversations yet</div>
|
||||
) : (
|
||||
conversations.map((conv) => (
|
||||
<div
|
||||
key={conv.id}
|
||||
className={`conversation-item ${
|
||||
conv.id === currentConversationId ? 'active' : ''
|
||||
}`}
|
||||
onClick={() => onSelectConversation(conv.id)}
|
||||
>
|
||||
<div className="conversation-content">
|
||||
{editingId === conv.id ? (
|
||||
<input
|
||||
type="text"
|
||||
className="conversation-title-edit"
|
||||
value={editValue}
|
||||
onChange={(e) => setEditValue(e.target.value)}
|
||||
onBlur={(e) => handleSaveEdit(conv.id, e)}
|
||||
onKeyDown={(e) => handleKeyDown(e, conv.id)}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
autoFocus
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
<div className="conversation-title">
|
||||
{conv.title || 'New Conversation'}
|
||||
</div>
|
||||
<div className="conversation-meta">
|
||||
{conv.message_count} messages
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<div className="conversation-actions" onClick={(e) => e.stopPropagation()}>
|
||||
{editingId !== conv.id && onRenameConversation && (
|
||||
<button
|
||||
className="conversation-rename-btn"
|
||||
onClick={(e) => handleStartEdit(conv, e)}
|
||||
title="Rename"
|
||||
>
|
||||
✏️
|
||||
</button>
|
||||
)}
|
||||
{onDeleteConversation && (
|
||||
<button
|
||||
className="conversation-delete-btn"
|
||||
onClick={(e) => onDeleteConversation(conv.id, e)}
|
||||
title="Delete"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
.stage {
|
||||
margin: 24px 0;
|
||||
padding: 20px;
|
||||
background: var(--bg-secondary);
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--border-color);
|
||||
transition: background-color 0.2s, border-color 0.2s;
|
||||
}
|
||||
|
||||
.stage-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.stage-meta {
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.stage-title {
|
||||
margin: 0;
|
||||
color: var(--text-primary);
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.tabs {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-bottom: 16px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.tab {
|
||||
padding: 8px 16px;
|
||||
background: var(--bg-primary);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 6px 6px 0 0;
|
||||
color: var(--text-secondary);
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.tab:hover {
|
||||
background: var(--hover-bg);
|
||||
color: var(--text-primary);
|
||||
border-color: #4a90e2;
|
||||
}
|
||||
|
||||
.tab.active {
|
||||
background: var(--bg-primary);
|
||||
color: #4a90e2;
|
||||
border-color: #4a90e2;
|
||||
border-bottom-color: var(--bg-primary);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.tab-content {
|
||||
background: var(--bg-primary);
|
||||
padding: 16px;
|
||||
border-radius: 6px;
|
||||
border: 1px solid var(--border-color);
|
||||
transition: background-color 0.2s, border-color 0.2s;
|
||||
}
|
||||
|
||||
.model-name {
|
||||
color: var(--text-secondary);
|
||||
font-size: 12px;
|
||||
margin-bottom: 12px;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.response-text {
|
||||
color: var(--text-primary);
|
||||
line-height: 1.6;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { useState } from 'react';
|
||||
import ReactMarkdown from 'react-markdown';
|
||||
import './Stage1.css';
|
||||
|
||||
export default function Stage1({ responses, metadata }) {
|
||||
const [activeTab, setActiveTab] = useState(0);
|
||||
|
||||
if (!responses || responses.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const duration = metadata?.duration_seconds;
|
||||
const successful = metadata?.successful_models?.length || 0;
|
||||
const total = metadata?.total_models || 0;
|
||||
|
||||
return (
|
||||
<div className="stage stage1">
|
||||
<div className="stage-header">
|
||||
<h3 className="stage-title">Stage 1: Individual Responses</h3>
|
||||
{duration && (
|
||||
<div className="stage-meta">
|
||||
{duration}s | {successful}/{total} models
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="tabs">
|
||||
{responses.map((resp, index) => (
|
||||
<button
|
||||
key={index}
|
||||
className={`tab ${activeTab === index ? 'active' : ''}`}
|
||||
onClick={() => setActiveTab(index)}
|
||||
>
|
||||
{resp.model.split('/')[1] || resp.model}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="tab-content">
|
||||
<div className="model-name">{responses[activeTab].model}</div>
|
||||
<div className="response-text markdown-content">
|
||||
<ReactMarkdown>{responses[activeTab].response}</ReactMarkdown>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
.stage-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.stage-meta {
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.stage2 {
|
||||
background: var(--bg-secondary);
|
||||
}
|
||||
|
||||
.stage2 h4 {
|
||||
margin: 20px 0 8px 0;
|
||||
color: var(--text-primary);
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.stage2 h4:first-of-type {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.stage-description {
|
||||
margin: 0 0 12px 0;
|
||||
color: var(--text-secondary);
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.aggregate-rankings {
|
||||
background: var(--hover-bg-light);
|
||||
padding: 16px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
border: 2px solid var(--border-hover);
|
||||
transition: background-color 0.2s, border-color 0.2s;
|
||||
}
|
||||
|
||||
.aggregate-rankings h4 {
|
||||
margin: 0 0 12px 0;
|
||||
color: #2a7ae2;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.aggregate-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.aggregate-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 10px;
|
||||
background: var(--bg-primary);
|
||||
border-radius: 6px;
|
||||
border: 1px solid var(--border-hover);
|
||||
transition: background-color 0.2s, border-color 0.2s;
|
||||
}
|
||||
|
||||
.rank-position {
|
||||
color: #2a7ae2;
|
||||
font-weight: 700;
|
||||
font-size: 16px;
|
||||
min-width: 35px;
|
||||
}
|
||||
|
||||
.rank-model {
|
||||
flex: 1;
|
||||
color: var(--text-primary);
|
||||
font-family: monospace;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.rank-score {
|
||||
color: var(--text-secondary);
|
||||
font-size: 13px;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.stage2 .tabs {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-bottom: 16px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.stage2 .tab {
|
||||
padding: 8px 16px;
|
||||
background: var(--bg-primary);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 6px 6px 0 0;
|
||||
color: var(--text-secondary);
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.stage2 .tab:hover {
|
||||
background: var(--hover-bg);
|
||||
color: var(--text-primary);
|
||||
border-color: #4a90e2;
|
||||
}
|
||||
|
||||
.stage2 .tab.active {
|
||||
background: var(--bg-primary);
|
||||
color: #4a90e2;
|
||||
border-color: #4a90e2;
|
||||
border-bottom-color: var(--bg-primary);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.stage2 .tab-content {
|
||||
background: var(--bg-primary);
|
||||
padding: 16px;
|
||||
border-radius: 6px;
|
||||
border: 1px solid var(--border-color);
|
||||
margin-bottom: 20px;
|
||||
transition: background-color 0.2s, border-color 0.2s;
|
||||
}
|
||||
|
||||
.ranking-model {
|
||||
color: var(--text-secondary);
|
||||
font-size: 12px;
|
||||
font-family: monospace;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.ranking-content {
|
||||
color: var(--text-primary);
|
||||
line-height: 1.6;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.parsed-ranking {
|
||||
margin-top: 16px;
|
||||
padding-top: 16px;
|
||||
border-top: 2px solid var(--border-color);
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.parsed-ranking strong {
|
||||
color: #2a7ae2;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.parsed-ranking ol {
|
||||
margin: 8px 0 0 0;
|
||||
padding-left: 24px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.parsed-ranking li {
|
||||
margin: 4px 0;
|
||||
font-family: monospace;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.rank-count {
|
||||
color: var(--text-tertiary);
|
||||
font-size: 12px;
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
import { useState } from 'react';
|
||||
import ReactMarkdown from 'react-markdown';
|
||||
import './Stage2.css';
|
||||
|
||||
function deAnonymizeText(text, labelToModel) {
|
||||
if (!labelToModel) return text;
|
||||
|
||||
let result = text;
|
||||
// Replace each "Response X" with the actual model name
|
||||
Object.entries(labelToModel).forEach(([label, model]) => {
|
||||
const modelShortName = model.split('/')[1] || model;
|
||||
result = result.replace(new RegExp(label, 'g'), `**${modelShortName}**`);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export default function Stage2({ rankings, labelToModel, aggregateRankings, metadata }) {
|
||||
const [activeTab, setActiveTab] = useState(0);
|
||||
|
||||
if (!rankings || rankings.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const duration = metadata?.duration_seconds;
|
||||
const successful = metadata?.successful_models?.length || 0;
|
||||
const total = metadata?.total_models || 0;
|
||||
|
||||
return (
|
||||
<div className="stage stage2">
|
||||
<div className="stage-header">
|
||||
<h3 className="stage-title">Stage 2: Peer Rankings</h3>
|
||||
{duration && (
|
||||
<div className="stage-meta">
|
||||
{duration}s | {successful}/{total} models
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<h4>Raw Evaluations</h4>
|
||||
<p className="stage-description">
|
||||
Each model evaluated all responses (anonymized as Response A, B, C, etc.) and provided rankings.
|
||||
Below, model names are shown in <strong>bold</strong> for readability, but the original evaluation used anonymous labels.
|
||||
</p>
|
||||
|
||||
<div className="tabs">
|
||||
{rankings.map((rank, index) => (
|
||||
<button
|
||||
key={index}
|
||||
className={`tab ${activeTab === index ? 'active' : ''}`}
|
||||
onClick={() => setActiveTab(index)}
|
||||
>
|
||||
{rank.model.split('/')[1] || rank.model}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="tab-content">
|
||||
<div className="ranking-model">
|
||||
{rankings[activeTab].model}
|
||||
</div>
|
||||
<div className="ranking-content markdown-content">
|
||||
<ReactMarkdown>
|
||||
{deAnonymizeText(rankings[activeTab].ranking, labelToModel)}
|
||||
</ReactMarkdown>
|
||||
</div>
|
||||
|
||||
{rankings[activeTab].parsed_ranking &&
|
||||
rankings[activeTab].parsed_ranking.length > 0 && (
|
||||
<div className="parsed-ranking">
|
||||
<strong>Extracted Ranking:</strong>
|
||||
<ol>
|
||||
{rankings[activeTab].parsed_ranking.map((label, i) => (
|
||||
<li key={i}>
|
||||
{labelToModel && labelToModel[label]
|
||||
? labelToModel[label].split('/')[1] || labelToModel[label]
|
||||
: label}
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{aggregateRankings && aggregateRankings.length > 0 && (
|
||||
<div className="aggregate-rankings">
|
||||
<h4>Aggregate Rankings (Street Cred)</h4>
|
||||
<p className="stage-description">
|
||||
Combined results across all peer evaluations (lower score is better):
|
||||
</p>
|
||||
<div className="aggregate-list">
|
||||
{aggregateRankings.map((agg, index) => (
|
||||
<div key={index} className="aggregate-item">
|
||||
<span className="rank-position">#{index + 1}</span>
|
||||
<span className="rank-model">
|
||||
{agg.model.split('/')[1] || agg.model}
|
||||
</span>
|
||||
<span className="rank-score">
|
||||
Avg: {agg.average_rank.toFixed(2)}
|
||||
</span>
|
||||
<span className="rank-count">
|
||||
({agg.rankings_count} votes)
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
.stage-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.stage-meta {
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.total-duration {
|
||||
margin-top: 12px;
|
||||
padding-top: 12px;
|
||||
border-top: 1px solid var(--border-light);
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.stage3 {
|
||||
background: var(--bg-secondary);
|
||||
border-color: var(--border-color);
|
||||
}
|
||||
|
||||
.final-response {
|
||||
background: var(--bg-primary);
|
||||
padding: 20px;
|
||||
border-radius: 6px;
|
||||
border: 1px solid var(--border-color);
|
||||
transition: background-color 0.2s, border-color 0.2s;
|
||||
}
|
||||
|
||||
.chairman-label {
|
||||
color: var(--text-primary);
|
||||
font-size: 12px;
|
||||
font-family: monospace;
|
||||
margin-bottom: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.final-text {
|
||||
color: var(--text-primary);
|
||||
line-height: 1.7;
|
||||
font-size: 15px;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import ReactMarkdown from 'react-markdown';
|
||||
import './Stage3.css';
|
||||
|
||||
export default function Stage3({ finalResponse, metadata, totalDuration }) {
|
||||
if (!finalResponse) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const duration = metadata?.duration_seconds;
|
||||
const model = metadata?.model || finalResponse.model;
|
||||
|
||||
return (
|
||||
<div className="stage stage3">
|
||||
<div className="stage-header">
|
||||
<h3 className="stage-title">Stage 3: Final Council Answer</h3>
|
||||
{duration && (
|
||||
<div className="stage-meta">
|
||||
{duration}s
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="final-response">
|
||||
<div className="chairman-label">
|
||||
Chairman: {model.split('/')[1] || model}
|
||||
</div>
|
||||
<div className="final-text markdown-content">
|
||||
<ReactMarkdown>{finalResponse.response}</ReactMarkdown>
|
||||
</div>
|
||||
{totalDuration && (
|
||||
<div className="total-duration">
|
||||
Total processing time: <strong>{totalDuration}s</strong>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
:root {
|
||||
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
/* Light theme (default) */
|
||||
:root,
|
||||
[data-theme="light"] {
|
||||
--bg-primary: #ffffff;
|
||||
--bg-secondary: #f8f8f8;
|
||||
--bg-tertiary: #fbfbfb;
|
||||
--bg-code: #f5f5f5;
|
||||
--text-primary: #333333;
|
||||
--text-secondary: #666666;
|
||||
--text-tertiary: #999999;
|
||||
--border-color: #e0e0e0;
|
||||
--border-light: #eaeaea;
|
||||
--hover-bg: #f5f5f5;
|
||||
--hover-bg-light: #f0f7ff;
|
||||
--border-hover: #d0e7ff;
|
||||
}
|
||||
|
||||
/* Dark theme - improved contrast */
|
||||
[data-theme="dark"] {
|
||||
--bg-primary: #1a1a1a;
|
||||
--bg-secondary: #252525;
|
||||
--bg-tertiary: #2a2a2a;
|
||||
--bg-code: #2d2d2d;
|
||||
--text-primary: #ffffff;
|
||||
--text-secondary: #e0e0e0;
|
||||
--text-tertiary: #b0b0b0;
|
||||
--border-color: #404040;
|
||||
--border-light: #353535;
|
||||
--hover-bg: #303030;
|
||||
--hover-bg-light: #2a3a4a;
|
||||
--border-hover: #4a5a6a;
|
||||
--active-border: #5aa0f2;
|
||||
--user-message-bg: #1e2a3a;
|
||||
--user-message-border: #2a3a4a;
|
||||
--stage-bg: #252525;
|
||||
--stage-border: #404040;
|
||||
--stage3-bg: #1e2a1e;
|
||||
--stage3-border: #2a3a2a;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
min-width: 320px;
|
||||
min-height: 100vh;
|
||||
background: var(--bg-secondary);
|
||||
color: var(--text-primary);
|
||||
transition: background-color 0.2s, color 0.2s;
|
||||
}
|
||||
|
||||
#root {
|
||||
height: 100vh;
|
||||
width: 100vw;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Global markdown styling */
|
||||
.markdown-content {
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.markdown-content p {
|
||||
margin: 0 0 12px 0;
|
||||
}
|
||||
|
||||
.markdown-content p:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.markdown-content h1,
|
||||
.markdown-content h2,
|
||||
.markdown-content h3,
|
||||
.markdown-content h4,
|
||||
.markdown-content h5,
|
||||
.markdown-content h6 {
|
||||
margin: 16px 0 8px 0;
|
||||
}
|
||||
|
||||
.markdown-content h1:first-child,
|
||||
.markdown-content h2:first-child,
|
||||
.markdown-content h3:first-child,
|
||||
.markdown-content h4:first-child,
|
||||
.markdown-content h5:first-child,
|
||||
.markdown-content h6:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.markdown-content ul,
|
||||
.markdown-content ol {
|
||||
margin: 0 0 12px 0;
|
||||
padding-left: 24px;
|
||||
}
|
||||
|
||||
.markdown-content li {
|
||||
margin: 4px 0;
|
||||
}
|
||||
|
||||
.markdown-content pre {
|
||||
background: var(--bg-code);
|
||||
padding: 12px;
|
||||
border-radius: 4px;
|
||||
overflow-x: auto;
|
||||
margin: 0 0 12px 0;
|
||||
}
|
||||
|
||||
.markdown-content code {
|
||||
background: var(--bg-code);
|
||||
padding: 2px 6px;
|
||||
border-radius: 3px;
|
||||
font-family: monospace;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.markdown-content pre code {
|
||||
background: none;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.markdown-content blockquote {
|
||||
margin: 0 0 12px 0;
|
||||
padding-left: 16px;
|
||||
border-left: 4px solid var(--border-color);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './index.css'
|
||||
import App from './App.jsx'
|
||||
|
||||
createRoot(document.getElementById('root')).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
||||
@@ -0,0 +1,101 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
import { api } from '../src/api.js';
|
||||
|
||||
|
||||
test('api.listDocuments calls correct endpoint', async () => {
|
||||
const calls = [];
|
||||
globalThis.fetch = async (url, options) => {
|
||||
calls.push({ url: String(url), options });
|
||||
return {
|
||||
ok: true,
|
||||
json: async () => [{ id: '1', filename: 'a.md', bytes: 3 }],
|
||||
};
|
||||
};
|
||||
|
||||
const out = await api.listDocuments('conv123');
|
||||
assert.equal(calls.length, 1);
|
||||
assert.match(calls[0].url, /\/api\/conversations\/conv123\/documents$/);
|
||||
assert.deepEqual(out, [{ id: '1', filename: 'a.md', bytes: 3 }]);
|
||||
});
|
||||
|
||||
|
||||
test('api.uploadDocument uses multipart form and POST', async () => {
|
||||
const calls = [];
|
||||
globalThis.fetch = async (url, options) => {
|
||||
calls.push({ url: String(url), options });
|
||||
return {
|
||||
ok: true,
|
||||
json: async () => ({ id: 'doc1', filename: 'x.md', bytes: 10 }),
|
||||
};
|
||||
};
|
||||
|
||||
// Node 18 doesn't provide a global File, but it does provide Blob.
|
||||
// Our api.uploadDocument supports Blob + filename.
|
||||
const file = new Blob(['hello'], { type: 'text/markdown' });
|
||||
file.name = 'x.md';
|
||||
const out = await api.uploadDocument('conv999', file);
|
||||
|
||||
assert.equal(calls.length, 1);
|
||||
assert.match(calls[0].url, /\/api\/conversations\/conv999\/documents$/);
|
||||
assert.equal(calls[0].options.method, 'POST');
|
||||
assert.ok(calls[0].options.body instanceof FormData);
|
||||
assert.equal(out.id, 'doc1');
|
||||
});
|
||||
|
||||
test('api.uploadDocuments uses multipart form and POST', async () => {
|
||||
const calls = [];
|
||||
globalThis.fetch = async (url, options) => {
|
||||
calls.push({ url: String(url), options });
|
||||
return {
|
||||
ok: true,
|
||||
json: async () => ({ uploaded: [{ id: 'a' }, { id: 'b' }] }),
|
||||
};
|
||||
};
|
||||
|
||||
const a = new Blob(['one'], { type: 'text/markdown' });
|
||||
a.name = 'a.md';
|
||||
const b = new Blob(['two'], { type: 'text/markdown' });
|
||||
b.name = 'b.md';
|
||||
|
||||
const out = await api.uploadDocuments('conv999', [a, b]);
|
||||
|
||||
assert.equal(calls.length, 1);
|
||||
assert.match(calls[0].url, /\/api\/conversations\/conv999\/documents$/);
|
||||
assert.equal(calls[0].options.method, 'POST');
|
||||
assert.ok(calls[0].options.body instanceof FormData);
|
||||
assert.equal(out.uploaded.length, 2);
|
||||
});
|
||||
|
||||
test('api.getDocument calls correct endpoint', async () => {
|
||||
const calls = [];
|
||||
globalThis.fetch = async (url) => {
|
||||
calls.push({ url: String(url) });
|
||||
return {
|
||||
ok: true,
|
||||
json: async () => ({ id: 'd1', content: '# hi' }),
|
||||
};
|
||||
};
|
||||
|
||||
const out = await api.getDocument('c1', 'd1');
|
||||
assert.equal(calls.length, 1);
|
||||
assert.match(calls[0].url, /\/api\/conversations\/c1\/documents\/d1$/);
|
||||
assert.equal(out.content, '# hi');
|
||||
});
|
||||
|
||||
test('api.deleteDocument uses DELETE', async () => {
|
||||
const calls = [];
|
||||
globalThis.fetch = async (url, options) => {
|
||||
calls.push({ url: String(url), options });
|
||||
return { ok: true, json: async () => ({ ok: true }) };
|
||||
};
|
||||
|
||||
const out = await api.deleteDocument('c1', 'd1');
|
||||
assert.equal(calls.length, 1);
|
||||
assert.match(calls[0].url, /\/api\/conversations\/c1\/documents\/d1$/);
|
||||
assert.equal(calls[0].options.method, 'DELETE');
|
||||
assert.equal(out.ok, true);
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
// Node 18 can't import .jsx without a loader; do a lightweight source-based test instead.
|
||||
test('ChatInterface includes Documents UI and always-visible input form', () => {
|
||||
const filePath = path.resolve(
|
||||
process.cwd(),
|
||||
'src/components/ChatInterface.jsx'
|
||||
);
|
||||
const src = fs.readFileSync(filePath, 'utf8');
|
||||
|
||||
assert.ok(src.includes('className="docs-bar"'));
|
||||
assert.ok(src.includes('Upload .md'));
|
||||
assert.ok(src.includes('className="docs-list"'));
|
||||
assert.ok(src.includes('Delete'));
|
||||
assert.ok(src.includes('doc-preview'));
|
||||
assert.ok(src.includes('className="input-form"'));
|
||||
assert.ok(src.includes('className="message-input"'));
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
})
|
||||
Reference in New Issue
Block a user