Percy3822 commited on
Commit
dd32e09
·
verified ·
1 Parent(s): 783a8d5

Create static/ui.html

Browse files
Files changed (1) hide show
  1. static/ui.html +172 -0
static/ui.html ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <title>Brain Console</title>
7
+ <style>
8
+ :root{--bg:#0b1020;--panel:#121a2e;--muted:#7280a7;--acc:#7aa2ff;--good:#2ecc71;--bad:#ff6b6b}
9
+ *{box-sizing:border-box} body{margin:0;background:var(--bg);color:#e9eefc;font-family:Inter,system-ui,Segoe UI,Roboto,Arial,sans-serif}
10
+ header{padding:16px 20px;background:linear-gradient(90deg,#0e1630,#0d1a3a)}
11
+ h1{margin:0;font-size:18px;letter-spacing:.3px}
12
+ main{display:grid;gap:16px;padding:16px}
13
+ .grid{display:grid;gap:16px}
14
+ @media (min-width:900px){.grid{grid-template-columns:1.2fr .8fr}}
15
+ .card{background:var(--panel);border:1px solid #1b2544;border-radius:14px;box-shadow:0 6px 20px rgba(0,0,0,.2)}
16
+ .card h2{margin:0;padding:12px 14px;border-bottom:1px solid #1b2544;font-size:14px;color:#cbd7ff}
17
+ .card .body{padding:12px 14px}
18
+ .row{display:flex;gap:8px;flex-wrap:wrap;align-items:center}
19
+ button{background:#1a2750;color:#dfe8ff;border:1px solid #27407d;border-radius:10px;padding:8px 12px;cursor:pointer}
20
+ button:hover{background:#213062}
21
+ .pill{padding:4px 8px;border-radius:999px;font-size:12px;border:1px solid #2b3e7a;color:#cdd8ff}
22
+ .pill.good{border-color:var(--good);color:#b8ffd3}
23
+ .pill.bad{border-color:var(--bad);color:#ffd6d6}
24
+ textarea{width:100%;background:#0d142a;color:#e9eefc;border:1px solid #22315e;border-radius:10px;padding:10px;min-height:180px;font-family:ui-monospace,monospace}
25
+ pre{margin:0;white-space:pre-wrap;word-break:break-word;font-family:ui-monospace,monospace;font-size:12px;color:#d9e6ff}
26
+ .small{font-size:12px;color:var(--muted)}
27
+ .sep{height:1px;background:#1b2544;margin:10px 0}
28
+ audio{width:100%}
29
+ .right{display:flex;gap:8px;justify-content:flex-end}
30
+ </style>
31
+ </head>
32
+ <body>
33
+ <header><h1>🧠 Brain Console</h1></header>
34
+ <main class="grid">
35
+ <section class="card">
36
+ <h2>Quick Actions</h2>
37
+ <div class="body">
38
+ <div class="row">
39
+ <button id="btnHealth">GET /health</button>
40
+ <button id="btnWarmup">POST /warmup</button>
41
+ <button id="btnSend">POST /code_help</button>
42
+ <span id="depPy" class="pill">python_ai: —</span>
43
+ <span id="depTts" class="pill">tts: —</span>
44
+ <span id="depStt" class="pill">stt: —</span>
45
+ <span id="depVis" class="pill">vision: —</span>
46
+ <span id="depMem" class="pill">memory: —</span>
47
+ </div>
48
+ <div class="sep"></div>
49
+ <div class="row">
50
+ <button id="btnLoadSample">Load Sample Body</button>
51
+ <button id="btnMinify">Minify JSON</button>
52
+ <button id="btnPretty">Pretty JSON</button>
53
+ </div>
54
+ </div>
55
+ </section>
56
+
57
+ <section class="card">
58
+ <h2>Request Body (for POST /code_help)</h2>
59
+ <div class="body">
60
+ <textarea id="reqBody" spellcheck="false"></textarea>
61
+ <div class="row right">
62
+ <span class="small">Tip: update file/lang/viewport/diag. Fix any __ if WhatsApp changed them.</span>
63
+ </div>
64
+ </div>
65
+ </section>
66
+
67
+ <section class="card">
68
+ <h2>Response</h2>
69
+ <div class="body">
70
+ <pre id="resp">(responses will appear here)</pre>
71
+ <div class="sep"></div>
72
+ <div id="audioWrap" style="display:none">
73
+ <div class="small">TTS (if provided):</div>
74
+ <audio id="ttsAudio" controls></audio>
75
+ </div>
76
+ </div>
77
+ </section>
78
+
79
+ <section class="card">
80
+ <h2>Patch Preview</h2>
81
+ <div class="body">
82
+ <pre id="patchPre">(unified diff will appear here)</pre>
83
+ </div>
84
+ </section>
85
+ </main>
86
+
87
+ <script>
88
+ const $ = (id)=>document.getElementById(id);
89
+ const originBase = window.location.origin;
90
+
91
+ function setDeps(json){
92
+ const deps = (json && json.deps) || {};
93
+ const set = (el, ok) => {
94
+ el.textContent = el.textContent.split(':')[0] + ': ' + (ok ? 'true' : 'false');
95
+ el.classList.remove('good','bad');
96
+ el.classList.add(ok ? 'good' : 'bad');
97
+ };
98
+ set($('depPy'), !!deps.python_ai);
99
+ set($('depTts'), !!deps.tts);
100
+ set($('depStt'), !!deps.stt);
101
+ set($('depVis'), !!deps.vision);
102
+ set($('depMem'), !!deps.memory);
103
+ }
104
+
105
+ async function getHealth(){
106
+ const r = await fetch(originBase + '/health');
107
+ const j = await r.json();
108
+ $('resp').textContent = JSON.stringify(j,null,2);
109
+ setDeps(j);
110
+ }
111
+
112
+ async function postWarmup(){
113
+ const r = await fetch(originBase + '/warmup',{method:'POST'});
114
+ const j = await r.json();
115
+ $('resp').textContent = JSON.stringify(j,null,2);
116
+ }
117
+
118
+ function loadSample(){
119
+ const sample = {
120
+ utterance: "please fix the error and make it run",
121
+ telemetry: {
122
+ file: "main.py",
123
+ lang: "python",
124
+ cursor: { l: 88, c: 12 },
125
+ viewport: {
126
+ start: 72,
127
+ end: 110,
128
+ text: "def foo():\n return bar\n\nresult = foo()\nprint(reslt)\n"
129
+ },
130
+ diag: [{ l: 90, sev: "error", msg: "NameError: reslt is not defined" }],
131
+ term: "Traceback... NameError: reslt"
132
+ },
133
+ memory: { short: [], sess: ["Prefer list comprehensions."], proj: [] },
134
+ response_mode: "patch"
135
+ };
136
+ $('reqBody').value = JSON.stringify(sample,null,2);
137
+ }
138
+
139
+ function minify(){
140
+ try{ const j=JSON.parse($('reqBody').value); $('reqBody').value=JSON.stringify(j); }
141
+ catch(e){ alert('Invalid JSON'); }
142
+ }
143
+ function pretty(){
144
+ try{ const j=JSON.parse($('reqBody').value); $('reqBody').value=JSON.stringify(j,null,2); }
145
+ catch(e){ alert('Invalid JSON'); }
146
+ }
147
+
148
+ async function sendCodeHelp(){
149
+ let body;
150
+ try{ body = JSON.parse($('reqBody').value); }
151
+ catch(e){ alert('Invalid JSON'); return; }
152
+ const r = await fetch(originBase + '/code_help',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(body)});
153
+ const j = await r.json();
154
+ $('resp').textContent = JSON.stringify(j,null,2);
155
+ const patch = (j.ai && j.ai.patch) ? j.ai.patch : '(no patch)';
156
+ $('patchPre').textContent = patch;
157
+ if (j.tts_audio_url){ $('audioWrap').style.display=''; $('ttsAudio').src=j.tts_audio_url; }
158
+ else { $('audioWrap').style.display='none'; $('ttsAudio').removeAttribute('src'); }
159
+ }
160
+
161
+ $('btnHealth').onclick=getHealth;
162
+ $('btnWarmup').onclick=postWarmup;
163
+ $('btnSend').onclick=sendCodeHelp;
164
+ $('btnLoadSample').onclick=loadSample;
165
+ $('btnMinify').onclick=minify;
166
+ $('btnPretty').onclick=pretty;
167
+
168
+ loadSample();
169
+ getHealth();
170
+ </script>
171
+ </body>
172
+ </html>