🔮 Initial commit: sibilla — self-hosted Perplexity-like AI search engine
This commit is contained in:
commit
ea09bb4f4f
11 files changed
+671
No files matched your search
+108
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* Sibilla — Frontend search interface
|
||||
*/
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const form = document.getElementById('search-form');
|
||||
const queryInput = document.getElementById('query');
|
||||
const submitBtn = document.getElementById('submit-btn');
|
||||
const responseArea = document.getElementById('response-area');
|
||||
const loading = document.getElementById('loading');
|
||||
const answerDiv = document.getElementById('answer');
|
||||
const sourcesDiv = document.getElementById('sources');
|
||||
|
||||
form.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const query = queryInput.value.trim();
|
||||
if (!query) return;
|
||||
|
||||
// Show response area + loading
|
||||
responseArea.style.display = 'block';
|
||||
loading.style.display = 'flex';
|
||||
answerDiv.innerHTML = '';
|
||||
sourcesDiv.innerHTML = '';
|
||||
submitBtn.disabled = true;
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/ask', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ query }),
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const err = await res.json();
|
||||
throw new Error(err.error || 'Errore sconosciuto');
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
|
||||
// Render answer as Markdown
|
||||
answerDiv.innerHTML = renderMarkdown(data.answer);
|
||||
|
||||
// Render sources
|
||||
if (data.sources && data.sources.length > 0) {
|
||||
sourcesDiv.innerHTML = '<h3>📚 Fonti</h3>' +
|
||||
data.sources.map(s =>
|
||||
`<a href="${escapeHtml(s.url)}" target="_blank" rel="noopener" class="source-item">
|
||||
<span class="source-title">${escapeHtml(s.title)}</span>
|
||||
<span class="source-url">${escapeHtml(s.url)}</span>
|
||||
</a>`
|
||||
).join('');
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
answerDiv.innerHTML = `<div class="error-box">⚠️ ${escapeHtml(err.message)}</div>`;
|
||||
} finally {
|
||||
loading.style.display = 'none';
|
||||
submitBtn.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
// Allow Ctrl+Enter to submit
|
||||
queryInput.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
|
||||
form.dispatchEvent(new Event('submit'));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// ── Tiny Markdown renderer ─────────────────────────────────────
|
||||
function renderMarkdown(text) {
|
||||
if (!text) return '';
|
||||
|
||||
let html = escapeHtml(text);
|
||||
|
||||
// Headers
|
||||
html = html.replace(/^### (.+)$/gm, '<h3>$1</h3>');
|
||||
html = html.replace(/^## (.+)$/gm, '<h2>$1</h2>');
|
||||
html = html.replace(/^# (.+)$/gm, '<h1>$1</h1>');
|
||||
|
||||
// Bold + italic
|
||||
html = html.replace(/\*\*\*(.+?)\*\*\*/g, '<strong><em>$1</em></strong>');
|
||||
html = html.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>');
|
||||
html = html.replace(/\*(.+?)\*/g, '<em>$1</em>');
|
||||
|
||||
// Inline code
|
||||
html = html.replace(/`(.+?)`/g, '<code>$1</code>');
|
||||
|
||||
// Links
|
||||
html = html.replace(/\[(.+?)\]\((.+?)\)/g, '<a href="$2" target="_blank" rel="noopener">$1</a>');
|
||||
|
||||
// Paragraphs (double newlines)
|
||||
html = html.replace(/\n\n/g, '</p><p>');
|
||||
html = '<p>' + html + '</p>';
|
||||
html = html.replace(/<p>\s*<\/p>/g, '');
|
||||
|
||||
// Line breaks
|
||||
html = html.replace(/\n/g, '<br>');
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
function escapeHtml(text) {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = text;
|
||||
return div.innerHTML;
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
/* ═══════════════════════════════════════════════════════════════
|
||||
Sibilla — L'Oracolo AI
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
:root {
|
||||
--bg: #0f0f14;
|
||||
--surface: #1a1a24;
|
||||
--surface-hover: #22222e;
|
||||
--border: #2a2a3a;
|
||||
--text: #e8e8ed;
|
||||
--text-muted: #8888a0;
|
||||
--accent: #a78bfa;
|
||||
--accent-glow: #c4b5fd;
|
||||
--success: #34d399;
|
||||
--danger: #f87171;
|
||||
--radius: 12px;
|
||||
--transition: 0.2s ease;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 800px;
|
||||
width: 100%;
|
||||
padding: 2rem 1.5rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
/* ── Header ──────────────────────────────────────────────────── */
|
||||
|
||||
header {
|
||||
text-align: center;
|
||||
margin-bottom: 3rem;
|
||||
padding-top: 3rem;
|
||||
}
|
||||
|
||||
header h1 {
|
||||
font-size: 2.8rem;
|
||||
font-weight: 700;
|
||||
background: linear-gradient(135deg, var(--accent), var(--accent-glow));
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
margin-bottom: 0.5rem;
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
color: var(--text-muted);
|
||||
font-size: 1.05rem;
|
||||
}
|
||||
|
||||
/* ── Search Box ──────────────────────────────────────────────── */
|
||||
|
||||
.search-box {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.search-box textarea {
|
||||
width: 100%;
|
||||
padding: 1rem 1.25rem;
|
||||
background: var(--surface);
|
||||
border: 2px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
color: var(--text);
|
||||
font-size: 1.05rem;
|
||||
font-family: inherit;
|
||||
resize: vertical;
|
||||
min-height: 80px;
|
||||
transition: border-color var(--transition), box-shadow var(--transition);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.search-box textarea:focus {
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.15);
|
||||
}
|
||||
|
||||
.search-box textarea::placeholder {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
#submit-btn {
|
||||
align-self: flex-end;
|
||||
padding: 0.75rem 1.75rem;
|
||||
background: linear-gradient(135deg, var(--accent), #8b5cf6);
|
||||
border: none;
|
||||
border-radius: var(--radius);
|
||||
color: #fff;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: transform var(--transition), box-shadow var(--transition), opacity var(--transition);
|
||||
}
|
||||
|
||||
#submit-btn:hover {
|
||||
transform: translateY(-1px);
|
||||
box-shadow: 0 4px 20px rgba(167, 139, 250, 0.35);
|
||||
}
|
||||
|
||||
#submit-btn:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
#submit-btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
/* ── Response Area ───────────────────────────────────────────── */
|
||||
|
||||
.response-area {
|
||||
flex: 1;
|
||||
animation: fadeIn 0.3s ease;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from { opacity: 0; transform: translateY(8px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
|
||||
/* ── Loading ─────────────────────────────────────────────────── */
|
||||
|
||||
.loading {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
padding: 2rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border: 3px solid var(--border);
|
||||
border-top-color: var(--accent);
|
||||
border-radius: 50%;
|
||||
animation: spin 0.8s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
/* ── Answer ──────────────────────────────────────────────────── */
|
||||
|
||||
.answer {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 1.5rem;
|
||||
margin-bottom: 1.5rem;
|
||||
line-height: 1.7;
|
||||
font-size: 1.02rem;
|
||||
}
|
||||
|
||||
.answer h1, .answer h2, .answer h3 {
|
||||
margin-top: 1.25rem;
|
||||
margin-bottom: 0.5rem;
|
||||
color: var(--accent-glow);
|
||||
}
|
||||
|
||||
.answer h1 { font-size: 1.5rem; }
|
||||
.answer h2 { font-size: 1.25rem; }
|
||||
.answer h3 { font-size: 1.1rem; }
|
||||
|
||||
.answer p {
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.answer ul, .answer ol {
|
||||
padding-left: 1.5rem;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.answer li {
|
||||
margin-bottom: 0.35rem;
|
||||
}
|
||||
|
||||
.answer code {
|
||||
background: rgba(167, 139, 250, 0.1);
|
||||
padding: 0.15rem 0.4rem;
|
||||
border-radius: 4px;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.answer pre {
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
padding: 1rem;
|
||||
border-radius: 8px;
|
||||
overflow-x: auto;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.answer blockquote {
|
||||
border-left: 3px solid var(--accent);
|
||||
padding-left: 1rem;
|
||||
color: var(--text-muted);
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
/* ── Sources ─────────────────────────────────────────────────── */
|
||||
|
||||
.sources {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 1.25rem;
|
||||
}
|
||||
|
||||
.sources h3 {
|
||||
color: var(--accent-glow);
|
||||
font-size: 0.95rem;
|
||||
margin-bottom: 0.75rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
.source-item {
|
||||
display: block;
|
||||
padding: 0.6rem 0.75rem;
|
||||
border-radius: 8px;
|
||||
color: var(--text);
|
||||
text-decoration: none;
|
||||
transition: background var(--transition);
|
||||
margin-bottom: 0.25rem;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.source-item:hover {
|
||||
background: var(--surface-hover);
|
||||
}
|
||||
|
||||
.source-item .source-title {
|
||||
font-weight: 500;
|
||||
color: var(--accent-glow);
|
||||
}
|
||||
|
||||
.source-item .source-url {
|
||||
color: var(--text-muted);
|
||||
font-size: 0.8rem;
|
||||
display: block;
|
||||
margin-top: 0.15rem;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
/* ── Error ───────────────────────────────────────────────────── */
|
||||
|
||||
.error-box {
|
||||
background: rgba(248, 113, 113, 0.1);
|
||||
border: 1px solid var(--danger);
|
||||
border-radius: var(--radius);
|
||||
padding: 1rem 1.25rem;
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
/* ── Footer ──────────────────────────────────────────────────── */
|
||||
|
||||
footer {
|
||||
text-align: center;
|
||||
padding: 1.5rem 0;
|
||||
color: var(--text-muted);
|
||||
font-size: 0.8rem;
|
||||
margin-top: auto;
|
||||
}
|
||||
Reference in new issue
Block a user