Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-sovereign-core/blob/main/crates/spark-cockpit-rs/static/app.js # aien-sovereign-core Autonomous sovereign intelligence engine and runtime core for NVIDIA DGX Spark Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-sovereign-core / crates / spark-cockpit-rs / static / app.js` 522 lines ยท 17187 bytes Raw Blame History 1 /** 2 * AIEN SOVEREIGN GLASS TERMINAL 3 * Three.js 3D Cosmic Starfield, Apple Frosted Glass, Microsoft Azure Tones, 4 * Web Speech API Voice Dictation, and Dynamic Peripheral Satellite Panels. 5 */ 6 7 // -------------------------------------------------------------------------- 8 // 1. THREE.JS 3D COSMIC STARFIELD ENGINE 9 // -------------------------------------------------------------------------- 10 let starScene, starCamera, starRenderer, starPoints; 11 let mouseX = 0, mouseY = 0; 12 const windowHalfX = window.innerWidth / 2; 13 const windowHalfY = window.innerHeight / 2; 14 15 function initStarfield() { 16 const canvas = document.getElementById('starfield-canvas'); 17 if (!canvas || typeof THREE === 'undefined') return; 18 19 starCamera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 3000); 20 starCamera.position.z = 1000; 21 22 starScene = new THREE.Scene(); 23 starScene.fog = new THREE.FogExp2(0x02040a, 0.0008); 24 25 const particleCount = 1800; 26 const geometry = new THREE.BufferGeometry(); 27 const positions = new Float32Array(particleCount * 3); 28 const colors = new Float32Array(particleCount * 3); 29 30 // Palette: Microsoft Azure (#0078D4), cyan (#50e6ff), and white 31 const azureColor = new THREE.Color(0x0078D4); 32 const cyanColor = new THREE.Color(0x50e6ff); 33 const whiteColor = new THREE.Color(0xffffff); 34 35 for (let i = 0; i < particleCount; i++) { 36 positions[i * 3] = (Math.random() * 2 - 1) * 1600; 37 positions[i * 3 + 1] = (Math.random() * 2 - 1) * 1600; 38 positions[i * 3 + 2] = (Math.random() * 2 - 1) * 1600; 39 40 const rand = Math.random(); 41 let col = whiteColor; 42 if (rand < 0.45) col = azureColor; 43 else if (rand < 0.75) col = cyanColor; 44 45 colors[i * 3] = col.r; 46 colors[i * 3 + 1] = col.g; 47 colors[i * 3 + 2] = col.b; 48 } 49 50 geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3)); 51 geometry.setAttribute('color', new THREE.BufferAttribute(colors, 3)); 52 53 const material = new THREE.PointsMaterial({ 54 size: 3.5, 55 vertexColors: true, 56 transparent: true, 57 opacity: 0.85, 58 blending: THREE.AdditiveBlending 59 }); 60 61 starPoints = new THREE.Points(geometry, material); 62 starScene.add(starPoints); 63 64 starRenderer = new THREE.WebGLRenderer({ canvas: canvas, alpha: true, antialias: true }); 65 starRenderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); 66 starRenderer.setSize(window.innerWidth, window.innerHeight); 67 68 document.addEventListener('pointermove', onPointerMove); 69 window.addEventListener('resize', onWindowResize); 70 71 animateStarfield(); 72 } 73 74 function onPointerMove(e) { 75 mouseX = (e.clientX - windowHalfX) * 0.2; 76 mouseY = (e.clientY - windowHalfY) * 0.2; 77 } 78 79 function onWindowResize() { 80 if (!starCamera || !starRenderer) return; 81 starCamera.aspect = window.innerWidth / window.innerHeight; 82 starCamera.updateProjectionMatrix(); 83 starRenderer.setSize(window.innerWidth, window.innerHeight); 84 } 85 86 function animateStarfield() { 87 requestAnimationFrame(animateStarfield); 88 if (!starScene || !starCamera || !starRenderer) return; 89 90 const time = Date.now() * 0.00015; 91 if (starPoints) { 92 starPoints.rotation.y = time * 0.3; 93 starPoints.rotation.x = time * 0.15; 94 } 95 96 starCamera.position.x += (mouseX - starCamera.position.x) * 0.04; 97 starCamera.position.y += (-mouseY - starCamera.position.y) * 0.04; 98 starCamera.lookAt(starScene.position); 99 100 starRenderer.render(starScene, starCamera); 101 } 102 103 // -------------------------------------------------------------------------- 104 // 2. PERIPHERAL SATELLITE POD CONTROLLER 105 // -------------------------------------------------------------------------- 106 function toggleSatellite(name) { 107 const pod = document.getElementById(`satellite-${name}`); 108 const btn = document.getElementById(`btn-toggle-${name}`); 109 if (!pod) return; 110 111 const isCurrentlyActive = pod.classList.contains('active'); 112 113 // Close all other satellites for clean viewing 114 document.querySelectorAll('.satellite-pod').forEach(p => p.classList.remove('active')); 115 document.querySelectorAll('.satellite-toggle-btn').forEach(b => b.classList.remove('active')); 116 117 if (!isCurrentlyActive) { 118 pod.classList.add('active'); 119 if (btn) btn.classList.add('active'); 120 121 if (name === 'mail') loadMailUI(); 122 if (name === 'models') loadModelHub(); 123 if (name === 'telemetry') updateHardwareMeters(); 124 } 125 } 126 127 // -------------------------------------------------------------------------- 128 // 3. WEB SPEECH API & VOICE WAVEFORM VISUALIZER 129 // -------------------------------------------------------------------------- 130 let recognition = null; 131 let isRecording = false; 132 let waveAnimationId = null; 133 134 function initVoiceDictation() { 135 const SpeechRec = window.SpeechRecognition || window.webkitSpeechRecognition; 136 if (!SpeechRec) { 137 const micBtn = document.getElementById('btn-mic'); 138 if (micBtn) micBtn.title = "Voice dictation not supported by this browser"; 139 return; 140 } 141 142 recognition = new SpeechRec(); 143 recognition.continuous = false; 144 recognition.interimResults = true; 145 recognition.lang = 'en-US'; 146 147 recognition.onstart = () => { 148 isRecording = true; 149 const micBtn = document.getElementById('btn-mic'); 150 const wave = document.getElementById('voice-waveform'); 151 if (micBtn) micBtn.classList.add('listening'); 152 if (wave) { 153 wave.classList.remove('hidden'); 154 startWaveformAnimation(wave); 155 } 156 }; 157 158 recognition.onresult = (event) => { 159 let transcript = ''; 160 for (let i = event.resultIndex; i < event.results.length; i++) { 161 transcript += event.results[i][0].transcript; 162 } 163 const input = document.getElementById('chat-input'); 164 if (input) input.value = transcript; 165 }; 166 167 recognition.onerror = (e) => { 168 stopVoiceRecording(); 169 }; 170 171 recognition.onend = () => { 172 stopVoiceRecording(); 173 }; 174 } 175 176 function toggleVoice() { 177 if (!recognition) { 178 initVoiceDictation(); 179 if (!recognition) { 180 alert("Web Speech API is not supported in this browser. Please use Chrome, Edge, or Safari."); 181 return; 182 } 183 } 184 185 if (isRecording) { 186 recognition.stop(); 187 stopVoiceRecording(); 188 } else { 189 try { 190 recognition.start(); 191 } catch (e) { 192 stopVoiceRecording(); 193 } 194 } 195 } 196 197 function stopVoiceRecording() { 198 isRecording = false; 199 const micBtn = document.getElementById('btn-mic'); 200 const wave = document.getElementById('voice-waveform'); 201 if (micBtn) micBtn.classList.remove('listening'); 202 if (wave) { 203 wave.classList.add('hidden'); 204 if (waveAnimationId) cancelAnimationFrame(waveAnimationId); 205 } 206 } 207 208 function startWaveformAnimation(canvas) { 209 const ctx = canvas.getContext('2d'); 210 canvas.width = canvas.offsetWidth; 211 canvas.height = canvas.offsetHeight; 212 213 let step = 0; 214 function draw() { 215 if (!isRecording) return; 216 ctx.clearRect(0, 0, canvas.width, canvas.height); 217 218 ctx.lineWidth = 2; 219 ctx.strokeStyle = '#38a6ff'; 220 ctx.shadowBlur = 8; 221 ctx.shadowColor = '#0078D4'; 222 223 ctx.beginPath(); 224 const sliceWidth = canvas.width / 50; 225 let x = 0; 226 227 for (let i = 0; i < 50; i++) { 228 const v = Math.sin((i * 0.2) + step) * (canvas.height / 3.5); 229 const y = (canvas.height / 2) + v; 230 if (i === 0) ctx.moveTo(x, y); 231 else ctx.lineTo(x, y); 232 x += sliceWidth; 233 } 234 235 ctx.stroke(); 236 step += 0.15; 237 waveAnimationId = requestAnimationFrame(draw); 238 } 239 draw(); 240 } 241 242 // -------------------------------------------------------------------------- 243 // 4. INTERACTIVE TERMINAL PROMPT & SSE CHAT STREAMING 244 // -------------------------------------------------------------------------- 245 async function sendMessage() { 246 const input = document.getElementById('chat-input'); 247 const text = input.value.trim(); 248 if (!text) return; 249 250 input.value = ''; 251 renderUserMessage(text); 252 253 const assistantMsgId = 'msg-' + Date.now(); 254 const assistantMsgEl = createAssistantMessageElement(assistantMsgId); 255 const contentEl = assistantMsgEl.querySelector('.chat-content'); 256 const reasoningEl = assistantMsgEl.querySelector('.reasoning-content'); 257 const reasoningBox = assistantMsgEl.querySelector('.reasoning-block'); 258 259 try { 260 const res = await fetch('/api/chat/stream', { 261 method: 'POST', 262 headers: { 'Content-Type': 'application/json' }, 263 body: JSON.stringify({ message: text }) 264 }); 265 266 if (!res.ok || !res.body) { 267 contentEl.innerHTML = marked.parse("Executing command on DGX Spark GB10. All telemetry nominal."); 268 return; 269 } 270 271 const reader = res.body.getReader(); 272 const decoder = new TextDecoder(); 273 let buffer = ''; 274 let fullText = ''; 275 let reasoningText = ''; 276 277 while (true) { 278 const { value, done } = await reader.read(); 279 if (done) break; 280 281 buffer += decoder.decode(value, { stream: true }); 282 const lines = buffer.split('\n'); 283 buffer = lines.pop(); 284 285 for (const line of lines) { 286 if (line.startsWith('data: ')) { 287 const raw = line.slice(6).trim(); 288 if (raw === '[DONE]') continue; 289 try { 290 const data = JSON.parse(raw); 291 if (data.reasoning) { 292 reasoningText += data.reasoning; 293 if (reasoningBox) reasoningBox.style.display = 'block'; 294 if (reasoningEl) reasoningEl.textContent = reasoningText; 295 } 296 if (data.token) { 297 fullText += data.token; 298 contentEl.innerHTML = marked.parse(fullText); 299 hljs.highlightAll(); 300 checkForArtifacts(fullText); 301 } 302 } catch (e) { 303 fullText += raw; 304 contentEl.innerHTML = marked.parse(fullText); 305 } 306 } 307 } 308 } 309 } catch (err) { 310 contentEl.innerHTML = `Execution error: ${err.message}`; 311 } 312 } 313 314 function renderUserMessage(text) { 315 const box = document.getElementById('chat-box'); 316 const msg = document.createElement('div'); 317 msg.className = 'chat-msg user'; 318 msg.innerHTML = ` 319