Spaces:
Paused
Paused
P3.3: quota HUD + fallback notices
Browse files- app.js +5 -5
- avatar.js +1 -1
- index.html +2 -2
- master.js +1 -1
- real.js +14 -4
- server/main.py +10 -0
- style.css +2 -0
- workspace.js +9 -4
app.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
import * as THREE from './vendor/three.module.min.js';
|
| 2 |
import { STUDIOS, stopLoops } from './widgets.js?v=50';
|
| 3 |
-
import './real.js?v=
|
| 4 |
-
import './avatar.js?v=
|
| 5 |
-
import './master.js?v=
|
| 6 |
-
import './workspace.js?v=
|
| 7 |
-
import { icon } from './icons.js?v=
|
| 8 |
import { RoomEnvironment } from './vendor/addons/environments/RoomEnvironment.js';
|
| 9 |
import { EffectComposer } from './vendor/addons/postprocessing/EffectComposer.js';
|
| 10 |
import { RenderPass } from './vendor/addons/postprocessing/RenderPass.js';
|
|
|
|
| 1 |
import * as THREE from './vendor/three.module.min.js';
|
| 2 |
import { STUDIOS, stopLoops } from './widgets.js?v=50';
|
| 3 |
+
import './real.js?v=74';
|
| 4 |
+
import './avatar.js?v=74';
|
| 5 |
+
import './master.js?v=74';
|
| 6 |
+
import './workspace.js?v=74';
|
| 7 |
+
import { icon } from './icons.js?v=74';
|
| 8 |
import { RoomEnvironment } from './vendor/addons/environments/RoomEnvironment.js';
|
| 9 |
import { EffectComposer } from './vendor/addons/postprocessing/EffectComposer.js';
|
| 10 |
import { RenderPass } from './vendor/addons/postprocessing/RenderPass.js';
|
avatar.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
// Avatar / Persona studio (DoD): persistent avatars as workspace asset type `avatar`
|
| 2 |
// avatars/<slug>/avatar.json + ref.webp + voice.wav · reused by Chat, Image (Kontext), agents.
|
| 3 |
import { STUDIOS, onStop } from './widgets.js?v=50';
|
| 4 |
-
import { run, result, MODULES, esc, hf, stTxt, url, badge, setS, keep, LS, FLUX, KONTEXT, TTS, CHAT, signedIn } from './real.js?v=
|
| 5 |
|
| 6 |
const LANGS = ['German', 'English', 'French', 'Spanish', 'Auto'];
|
| 7 |
const slug = (n) => (n || 'avatar').toLowerCase().normalize('NFKD').replace(/[^\w]+/g, '-').replace(/^-|-$/g, '').slice(0, 40) || 'avatar';
|
|
|
|
| 1 |
// Avatar / Persona studio (DoD): persistent avatars as workspace asset type `avatar`
|
| 2 |
// avatars/<slug>/avatar.json + ref.webp + voice.wav · reused by Chat, Image (Kontext), agents.
|
| 3 |
import { STUDIOS, onStop } from './widgets.js?v=50';
|
| 4 |
+
import { run, result, MODULES, esc, hf, stTxt, url, badge, setS, keep, LS, FLUX, KONTEXT, TTS, CHAT, signedIn } from './real.js?v=74';
|
| 5 |
|
| 6 |
const LANGS = ['German', 'English', 'French', 'Spanish', 'Auto'];
|
| 7 |
const slug = (n) => (n || 'avatar').toLowerCase().normalize('NFKD').replace(/[^\w]+/g, '-').replace(/^-|-$/g, '').slice(0, 40) || 'avatar';
|
index.html
CHANGED
|
@@ -8,7 +8,7 @@
|
|
| 8 |
<title>STUDIUS · DAS Studio — Einswarm</title>
|
| 9 |
<link rel="icon" href="assets/einswarm-mascot.webp">
|
| 10 |
<link rel="preload" href="fonts/outfit-latin-wght.woff2" as="font" type="font/woff2" crossorigin>
|
| 11 |
-
<link rel="stylesheet" href="style.css?v=
|
| 12 |
</head>
|
| 13 |
<body>
|
| 14 |
<canvas id="gl"></canvas>
|
|
@@ -49,6 +49,6 @@
|
|
| 49 |
|
| 50 |
<a id="bmc" href="https://www.buymeacoffee.com/2btainment" target="_blank" rel="noopener noreferrer">Buy me a coffee</a>
|
| 51 |
<noscript><p style="color:#f2c94c;padding:2em">STUDIUS braucht JavaScript.</p></noscript>
|
| 52 |
-
<script type="module" src="app.js?v=
|
| 53 |
</body>
|
| 54 |
</html>
|
|
|
|
| 8 |
<title>STUDIUS · DAS Studio — Einswarm</title>
|
| 9 |
<link rel="icon" href="assets/einswarm-mascot.webp">
|
| 10 |
<link rel="preload" href="fonts/outfit-latin-wght.woff2" as="font" type="font/woff2" crossorigin>
|
| 11 |
+
<link rel="stylesheet" href="style.css?v=74">
|
| 12 |
</head>
|
| 13 |
<body>
|
| 14 |
<canvas id="gl"></canvas>
|
|
|
|
| 49 |
|
| 50 |
<a id="bmc" href="https://www.buymeacoffee.com/2btainment" target="_blank" rel="noopener noreferrer">Buy me a coffee</a>
|
| 51 |
<noscript><p style="color:#f2c94c;padding:2em">STUDIUS braucht JavaScript.</p></noscript>
|
| 52 |
+
<script type="module" src="app.js?v=74"></script>
|
| 53 |
</body>
|
| 54 |
</html>
|
master.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
// Mastering studio (DoD): client-side WebAudio chain EQ → compressor → limiter, loudness normalisation to target LUFS
|
| 2 |
// (ITU-R BS.1770-4 K-weighting + gating, measured offline), live meter, A/B, WAV/MP3 export, save to workspace.
|
| 3 |
import { STUDIOS, onStop, loop, cv } from './widgets.js?v=50';
|
| 4 |
-
import { result, MODULES, esc, setS, keep } from './real.js?v=
|
| 5 |
|
| 6 |
/* ---------- BS.1770 loudness ---------- */
|
| 7 |
function biquad(x, b0, b1, b2, a0, a1, a2) { const y = new Float32Array(x.length); b0 /= a0; b1 /= a0; b2 /= a0; a1 /= a0; a2 /= a0; let x1 = 0, x2 = 0, y1 = 0, y2 = 0;
|
|
|
|
| 1 |
// Mastering studio (DoD): client-side WebAudio chain EQ → compressor → limiter, loudness normalisation to target LUFS
|
| 2 |
// (ITU-R BS.1770-4 K-weighting + gating, measured offline), live meter, A/B, WAV/MP3 export, save to workspace.
|
| 3 |
import { STUDIOS, onStop, loop, cv } from './widgets.js?v=50';
|
| 4 |
+
import { result, MODULES, esc, setS, keep } from './real.js?v=74';
|
| 5 |
|
| 6 |
/* ---------- BS.1770 loudness ---------- */
|
| 7 |
function biquad(x, b0, b1, b2, a0, a1, a2) { const y = new Float32Array(x.length); b0 /= a0; b1 /= a0; b2 /= a0; a1 /= a0; a2 /= a0; let x1 = 0, x2 = 0, y1 = 0, y2 = 0;
|
real.js
CHANGED
|
@@ -49,14 +49,24 @@ async function runUser(space, ep, data, { onStatus = () => {}, onData = () => {}
|
|
| 49 |
window.__studiusLog.push({ space, ep, via: 'user', ms: Math.round(performance.now() - t0) }); return last;
|
| 50 |
}
|
| 51 |
export const signedIn = () => !!window.__ws?.me?.signedIn;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
let LASTM = '';
|
| 53 |
-
export async function run(space, ep, data, opt = {}) { LASTM = space;
|
| 54 |
if (signedIn()) {
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
}
|
| 58 |
const anon = {}; for (const [k, v] of Object.entries(data)) anon[k] = v instanceof Blob ? handle_file(v) : typeof v === 'string' && v.startsWith('/api/') && k !== 'prompt' ? handle_file(await (await fetch(v)).blob()) : v;
|
| 59 |
-
const d = await runAnon(space, ep, anon, opt); opt.el && via(opt.el, 'anon'); return d;
|
|
|
|
| 60 |
}
|
| 61 |
const via = (el, v) => { const c = el.closest?.('#pop')?.querySelector('.credit'); if (c) { c.querySelector('.via')?.remove(); c.insertAdjacentHTML('beforeend', `<span class="via"> · ${v === 'user' ? '🔑 deine HF-Quota' : 'anonyme Quota'}</span>`); } };
|
| 62 |
const stTxt = (m) => m.stage === 'pending' ? (m.position != null ? `Warteschlange: Platz ${m.position + 1}${m.queue_size ? '/' + m.queue_size : ''}${m.eta ? ' · ETA ' + Math.round(m.eta) + ' s' : ''}` : 'Warte auf GPU…')
|
|
|
|
| 49 |
window.__studiusLog.push({ space, ep, via: 'user', ms: Math.round(performance.now() - t0) }); return last;
|
| 50 |
}
|
| 51 |
export const signedIn = () => !!window.__ws?.me?.signedIn;
|
| 52 |
+
/* quota: user's own ZeroGPU seconds (HUD) + clear fallback notices */
|
| 53 |
+
export async function refreshQuota() { try { const q = await (await fetch('/api/quota', { credentials: 'include' })).json(); window.__quota = q; window.dispatchEvent(new CustomEvent('studius-quota', { detail: q })); return q; } catch (e) { return null; } }
|
| 54 |
+
const fmtReset = (iso) => { if (!iso) return ''; const ms = new Date(iso) - Date.now(); if (ms <= 0) return 'gleich'; const h = Math.floor(ms / 36e5), m = Math.round(ms % 36e5 / 6e4); return `in ${h ? h + ' h ' : ''}${m} min (${new Date(iso).toLocaleTimeString('de-DE', { hour: '2-digit', minute: '2-digit' })})`; };
|
| 55 |
+
const isQuota = (m) => /quota|ZeroGPU|GPU task aborted|exceeded/i.test(m || '');
|
| 56 |
+
function notice(el, html, kind = 'warn') { const pop = el?.closest?.('#pop'); if (!pop) return; let n = pop.querySelector('.qnote'); if (!n) { n = document.createElement('div'); n.className = 'qnote'; n.setAttribute('role', 'status'); (pop.querySelector('.credit') || pop.lastElementChild).insertAdjacentElement('beforebegin', n); } n.className = 'qnote ' + kind; n.innerHTML = html; window.__notice = n.textContent; }
|
| 57 |
let LASTM = '';
|
| 58 |
+
export async function run(space, ep, data, opt = {}) { LASTM = space; let why = '';
|
| 59 |
if (signedIn()) {
|
| 60 |
+
const q = window.__quota; if (q?.ok && q.remaining < 60) notice(opt.el, `⚡ Nur noch <b>${Math.round(q.remaining)} s</b> deiner ZeroGPU-Quota${q.resetsAt ? ' · Reset ' + fmtReset(q.resetsAt) : ''} – evtl. Fallback.`);
|
| 61 |
+
try { const d = await runUser(space, ep, data, opt); opt.el && via(opt.el, 'user'); refreshQuota(); return d; }
|
| 62 |
+
catch (e) { if (e.message === 'abgebrochen' || (opt.el && !opt.el.isConnected)) throw e; console.warn('user-quota run failed, trying anonymous:', e.message); why = e.message;
|
| 63 |
+
const q2 = await refreshQuota();
|
| 64 |
+
notice(opt.el, isQuota(why) ? `⚠ <b>Deine ZeroGPU-Quota ist aufgebraucht</b>${(m => m ? ` (${m[1]} s angefragt, ${m[2]} s übrig)` : '')(why.match(/\((\d+)s requested vs\. (\d+)s left\)/))}${q2?.ok && q2.resetsAt ? ' · Reset ' + fmtReset(q2.resetsAt) : ''}. Fallback: <b>anonyme Quota</b> – kann langsamer sein oder ebenfalls scheitern. <a href="https://huggingface.co/pricing" target="_blank" rel="noopener">Mehr Quota (PRO)</a>` : `⚠ Lauf mit deinem Konto fehlgeschlagen (${esc(why.slice(0, 120))}). Fallback: anonyme Quota.`);
|
| 65 |
+
opt.onStatus?.({ stage: 'pending', message: 'Fallback: anonyme Quota' }); }
|
| 66 |
}
|
| 67 |
const anon = {}; for (const [k, v] of Object.entries(data)) anon[k] = v instanceof Blob ? handle_file(v) : typeof v === 'string' && v.startsWith('/api/') && k !== 'prompt' ? handle_file(await (await fetch(v)).blob()) : v;
|
| 68 |
+
try { const d = await runAnon(space, ep, anon, opt); opt.el && via(opt.el, 'anon'); return d; }
|
| 69 |
+
catch (e) { opt.el?.closest?.('#pop')?.querySelector('.credit .via')?.remove(); if (why || isQuota(e.message)) notice(opt.el, (window.__notice && why ? esc(window.__notice) + '<br>' : '') + (isQuota(e.message) ? '⛔ <b>Auch die anonyme Quota ist erschöpft</b>' : `⛔ <b>Anonymer Fallback fehlgeschlagen</b> (${esc(e.message.slice(0, 100))})`) + ` – ${signedIn() ? 'warte auf den Reset deiner Quota' : 'melde dich mit Hugging Face an, um deine eigene Quota zu nutzen'}. Das Studio zeigt bis dahin eine <b>Simulation</b>.`, 'err'); throw e; }
|
| 70 |
}
|
| 71 |
const via = (el, v) => { const c = el.closest?.('#pop')?.querySelector('.credit'); if (c) { c.querySelector('.via')?.remove(); c.insertAdjacentHTML('beforeend', `<span class="via"> · ${v === 'user' ? '🔑 deine HF-Quota' : 'anonyme Quota'}</span>`); } };
|
| 72 |
const stTxt = (m) => m.stage === 'pending' ? (m.position != null ? `Warteschlange: Platz ${m.position + 1}${m.queue_size ? '/' + m.queue_size : ''}${m.eta ? ' · ETA ' + Math.round(m.eta) + ' s' : ''}` : 'Warte auf GPU…')
|
server/main.py
CHANGED
|
@@ -285,6 +285,16 @@ def ws_pin(req: Request, bucket: str = Form(...), path: str = Form(...), studio:
|
|
| 285 |
api.batch_bucket_files(bucket, add=[(json.dumps(e, indent=1).encode(), mpath(p))]); return {"path": p, "pins": e["pins"]}
|
| 286 |
except Exception as e: herr(e)
|
| 287 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
@app.middleware("http")
|
| 289 |
async def nocache(req, call_next):
|
| 290 |
r = await call_next(req)
|
|
|
|
| 285 |
api.batch_bucket_files(bucket, add=[(json.dumps(e, indent=1).encode(), mpath(p))]); return {"path": p, "pins": e["pins"]}
|
| 286 |
except Exception as e: herr(e)
|
| 287 |
|
| 288 |
+
@app.get("/api/quota")
|
| 289 |
+
async def quota(req: Request):
|
| 290 |
+
"""User's own ZeroGPU quota (GPU-seconds) from the Hub. Token stays server-side."""
|
| 291 |
+
s = session(req)
|
| 292 |
+
if not s: return {"ok": False, "reason": "anon", "note": "Anonym: ca. 2 min GPU/Tag pro IP"}
|
| 293 |
+
async with httpx.AsyncClient(timeout=15) as c:
|
| 294 |
+
r = await c.get(f"{HUB}/api/spaces/zero-gpu/quota", headers={"Authorization": f"Bearer {s['token']}"})
|
| 295 |
+
if r.status_code != 200: return {"ok": False, "reason": f"HTTP {r.status_code}", "note": "Quota für dieses Login nicht abrufbar"}
|
| 296 |
+
q = r.json(); return {"ok": True, "base": q.get("base"), "remaining": q.get("current"), "resetsAt": q.get("resetsAt"), "overquotaUsed": q.get("overquotaUsed", 0), "runs": q.get("runs")}
|
| 297 |
+
|
| 298 |
@app.middleware("http")
|
| 299 |
async def nocache(req, call_next):
|
| 300 |
r = await call_next(req)
|
style.css
CHANGED
|
@@ -230,3 +230,5 @@ body:not(.live) #beebtn{display:none}
|
|
| 230 |
.bkl .sk{height:22px;margin:4px 0;border-radius:4px;background:linear-gradient(90deg,rgba(255,255,255,.04),rgba(255,255,255,.1),rgba(255,255,255,.04));background-size:200% 100%;animation:skel 1.2s infinite}
|
| 231 |
@keyframes skel{to{background-position:-200% 0}}.bnew{margin-top:8px;border-top:1px solid var(--line);padding-top:6px}.bnew summary{cursor:pointer;color:var(--gold)}.bnew .row{align-items:center;gap:4px}.bnew #bname{flex:1;min-width:0}.chk{display:flex;gap:6px;align-items:center;margin:4px 0}.stat.err{color:#ff8a7a}
|
| 232 |
@keyframes pulse{50%{opacity:.3}}
|
|
|
|
|
|
|
|
|
| 230 |
.bkl .sk{height:22px;margin:4px 0;border-radius:4px;background:linear-gradient(90deg,rgba(255,255,255,.04),rgba(255,255,255,.1),rgba(255,255,255,.04));background-size:200% 100%;animation:skel 1.2s infinite}
|
| 231 |
@keyframes skel{to{background-position:-200% 0}}.bnew{margin-top:8px;border-top:1px solid var(--line);padding-top:6px}.bnew summary{cursor:pointer;color:var(--gold)}.bnew .row{align-items:center;gap:4px}.bnew #bname{flex:1;min-width:0}.chk{display:flex;gap:6px;align-items:center;margin:4px 0}.stat.err{color:#ff8a7a}
|
| 232 |
@keyframes pulse{50%{opacity:.3}}
|
| 233 |
+
.hbtn.q{cursor:default;color:#9fe39f;border-color:rgba(159,227,159,.4)}.hbtn.q.mid{color:#f2c94c;border-color:#f2c94c}.hbtn.q.low{color:#ff8a7a;border-color:#ff8a7a}
|
| 234 |
+
.qnote{margin:6px 0;padding:6px 8px;border-radius:4px;font-size:11px;line-height:1.4;background:rgba(242,201,76,.1);border:1px solid rgba(242,201,76,.4)}.qnote.err{background:rgba(255,90,70,.1);border-color:rgba(255,120,100,.5)}.qnote a{color:var(--gold)}
|
workspace.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
// STUDIUS empire backbone (frontend): HF sign-in, Workspace (user's HF Bucket), asset bus hand-off, bee agent dock.
|
| 2 |
-
import { MODULES } from './real.js?v=
|
| 3 |
-
import { Avatars } from './avatar.js?v=
|
| 4 |
const $ = (s, r = document) => r.querySelector(s);
|
| 5 |
const esc = (t) => String(t ?? '').replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
| 6 |
const ST = () => window.__studius.STUDIOS;
|
|
@@ -11,7 +11,7 @@ async function api(path, opt = {}) { const r = await fetch(path, { credentials:
|
|
| 11 |
const form = (o) => { const f = new FormData(); Object.entries(o).forEach(([k, v]) => f.append(k, v)); return f; };
|
| 12 |
|
| 13 |
/* HUD buttons */
|
| 14 |
-
$('#hud .hudr').insertAdjacentHTML('afterbegin', `<a id="signin" class="hbtn" href="/login" target="_blank" rel="noopener" hidden>🤗<span class="t"> Sign in with Hugging Face</span><span class="s"> Login</span></a><button id="bkchip" class="hbtn" aria-label="Workspace-Bucket wechseln" hidden></button><button id="wsbtn" class="hbtn" aria-label="Workspace öffnen" hidden>▤<span class="t"> Workspace</span></button><span id="who" hidden></span>`);
|
| 15 |
document.body.insertAdjacentHTML('beforeend', `<aside id="wsp" hidden role="dialog" aria-label="Workspace"><div class="wh"><b>WORKSPACE</b><small id="wsb"></small><button class="x" aria-label="Workspace schließen">✕</button></div><div class="wbody"></div></aside>
|
| 16 |
<button id="beebtn" aria-label="Bee-Agenten öffnen" title="Bee-Agenten">🐝<span>Agents</span></button>
|
| 17 |
<aside id="bees" hidden role="dialog" aria-label="Bee-Agenten"><div class="wh"><b>BEE AGENTS</b><select id="agsel" aria-label="Agent wählen"></select><button class="x" aria-label="Agenten schließen">✕</button></div><div class="agcfg"></div><div class="blog" aria-live="polite"></div><details class="jw"><summary>Jobs (Server)</summary><div class="jobs"></div></details><div class="brow"><input id="bin" aria-label="Auftrag an Agent" placeholder="Auftrag… z.B. 'Male eine goldene Biene'"><button class="btn" id="bsend" aria-label="Senden">➤</button></div></aside>`);
|
|
@@ -24,13 +24,18 @@ $('#beebtn').onclick = () => { $('#bees').hidden = !$('#bees').hidden; if (!$('#
|
|
| 24 |
async function refreshMe() {
|
| 25 |
try { W.me = await api('/api/me'); W.backend = true; } catch (e) { W.backend = false; W.me = null; }
|
| 26 |
$('#signin').hidden = !W.backend || !!W.me?.signedIn || !W.me?.oauth; $('#wsbtn').hidden = !W.backend;
|
| 27 |
-
hudBucket(); if (W.me?.signedIn) loadBuckets().catch(() => {});
|
| 28 |
const who = $('#who'); who.hidden = !W.me?.signedIn; if (W.me?.signedIn) who.innerHTML = `${W.me.user.avatar ? `<img src="${esc(W.me.user.avatar)}" alt="">` : ''}${esc(W.me.user.name)}`;
|
| 29 |
}
|
| 30 |
const fresh = /signedin=1/.test(location.search); if (fresh) history.replaceState(null, '', '/');
|
| 31 |
let wasIn = null; const onMe = () => { const now = !!W.me?.signedIn; if (now && (fresh || wasIn === false) && !W.bucket) { $('#wsp').hidden = false; renderWS(); } wasIn = now; };
|
| 32 |
window.__wsReady = refreshMe().then(onMe); addEventListener('focus', () => refreshMe().then(onMe));
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
/* Workspace panel */
|
| 35 |
async function renderWS() {
|
| 36 |
const b = $('#wsp .wbody'); $('#wsb').textContent = W.bucket || '';
|
|
|
|
| 1 |
// STUDIUS empire backbone (frontend): HF sign-in, Workspace (user's HF Bucket), asset bus hand-off, bee agent dock.
|
| 2 |
+
import { MODULES, refreshQuota } from './real.js?v=74';
|
| 3 |
+
import { Avatars } from './avatar.js?v=74';
|
| 4 |
const $ = (s, r = document) => r.querySelector(s);
|
| 5 |
const esc = (t) => String(t ?? '').replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
| 6 |
const ST = () => window.__studius.STUDIOS;
|
|
|
|
| 11 |
const form = (o) => { const f = new FormData(); Object.entries(o).forEach(([k, v]) => f.append(k, v)); return f; };
|
| 12 |
|
| 13 |
/* HUD buttons */
|
| 14 |
+
$('#hud .hudr').insertAdjacentHTML('afterbegin', `<a id="signin" class="hbtn" href="/login" target="_blank" rel="noopener" hidden>🤗<span class="t"> Sign in with Hugging Face</span><span class="s"> Login</span></a><span id="quota" class="hbtn q" hidden title="Deine ZeroGPU-Quota"></span><button id="bkchip" class="hbtn" aria-label="Workspace-Bucket wechseln" hidden></button><button id="wsbtn" class="hbtn" aria-label="Workspace öffnen" hidden>▤<span class="t"> Workspace</span></button><span id="who" hidden></span>`);
|
| 15 |
document.body.insertAdjacentHTML('beforeend', `<aside id="wsp" hidden role="dialog" aria-label="Workspace"><div class="wh"><b>WORKSPACE</b><small id="wsb"></small><button class="x" aria-label="Workspace schließen">✕</button></div><div class="wbody"></div></aside>
|
| 16 |
<button id="beebtn" aria-label="Bee-Agenten öffnen" title="Bee-Agenten">🐝<span>Agents</span></button>
|
| 17 |
<aside id="bees" hidden role="dialog" aria-label="Bee-Agenten"><div class="wh"><b>BEE AGENTS</b><select id="agsel" aria-label="Agent wählen"></select><button class="x" aria-label="Agenten schließen">✕</button></div><div class="agcfg"></div><div class="blog" aria-live="polite"></div><details class="jw"><summary>Jobs (Server)</summary><div class="jobs"></div></details><div class="brow"><input id="bin" aria-label="Auftrag an Agent" placeholder="Auftrag… z.B. 'Male eine goldene Biene'"><button class="btn" id="bsend" aria-label="Senden">➤</button></div></aside>`);
|
|
|
|
| 24 |
async function refreshMe() {
|
| 25 |
try { W.me = await api('/api/me'); W.backend = true; } catch (e) { W.backend = false; W.me = null; }
|
| 26 |
$('#signin').hidden = !W.backend || !!W.me?.signedIn || !W.me?.oauth; $('#wsbtn').hidden = !W.backend;
|
| 27 |
+
hudBucket(); if (W.me?.signedIn) { loadBuckets().catch(() => {}); refreshQuota(); } else $('#quota').hidden = true;
|
| 28 |
const who = $('#who'); who.hidden = !W.me?.signedIn; if (W.me?.signedIn) who.innerHTML = `${W.me.user.avatar ? `<img src="${esc(W.me.user.avatar)}" alt="">` : ''}${esc(W.me.user.name)}`;
|
| 29 |
}
|
| 30 |
const fresh = /signedin=1/.test(location.search); if (fresh) history.replaceState(null, '', '/');
|
| 31 |
let wasIn = null; const onMe = () => { const now = !!W.me?.signedIn; if (now && (fresh || wasIn === false) && !W.bucket) { $('#wsp').hidden = false; renderWS(); } wasIn = now; };
|
| 32 |
window.__wsReady = refreshMe().then(onMe); addEventListener('focus', () => refreshMe().then(onMe));
|
| 33 |
|
| 34 |
+
addEventListener('studius-quota', (e) => { const q = e.detail, el = $('#quota'); if (!q?.ok) { el.hidden = true; return; } el.hidden = false;
|
| 35 |
+
const r = Math.max(0, q.remaining), p = q.base ? r / q.base : 0; el.className = 'hbtn q' + (r < 60 ? ' low' : p < .25 ? ' mid' : '');
|
| 36 |
+
el.innerHTML = `⚡<span class="t"> ${Math.floor(r / 60)}:${String(Math.round(r % 60)).padStart(2, '0')} min GPU</span><span class="s"> ${Math.round(r / 60)}m</span>`;
|
| 37 |
+
el.title = `ZeroGPU-Quota: ${Math.round(r)} von ${q.base} s übrig` + (q.resetsAt ? ' · Reset ' + new Date(q.resetsAt).toLocaleString('de-DE') : ' · voll'); });
|
| 38 |
+
|
| 39 |
/* Workspace panel */
|
| 40 |
async function renderWS() {
|
| 41 |
const b = $('#wsp .wbody'); $('#wsb').textContent = W.bucket || '';
|