Spaces:
Runtime error
Runtime error
Commit ·
a76a5fb
1
Parent(s): b546831
feat: add web client
Browse filesFiles changed (2)
- public/app.jsAdded+680
- public/index.htmlAdded+293
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680// config and stateconst API_BASE = window.location.origin + '/v1';let STATE = { apiKey: localStorage.getItem('anput_key') || null, schemas: [], currentSchema: null, mode: 'live', isRecording: false};
let deleteTargetSlug = null;
let recognition = null; let audioContext = null; let processor = null;let stream = null;let ws = null;let transcriptBuffer = "";
// initdocument.addEventListener('DOMContentLoaded', () => { if (STATE.apiKey) { document.getElementById('loginKey').value = STATE.apiKey; validateAndLogin(STATE.apiKey); } else { router('landing'); }
document.addEventListener('click', (e) => { if (!e.target.closest('.schema-menu-btn')) { closeAllDropdowns(); } });});
// notiffunction showNotification(title, message, type = 'info') { const modal = document.getElementById('modal-notification'); const icon = document.getElementById('notif-icon'); const iconBg = document.getElementById('notif-icon-bg'); document.getElementById('notif-title').innerText = title; document.getElementById('notif-message').innerText = message;
if (type === 'error') { icon.className = 'fa-solid fa-triangle-exclamation text-red-500 text-xl'; iconBg.className = 'w-12 h-12 rounded-full flex items-center justify-center bg-red-500/10'; } else if (type === 'success') { icon.className = 'fa-solid fa-check text-emerald-500 text-xl'; iconBg.className = 'w-12 h-12 rounded-full flex items-center justify-center bg-emerald-500/10'; } else { icon.className = 'fa-solid fa-info text-zinc-400 text-xl'; iconBg.className = 'w-12 h-12 rounded-full flex items-center justify-center bg-zinc-900'; }
modal.classList.remove('hidden');}
function closeNotification() { document.getElementById('modal-notification').classList.add('hidden');}
// routerfunction router(view) { document.querySelectorAll('.view-section').forEach(el => el.classList.remove('active')); document.getElementById(`view-${view}`).classList.add('active'); const navUser = document.getElementById('nav-user'); if (view === 'landing') { navUser.classList.add('hidden'); } else { navUser.classList.remove('hidden'); document.getElementById('nav-key-display').innerText = STATE.apiKey ? STATE.apiKey.substring(0, 12) + '...' : 'KEY ACTIVE'; if (view === 'dashboard') loadSchemas(); }}
// auth and validationasync function handleLogin() { const key = document.getElementById('loginKey').value.trim(); if (!key) return showNotification("Error", "Please enter API Key", "error"); const btn = document.getElementById('btn-login'); const originalText = btn.innerHTML; btn.innerHTML = '<i class="fa-solid fa-circle-notch fa-spin"></i> Checking...'; btn.disabled = true;
await validateAndLogin(key, btn, originalText);}
async function validateAndLogin(key, btn = null, originalText = null) { try { const res = await fetch(`${API_BASE}/schemas`, { headers: { 'Authorization': `Bearer ${key}` } });
if (res.status === 401) { if(btn) { showNotification("Access Denied", "Invalid API Key. Please check and try again.", "error"); } else { logout(); } return; }
if (!res.ok) throw new Error("Connection failed");
STATE.apiKey = key; localStorage.setItem('anput_key', key); router('dashboard');
} catch(e) { showNotification("Connection Error", "Could not connect to server.", "error"); } finally { if(btn) { btn.innerHTML = originalText; btn.disabled = false; } }}
function logout() { localStorage.removeItem('anput_key'); STATE.apiKey = null; router('landing');}
function requestSandboxAccess() { showNotification("Coming Soon", "Sandbox key generation is currently in closed beta. Please contact administrator for access.", "info");}
// dashboard and CRUDasync function loadSchemas() { const grid = document.getElementById('schema-grid'); const loader = document.getElementById('schema-loader'); const empty = document.getElementById('schema-empty'); grid.innerHTML = ''; loader.classList.remove('hidden'); empty.classList.add('hidden');
try { const res = await fetch(`${API_BASE}/schemas`, { headers: { 'Authorization': `Bearer ${STATE.apiKey}` } }); const data = await res.json(); loader.classList.add('hidden');
if (!data || data.length === 0) { empty.classList.remove('hidden'); return; }
STATE.schemas = data; data.forEach(s => { let fieldCount = 0; if (s.definition) { if (s.definition.properties) { fieldCount = Object.keys(s.definition.properties).length; } else { fieldCount = Object.keys(s.definition).length; } }
const card = document.createElement('div'); card.className = "bg-zinc-950 border border-zinc-800 p-6 rounded-2xl hover:border-emerald-500 transition cursor-pointer group flex flex-col justify-between h-48 relative"; card.onclick = (e) => { if(!e.target.closest('.schema-menu-btn') && !e.target.closest('.dropdown-menu')) { openPlayground(s); } };
card.innerHTML = ` <div> <div class="flex justify-between items-start mb-4"> <div class="w-10 h-10 bg-zinc-900 rounded-lg flex items-center justify-center text-xl text-zinc-400 group-hover:text-emerald-500 group-hover:bg-emerald-500/10 transition">📦</div> <div class="relative"> <button onclick="toggleDropdown(event, '${s.slug}')" class="schema-menu-btn text-zinc-600 hover:text-white p-2 rounded-md transition hover:bg-zinc-800"> <i class="fa-solid fa-ellipsis-vertical"></i> </button> <div id="dd-${s.slug}" class="dropdown-menu hidden absolute right-0 mt-2 w-36 bg-zinc-900 border border-zinc-800 rounded-xl shadow-xl z-20 dropdown-enter overflow-hidden"> <button onclick="editSchema('${s.slug}')" class="w-full text-left px-4 py-3 text-xs text-zinc-300 hover:bg-zinc-800 hover:text-white transition border-b border-zinc-800"> <i class="fa-solid fa-pen mr-2"></i> Edit </button> <button onclick="askDeleteSchema('${s.slug}')" class="w-full text-left px-4 py-3 text-xs text-red-500 hover:bg-red-500/10 transition font-bold"> <i class="fa-solid fa-trash mr-2"></i> Delete </button> </div> </div> </div> <h3 class="font-bold text-white text-lg mb-1 truncate">${s.slug}</h3> <p class="text-zinc-500 text-xs line-clamp-2 leading-relaxed">${s.description || 'No description provided.'}</p> </div> <div class="pt-4 border-t border-zinc-900 text-[10px] text-zinc-600 font-mono flex items-center gap-2"> <span class="w-2 h-2 rounded-full bg-zinc-800 group-hover:bg-emerald-500 transition"></span> ${fieldCount} Data Fields </div> `; grid.appendChild(card); }); } catch (e) { loader.classList.add('hidden'); empty.classList.remove('hidden'); }}
// dropdownfunction toggleDropdown(e, slug) { e.stopPropagation(); const targetId = `dd-${slug}`; const target = document.getElementById(targetId); const isAlreadyOpen = !target.classList.contains('hidden'); closeAllDropdowns(); if (!isAlreadyOpen) { target.classList.remove('hidden'); }}
function closeAllDropdowns() { document.querySelectorAll('.dropdown-menu').forEach(el => el.classList.add('hidden'));}
// deletefunction askDeleteSchema(slug) { deleteTargetSlug = slug; document.getElementById('delete-target-slug').innerText = slug; document.getElementById('modal-delete').classList.remove('hidden'); closeAllDropdowns();}
function closeDeleteModal() { document.getElementById('modal-delete').classList.add('hidden'); deleteTargetSlug = null;}
async function confirmDelete() { if(!deleteTargetSlug) return; try { const res = await fetch(`${API_BASE}/schemas?slug=${deleteTargetSlug}`, { method: 'DELETE', headers: { 'Authorization': `Bearer ${STATE.apiKey}` } });
if(res.status === 404 || res.status === 405) { await fetch(`${API_BASE}/schemas/${deleteTargetSlug}`, { method: 'DELETE', headers: { 'Authorization': `Bearer ${STATE.apiKey}` } }); }
if(res.ok || res.status === 200) { closeDeleteModal(); loadSchemas(); showNotification("Deleted", "Schema has been deleted successfully", "success"); } else { showNotification("Failed", "Failed to delete schema", "error"); } } catch(e) { showNotification("Error", "Server connection error", "error"); }}
// schema builderlet builderFields = [];let isEditMode = false;
function resetBuilderUI() { builderFields = []; document.getElementById('buildSlug').value = ""; document.getElementById('buildSlug').disabled = false; document.getElementById('buildDesc').value = ""; document.getElementById('builder-title').innerText = "New Schema"; document.getElementById('btn-save-text').innerText = "Deploy Schema"; document.getElementById('builder-preview').innerHTML = '{}'; isEditMode = false; renderBuilderFields(); router('builder');}
function editSchema(slug) { const schema = STATE.schemas.find(s => s.slug === slug); if(!schema) return;
closeAllDropdowns(); isEditMode = true; document.getElementById('builder-title').innerText = "Edit Schema"; document.getElementById('btn-save-text').innerText = "Save Changes"; document.getElementById('buildSlug').value = schema.slug; document.getElementById('buildSlug').disabled = true; document.getElementById('buildDesc').value = schema.description;
builderFields = []; let props = {}; if(schema.definition && schema.definition.properties) { props = schema.definition.properties; } else { props = schema.definition || {}; }
Object.keys(props).forEach((key) => { const val = props[key]; let type = 'string'; let desc = ''; if (typeof val === 'string') type = val; else if (typeof val === 'object') { type = val.type || 'string'; desc = val.description || ''; } builderFields.push({ id: Date.now() + Math.random(), name: key, type: type, desc: desc }); });
renderBuilderFields(); router('builder');}
function builderAddField() { const id = Date.now(); builderFields.push({ id, name: '', type: 'string', desc: '' }); renderBuilderFields();}
function renderBuilderFields() { const container = document.getElementById('builder-fields'); container.innerHTML = ''; builderFields.forEach((f, idx) => { const row = document.createElement('div'); row.className = "flex gap-2 items-start animate-in fade-in slide-in-from-left-2 duration-300"; row.innerHTML = ` <input type="text" placeholder="field_name" class="flex-1 bg-zinc-900 border border-zinc-800 rounded-lg px-3 py-2 text-xs text-white font-mono focus:border-emerald-500" value="${f.name}" oninput="updateBuilderField(${idx}, 'name', this.value)"> <select class="bg-zinc-900 border border-zinc-800 rounded-lg px-3 py-2 text-xs text-zinc-400 focus:border-emerald-500" onchange="updateBuilderField(${idx}, 'type', this.value)"> <option value="string" ${f.type==='string'?'selected':''}>Text</option> <option value="number" ${f.type==='number'?'selected':''}>Number</option> <option value="boolean" ${f.type==='boolean'?'selected':''}>Checkbox</option> <option value="date" ${f.type==='date'?'selected':''}>Date</option> </select> <input type="text" placeholder="Description..." class="flex-1 bg-zinc-900 border border-zinc-800 rounded-lg px-3 py-2 text-xs text-white focus:border-emerald-500" value="${f.desc}" oninput="updateBuilderField(${idx}, 'desc', this.value)"> <button onclick="removeBuilderField(${idx})" class="text-zinc-600 hover:text-red-500 px-2 py-2 transition"><i class="fa-solid fa-trash"></i></button> `; container.appendChild(row); }); updateBuilderPreview();}
function updateBuilderField(idx, key, val) { builderFields[idx][key] = val; updateBuilderPreview(); }function removeBuilderField(idx) { builderFields.splice(idx, 1); renderBuilderFields(); }
function updateBuilderPreview() { if (builderFields.length === 0) { document.getElementById('builder-preview').innerHTML = '{}'; return; } const def = { type: "object", properties: {}, required: [] }; builderFields.forEach(f => { if(f.name) { def.properties[f.name] = { type: f.type, description: f.desc }; def.required.push(f.name); } }); const json = JSON.stringify(def, null, 2); document.getElementById('builder-preview').innerHTML = Prism.highlight(json, Prism.languages.json, 'json');}
async function submitSchema() { const slug = document.getElementById('buildSlug').value.trim(); const desc = document.getElementById('buildDesc').value.trim(); const defStr = document.getElementById('builder-preview').textContent; if(!slug || builderFields.length === 0) return showNotification("Validation Error", "Please fill slug and add at least one field", "error");
let url = `${API_BASE}/schemas`; let method = 'POST'; if (isEditMode) { url = `${API_BASE}/schemas?slug=${slug}`; method = 'PUT'; }
try { const res = await fetch(url, { method: method, headers: { 'Authorization': `Bearer ${STATE.apiKey}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ slug: slug, description: desc, definition: JSON.parse(defStr) }) }); if(res.ok) { showNotification("Success", isEditMode ? "Schema Updated!" : "Schema Deployed!", "success"); resetBuilderUI(); router('dashboard'); } else { const e = await res.json(); showNotification("Failed", e.error || "Operation failed", "error"); } } catch(e) { showNotification("Error", "Invalid JSON Schema or Server Error", "error"); }}
// playgroundfunction openPlayground(schema) { STATE.currentSchema = schema; document.getElementById('pg-schema-name').innerText = schema.slug; document.getElementById('pg-code-url').innerText = `${API_BASE}/transcribe?slug=${schema.slug}`; transcriptBuffer = ""; document.getElementById('pg-transcript').innerHTML = '<span class="text-zinc-700 italic">Ready to transcribe...</span>'; renderFormEmpty(); setPlaygroundMode('live'); router('playground'); setupVisualRecognition();}
function setPlaygroundMode(mode) { STATE.mode = mode; const btnLive = document.getElementById('btn-mode-live'); const btnFile = document.getElementById('btn-mode-file'); if (mode === 'live') { btnLive.className = "px-4 py-1.5 rounded-md text-xs font-bold bg-zinc-800 text-white shadow"; btnFile.className = "px-4 py-1.5 rounded-md text-xs font-bold text-zinc-500 hover:text-white"; document.getElementById('pg-ui-live').classList.remove('hidden'); document.getElementById('pg-ui-file').classList.add('hidden'); } else { btnFile.className = "px-4 py-1.5 rounded-md text-xs font-bold bg-zinc-800 text-white shadow"; btnLive.className = "px-4 py-1.5 rounded-md text-xs font-bold text-zinc-500 hover:text-white"; document.getElementById('pg-ui-file').classList.remove('hidden'); document.getElementById('pg-ui-live').classList.add('hidden'); }}
function toggleRecording() { if (STATE.isRecording) stopRecording(); else startRecording();}
function setupVisualRecognition() { if (!('webkitSpeechRecognition' in window)) return; recognition = new webkitSpeechRecognition(); recognition.continuous = true; recognition.interimResults = true; recognition.lang = 'id-ID';
recognition.onresult = (event) => { let interim = ''; for (let i = event.resultIndex; i < event.results.length; ++i) { if (event.results[i].isFinal) { transcriptBuffer += event.results[i][0].transcript; } else { interim += event.results[i][0].transcript; } } const box = document.getElementById('pg-transcript'); box.innerHTML = `<span class="text-white">${transcriptBuffer}</span> <span class="text-zinc-600 italic">${interim}</span>`; box.parentElement.scrollTop = box.parentElement.scrollHeight; }; recognition.onend = () => { if(STATE.isRecording) recognition.start(); };}
async function startRecording() { if(STATE.isRecording) return; updateMicState(true); transcriptBuffer = ""; document.getElementById('pg-transcript').innerHTML = '<span class="text-emerald-500 animate-pulse">Listening...</span>'; try { stream = await navigator.mediaDevices.getUserMedia({ audio: true }); audioContext = new (window.AudioContext || window.webkitAudioContext)(); const source = audioContext.createMediaStreamSource(stream); processor = audioContext.createScriptProcessor(4096, 1, 1); const proto = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; const url = `${proto}//${window.location.host}/v1/stream?slug=${STATE.currentSchema.slug}&token=${STATE.apiKey}`; ws = new WebSocket(url); ws.binaryType = 'arraybuffer';
ws.onopen = () => { console.log("WS Connected"); source.connect(processor); processor.connect(audioContext.destination); document.getElementById('pg-transcript').innerHTML = ""; };
ws.onmessage = (e) => { const msg = JSON.parse(e.data); if(msg.type === 'result') { document.getElementById('global-loader').classList.add('hidden'); renderFormResult(msg.data.parsed); if(msg.data.final_transcript) { transcriptBuffer = msg.data.final_transcript; document.getElementById('pg-transcript').innerHTML = ` <div class="bg-zinc-900 border border-emerald-500/30 p-4 rounded-xl text-emerald-400 font-mono text-sm leading-relaxed shadow-lg shadow-emerald-900/10"> <i class="fa-solid fa-check-circle mr-2"></i> ${transcriptBuffer} </div>`; } if(ws) ws.close(); } else if (msg.type === 'error') { document.getElementById('global-loader').classList.add('hidden'); showNotification("AI Error", msg.data, "error"); } };
processor.onaudioprocess = (e) => { if(ws && ws.readyState === WebSocket.OPEN) { const inputData = e.inputBuffer.getChannelData(0); const downsampled = downsampleBuffer(inputData, audioContext.sampleRate, 16000); const pcm16 = convertFloatToInt16(downsampled); ws.send(pcm16.buffer); } };
if(recognition) recognition.start();
} catch(e) { showNotification("Microphone Error", e.message, "error"); updateMicState(false); }}
function stopRecording() { if(!STATE.isRecording) return; if(recognition) recognition.stop(); if(processor) processor.disconnect(); if(audioContext) audioContext.close(); if(stream) stream.getTracks().forEach(t => t.stop());
if(ws && ws.readyState === WebSocket.OPEN) { ws.send(JSON.stringify({action: "stop"})); document.getElementById('global-loader').classList.remove('hidden'); } updateMicState(false);}
function updateMicState(isRec) { STATE.isRecording = isRec; const btn = document.getElementById('pg-mic-btn'); const status = document.getElementById('pg-status'); const glow = document.getElementById('mic-glow'); if(isRec) { btn.classList.add('border-emerald-500', 'text-black', 'bg-emerald-500'); btn.classList.remove('border-zinc-800', 'text-zinc-500', 'bg-zinc-900'); status.innerText = "TAP TO STOP"; status.classList.add('text-emerald-500'); glow.classList.remove('opacity-0'); } else { btn.classList.remove('border-emerald-500', 'text-black', 'bg-emerald-500'); btn.classList.add('border-zinc-800', 'text-zinc-500', 'bg-zinc-900'); status.innerText = "TAP TO SPEAK"; status.classList.remove('text-emerald-500'); glow.classList.add('opacity-0'); }}
function downsampleBuffer(buffer, sampleRate, outSampleRate) { if (outSampleRate === sampleRate) return buffer; const ratio = sampleRate / outSampleRate; const newLength = Math.round(buffer.length / ratio); const result = new Float32Array(newLength); let offsetResult = 0; let offsetBuffer = 0; while (offsetResult < result.length) { const nextOffsetBuffer = Math.round((offsetResult + 1) * ratio); let accum = 0, count = 0; for (let i = offsetBuffer; i < nextOffsetBuffer && i < buffer.length; i++) { accum += buffer[i]; count++; } result[offsetResult] = count > 0 ? accum / count : 0; offsetResult++; offsetBuffer = nextOffsetBuffer; } return result;}
function convertFloatToInt16(buffer) { const l = buffer.length; const buf = new Int16Array(l); for (let i = 0; i < l; i++) { let s = Math.max(-1, Math.min(1, buffer[i])); buf[i] = s < 0 ? s * 0x8000 : s * 0x7FFF; } return buf;}
async function handleFileUpload(input) { const file = input.files[0]; if(!file) return; document.getElementById('pg-file-info').innerText = file.name; document.getElementById('pg-file-info').classList.remove('hidden'); document.getElementById('pg-upload-loader').classList.remove('hidden'); const formData = new FormData(); formData.append('audio', file); try { const res = await fetch(`${API_BASE}/transcribe?slug=${STATE.currentSchema.slug}`, { method: 'POST', headers: {'Authorization': `Bearer ${STATE.apiKey}`}, body: formData }); const data = await res.json(); if(res.ok) { renderFormResult(data.parsed); document.getElementById('pg-transcript').innerText = data.raw_transcript; } else { showNotification("Error", data.error, "error"); } } catch(e) { showNotification("Error", "Upload Failed", "error"); } finally { document.getElementById('pg-upload-loader').classList.add('hidden'); }}
function renderFormResult(data) { const container = document.getElementById('pg-form-container'); container.innerHTML = ''; if(!data) { renderFormEmpty(); return; }
for (const [key, value] of Object.entries(data)) { const div = document.createElement('div'); div.className = "mb-5 animate-in fade-in slide-in-from-bottom-2 duration-500"; let label = key.replace(/_/g, ' '); let valStr = value === null ? '' : String(value); if (typeof value === 'boolean') { div.innerHTML = ` <div class="flex items-center gap-3 bg-zinc-900 p-4 rounded-xl border border-zinc-800"> <input type="checkbox" data-key="${key}" ${value ? 'checked' : ''} class="w-5 h-5 accent-emerald-500 rounded bg-zinc-800 border-zinc-700"> <span class="text-xs text-zinc-300 font-bold uppercase tracking-wider">${label}</span> </div>`; } else { div.innerHTML = ` <label class="block text-[10px] font-bold text-zinc-500 uppercase mb-2 tracking-wider ml-1">${label}</label> <input type="text" data-key="${key}" value="${valStr}" class="w-full bg-zinc-900 border border-zinc-800 rounded-lg px-4 py-3 text-sm text-white focus:border-emerald-500 outline-none transition font-mono"> `; } container.appendChild(div); }}
function renderFormEmpty() { document.getElementById('pg-form-container').innerHTML = ` <div class="h-64 flex flex-col items-center justify-center text-zinc-800 border border-zinc-900 rounded-xl bg-zinc-900/30"> <i class="fa-solid fa-cube text-4xl mb-3 opacity-20"></i> <p class="text-sm">Ready for data...</p> </div>`;}
function copyResult() { const inputs = document.querySelectorAll('#pg-form-container input'); if(inputs.length === 0) { showNotification("Info", "No data to copy yet!", "info"); return; }
const currentData = {}; inputs.forEach(input => { const key = input.getAttribute('data-key'); if(key) { if(input.type === 'checkbox') { currentData[key] = input.checked; } else { const val = input.value; const num = Number(val); currentData[key] = (!isNaN(num) && val.trim() !== '') ? num : val; } } }); const jsonStr = JSON.stringify(currentData, null, 2); navigator.clipboard.writeText(jsonStr).then(() => { showNotification("Copied!", "JSON copied to clipboard", "success"); }).catch(err => { showNotification("Error", "Failed to copy", "error"); });}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>ANPUT Console</title> <script src="https://cdn.tailwindcss.com"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet"> <link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-tomorrow.min.css" rel="stylesheet" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-json.min.js"></script>
<style> :root { --bg-dark: #09090b; --bg-card: #121214; --border: #27272a; --accent: #10b981; } body { background-color: var(--bg-dark); color: #e4e4e7; font-family: 'Inter', sans-serif; } .font-mono { font-family: 'JetBrains Mono', monospace; } /* Layout Utilities */ .view-section { display: none; height: 100%; width: 100%; } .view-section.active { display: flex; flex-direction: column; animation: fadeIn 0.3s ease-out; } @keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } } @keyframes pulse-ring { 0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); } 70% { box-shadow: 0 0 0 20px rgba(16, 185, 129, 0); } 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); } } .recording-active { animation: pulse-ring 2s infinite; background-color: #10b981 !important; border-color: #10b981 !important; color: black !important; }
/* Scrollbar */ ::-webkit-scrollbar { width: 6px; height: 6px; } ::-webkit-scrollbar-track { background: transparent; } ::-webkit-scrollbar-thumb { background: #3f3f46; border-radius: 3px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
/* Dropdown Animation */ .dropdown-enter { animation: scaleIn 0.1s ease-out forwards; transform-origin: top right; } @keyframes scaleIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
/* chrome autofill handle */ input:-webkit-autofill, input:-webkit-autofill:hover, input:-webkit-autofill:focus, input:-webkit-autofill:active { -webkit-box-shadow: 0 0 0 30px #18181b inset !important; -webkit-text-fill-color: #e4e4e7 !important; caret-color: white !important; transition: background-color 5000s ease-in-out 0s; } </style></head><body class="flex flex-col h-screen overflow-hidden text-sm">
<nav class="h-16 border-b border-zinc-800 bg-zinc-950 flex items-center justify-between px-4 md:px-8 shrink-0 z-50"> <div class="flex items-center gap-3 cursor-pointer hover:opacity-80 transition" onclick="router('dashboard')"> <div class="w-8 h-8 bg-emerald-500 rounded-lg flex items-center justify-center text-black font-bold text-lg">A</div> <span class="font-bold text-lg tracking-tight">ANPUT <span class="text-zinc-500 font-normal text-xs">v1.0</span></span> </div> <div id="nav-user" class="hidden flex items-center gap-4"> <div class="hidden md:flex text-[10px] text-zinc-500 font-mono bg-zinc-900 px-3 py-1.5 rounded border border-zinc-800 items-center"> <div class="w-2 h-2 bg-emerald-500 rounded-full mr-2 animate-pulse"></div> <span id="nav-key-display">API KEY ACTIVE</span> </div> <button onclick="logout()" class="text-zinc-500 hover:text-white transition" title="Logout"><i class="fa-solid fa-right-from-bracket"></i></button> </div> </nav>
<main class="flex-1 overflow-hidden relative">
<section id="view-landing" class="view-section active items-center justify-center bg-zinc-950 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-zinc-900 via-zinc-950 to-black px-4"> <div class="w-full max-w-md p-6 md:p-8 animate-in fade-in zoom-in duration-500"> <div class="text-center mb-10"> <h1 class="text-5xl font-extrabold text-white mb-3 tracking-tight">ANPUT</h1> <p class="text-zinc-400">The Enterprise Voice-to-Data Engine</p> </div> <div class="bg-zinc-950 border border-zinc-800 p-8 rounded-2xl shadow-2xl shadow-emerald-900/10"> <div class="space-y-5"> <div> <label class="block text-[10px] font-bold text-zinc-500 uppercase mb-2 tracking-wider">Access Token</label> <div class="relative"> <i class="fa-solid fa-key absolute left-4 top-3.5 text-zinc-600"></i> <input type="password" id="loginKey" placeholder="anput_live_xxxxxxxx..." class="w-full bg-zinc-900/50 border border-zinc-700 rounded-xl pl-10 pr-4 py-3 text-white placeholder-zinc-600 focus:border-emerald-500 focus:bg-zinc-900 transition font-mono"> </div> </div> <button id="btn-login" onclick="handleLogin()" class="w-full bg-emerald-600 hover:bg-emerald-500 text-white font-bold py-3.5 rounded-xl transition shadow-lg shadow-emerald-900/20 transform hover:-translate-y-0.5 flex items-center justify-center gap-2"> <span>Connect to Console</span> </button> </div> <div class="mt-8 pt-6 border-t border-zinc-900 text-center"> <button onclick="requestSandboxAccess()" class="text-xs text-zinc-500 hover:text-emerald-400 transition flex items-center justify-center gap-2 mx-auto"> <i class="fa-solid fa-magic"></i> Generate Sandbox Key </button> </div> </div> </div> </section>
<section id="view-dashboard" class="view-section overflow-y-auto p-8 md:p-12" onclick="closeAllDropdowns()"> <div class="max-w-7xl mx-auto w-full"> <div class="flex justify-between items-end mb-10 border-b border-zinc-800 pb-6"> <div> <h2 class="text-3xl font-bold text-white mb-2">Schema Library</h2> <p class="text-zinc-500">Define data structures for your voice extraction.</p> </div> <button onclick="resetBuilderUI()" class="bg-white text-black hover:bg-zinc-200 px-6 py-2.5 rounded-lg font-bold transition flex items-center gap-2 shadow-lg"> <i class="fa-solid fa-plus"></i> Create Schema </button> </div> <div id="schema-grid" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6"></div> <div id="schema-loader" class="hidden text-center py-20"><i class="fa-solid fa-circle-notch fa-spin text-zinc-600 text-3xl"></i></div> <div id="schema-empty" class="hidden flex flex-col items-center justify-center py-20 border-2 border-dashed border-zinc-800 rounded-2xl"> <div class="w-16 h-16 bg-zinc-900 rounded-full flex items-center justify-center mb-4 text-2xl text-zinc-700">📂</div> <p class="text-zinc-500 font-medium">No schemas found</p> <p class="text-zinc-600 text-xs mt-1">Create your first schema to get started</p> </div> </div> </section>
<section id="view-builder" class="view-section overflow-y-auto p-8"> <div class="max-w-5xl mx-auto w-full"> <div class="mb-8 flex items-center gap-4"> <button onclick="router('dashboard')" class="w-10 h-10 rounded-full bg-zinc-900 border border-zinc-800 flex items-center justify-center text-zinc-400 hover:text-white hover:border-zinc-600 transition"><i class="fa-solid fa-arrow-left"></i></button> <h2 id="builder-title" class="text-2xl font-bold text-white">New Schema</h2> </div>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8"> <div class="lg:col-span-2 space-y-6"> <div class="bg-zinc-950 border border-zinc-800 rounded-2xl p-6"> <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-2"> <div> <label class="block text-[10px] font-bold text-zinc-500 uppercase mb-2">Schema Slug (ID)</label> <input type="text" id="buildSlug" placeholder="e.g. patient-intake" class="w-full bg-zinc-900 border border-zinc-800 rounded-lg px-4 py-3 text-white focus:border-emerald-500 disabled:opacity-50 disabled:cursor-not-allowed"> </div> <div> <label class="block text-[10px] font-bold text-zinc-500 uppercase mb-2">Description</label> <input type="text" id="buildDesc" placeholder="e.g. Hospital registration form" class="w-full bg-zinc-900 border border-zinc-800 rounded-lg px-4 py-3 text-white focus:border-emerald-500"> </div> </div> </div>
<div class="bg-zinc-950 border border-zinc-800 rounded-2xl p-6"> <div class="flex justify-between items-center mb-6"> <h3 class="font-bold text-white">Fields Definition</h3> <button onclick="builderAddField()" class="text-xs bg-zinc-800 hover:bg-zinc-700 px-3 py-1.5 rounded text-white transition flex items-center gap-2"><i class="fa-solid fa-plus"></i> Add Field</button> </div> <div id="builder-fields" class="space-y-3 min-h-[100px]"></div> </div>
<button id="btn-save-schema" onclick="submitSchema()" class="w-full bg-emerald-600 hover:bg-emerald-500 text-white font-bold py-4 rounded-xl transition shadow-lg shadow-emerald-900/20"> <span id="btn-save-text">Deploy Schema</span> </button> </div>
<div class="lg:col-span-1"> <div class="bg-black border border-zinc-800 rounded-2xl p-6 sticky top-6"> <h3 class="text-[10px] font-bold text-zinc-500 uppercase mb-4">Generated JSON</h3> <pre id="builder-preview" class="text-[10px] font-mono text-emerald-400 overflow-x-auto whitespace-pre-wrap">{}</pre> </div> </div> </div> </div> </section>
<section id="view-playground" class="view-section flex-col h-full bg-black"> <div class="border-b border-zinc-800 bg-zinc-950 px-4 md:px-6 py-4 flex justify-between items-center shrink-0"> <div class="flex items-center gap-3 md:gap-4"> <button onclick="router('dashboard')" class="text-zinc-500 hover:text-white"><i class="fa-solid fa-arrow-left"></i></button> <div> <h2 class="font-bold text-white text-lg flex items-center gap-2"> <span id="pg-schema-name" class="text-emerald-400 font-mono truncate max-w-[150px] md:max-w-none">schema-name</span> </h2> <p class="text-[10px] text-zinc-500 uppercase font-bold tracking-wider hidden md:block">Playground Environment</p> </div> </div> <div class="bg-zinc-900 p-1 rounded-lg flex gap-1"> <button onclick="setPlaygroundMode('live')" id="btn-mode-live" class="px-3 md:px-4 py-1.5 rounded-md text-xs font-bold bg-zinc-800 text-white shadow transition">Live</button> <button onclick="setPlaygroundMode('file')" id="btn-mode-file" class="px-3 md:px-4 py-1.5 rounded-md text-xs font-bold text-zinc-500 hover:text-white transition">File</button> </div> </div>
<div class="flex-1 flex flex-col md:flex-row overflow-hidden"> <div class="w-full md:w-5/12 h-auto md:h-full border-b md:border-b-0 md:border-r border-zinc-800 flex flex-col relative bg-zinc-950/50 shrink-0"> <div id="pg-ui-live" class="flex-1 flex flex-col justify-center items-center p-6 relative min-h-[300px] md:min-h-0"> <div class="mb-6 md:mb-10 relative group"> <div id="mic-glow" class="absolute inset-0 bg-emerald-500/30 rounded-full blur-2xl opacity-0 transition duration-300"></div> <button id="pg-mic-btn" onclick="toggleRecording()" class="relative z-10 w-24 h-24 md:w-28 md:h-28 rounded-full border-4 border-zinc-800 bg-zinc-900 text-zinc-500 text-3xl md:text-4xl hover:text-white hover:border-zinc-600 transition-all flex items-center justify-center shadow-2xl active:scale-95"> <i class="fa-solid fa-microphone"></i> </button> </div> <div id="pg-status" class="text-xs md:text-sm font-bold text-zinc-500 tracking-[0.2em] mb-4 md:mb-8">TAP TO SPEAK</div> <div class="w-full max-w-md h-24 md:h-40 overflow-y-auto pr-2 relative"> <div id="pg-transcript" class="text-lg md:text-xl font-light text-zinc-300 leading-relaxed text-center"> <span class="text-zinc-700 italic">Ready to transcribe...</span> </div> </div> </div> <div id="pg-ui-file" class="flex-1 flex flex-col justify-center items-center p-8 hidden min-h-[300px] md:min-h-0"> <div class="border-2 border-dashed border-zinc-800 rounded-2xl p-8 md:p-12 w-full max-w-sm hover:border-emerald-500 hover:bg-emerald-500/5 transition cursor-pointer group text-center" onclick="document.getElementById('pg-file-input').click()"> <i class="fa-solid fa-cloud-arrow-up text-4xl md:text-5xl text-zinc-700 group-hover:text-emerald-500 mb-4 md:mb-6 transition"></i> <p class="text-sm font-bold text-white group-hover:text-emerald-400">Click to Upload Audio</p> <p class="text-xs text-zinc-600 mt-2">MP3, WAV, M4A (Max 10MB)</p> <input type="file" id="pg-file-input" class="hidden" accept="audio/*" onchange="handleFileUpload(this)"> </div> <div id="pg-file-info" class="mt-6 text-sm font-mono text-emerald-500 hidden bg-emerald-500/10 px-4 py-2 rounded-lg"></div> <div id="pg-upload-loader" class="hidden mt-6 text-blue-500 text-sm flex items-center gap-2"><i class="fa-solid fa-circle-notch fa-spin"></i> Processing...</div> </div> </div>
<div class="w-full md:w-7/12 h-full flex flex-col bg-zinc-950 overflow-hidden"> <div class="flex-1 p-6 md:p-8 overflow-y-auto"> <div class="flex items-center justify-between mb-6"> <h3 class="text-xs font-bold text-zinc-500 uppercase tracking-widest">Extracted Data</h3> <button onclick="copyResult()" class="text-xs text-zinc-500 hover:text-white"><i class="fa-regular fa-copy"></i> Copy JSON</button> </div> <div id="pg-form-container" class="space-y-4"> <div class="h-40 md:h-64 flex flex-col items-center justify-center text-zinc-800 border border-zinc-900 rounded-xl bg-zinc-900/30"> <i class="fa-solid fa-cube text-4xl mb-3 opacity-20"></i> <p class="text-sm">Ready for data...</p> </div> </div> </div> <div class="p-6 border-t border-zinc-900 bg-black hidden md:block"> <div class="flex justify-between items-center mb-3"> <p class="text-[10px] font-bold text-zinc-500 uppercase">Integration Endpoint</p> <span class="text-[10px] text-zinc-600">POST Request</span> </div> <code class="block bg-zinc-900 border border-zinc-800 p-4 rounded-lg text-[11px] text-zinc-400 font-mono overflow-x-auto select-all"> <span class="text-emerald-500">POST</span> <span id="pg-code-url" class="text-zinc-300">...</span> </code> </div> </div> </div> </section>
<div id="global-loader" class="fixed inset-0 bg-black/80 backdrop-blur-sm z-[100] hidden flex flex-col items-center justify-center"> <div class="w-16 h-16 border-4 border-zinc-800 border-t-emerald-500 rounded-full animate-spin mb-4"></div> <p class="text-white font-bold tracking-widest animate-pulse">PROCESSING AI...</p> </div>
<div id="modal-delete" class="fixed inset-0 bg-black/80 backdrop-blur-sm z-[90] hidden flex items-center justify-center p-4"> <div class="bg-zinc-950 border border-zinc-800 rounded-2xl p-6 w-full max-w-sm shadow-2xl scale-in-center"> <div class="flex items-center gap-4 mb-4 text-red-500"> <div class="w-10 h-10 rounded-full bg-red-500/10 flex items-center justify-center"> <i class="fa-solid fa-triangle-exclamation"></i> </div> <h3 class="font-bold text-white text-lg">Delete Schema?</h3> </div> <p class="text-zinc-400 mb-2">Are you sure you want to delete <span id="delete-target-slug" class="font-mono text-white font-bold">...</span>?</p> <p class="text-xs text-zinc-500 mb-6">This action cannot be undone. All data definitions will be lost.</p> <div class="flex gap-3"> <button onclick="closeDeleteModal()" class="flex-1 px-4 py-2.5 rounded-lg bg-zinc-900 hover:bg-zinc-800 text-white font-medium transition">Cancel</button> <button onclick="confirmDelete()" class="flex-1 px-4 py-2.5 rounded-lg bg-red-600 hover:bg-red-700 text-white font-bold transition shadow-lg shadow-red-900/20">Delete</button> </div> </div> </div>
<div id="modal-notification" class="fixed inset-0 bg-black/80 backdrop-blur-sm z-[100] hidden flex items-center justify-center p-4"> <div class="bg-zinc-950 border border-zinc-800 rounded-2xl p-6 w-full max-w-sm shadow-2xl scale-in-center text-center"> <div class="mb-4 flex justify-center"> <div id="notif-icon-bg" class="w-12 h-12 rounded-full flex items-center justify-center bg-zinc-900"> <i id="notif-icon" class="fa-solid fa-info text-xl"></i> </div> </div> <h3 id="notif-title" class="font-bold text-white text-lg mb-2">Notification</h3> <p id="notif-message" class="text-zinc-400 text-sm mb-6">Message goes here</p> <button onclick="closeNotification()" class="w-full px-4 py-2.5 rounded-lg bg-zinc-900 hover:bg-zinc-800 text-white font-medium transition border border-zinc-800 hover:border-zinc-700"> Okay </button> </div> </div>
</main>
<script src="app.js?v=8"></script></body></html>public/app.jsAdded+680
public/index.htmlAdded+293