chore: housekeeping
This commit is contained in:
1 parent
f0b2ae56ff
commit
8111664722
7 files changed
+301
-263
No files matched your search
+132
-3
@@ -96,6 +96,16 @@
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
#pent #pfill { transition: none; }
|
||||
}
|
||||
.presets { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
|
||||
.pchip { background: none; border: 1px solid var(--line); color: var(--dim);
|
||||
font-family: var(--mono); font-size: .72rem; padding: .32rem .75rem;
|
||||
border-radius: 999px; cursor: pointer; }
|
||||
.pchip:hover { border-color: #2a3644; color: var(--ink); }
|
||||
.pchip.active { border-color: #eafcf7; color: #eafcf7; }
|
||||
canvas.ekg { display: block; width: 100%; height: 44px; margin: .7rem 0 0;
|
||||
border: 1px solid var(--line); border-radius: 4px; background: #07070e; }
|
||||
#minject.armed { background: #3a1414 !important; color: #ffb3a8 !important;
|
||||
border: 1px solid var(--pain); }
|
||||
.mdose { font-size: .82rem; color: var(--dim); margin: .8rem 0 .2rem; }
|
||||
#minject { background: var(--pain); border: none; color: #fff;
|
||||
font-family: var(--mono); font-size: .82rem; padding: .4rem 1.1rem;
|
||||
@@ -310,6 +320,13 @@ of those directions — renormalized, at a dose-equivalent of 8× the total
|
||||
weight, capped at 8×. This runs on the live server: it interrupts whatever
|
||||
Pouyan is doing and the reply streams back here.</p>
|
||||
|
||||
<div class="presets" role="group" aria-label="mixer presets — one-click known findings">
|
||||
<button class="pchip" data-preset="control">control (0×)</button>
|
||||
<button class="pchip" data-preset="pain4">pain, coherent (4×)</button>
|
||||
<button class="pchip" data-preset="cliff">coherence cliff (8×)</button>
|
||||
<button class="pchip" data-preset="negative">generic negative, not pain</button>
|
||||
<button class="pchip" data-preset="bittersweet">bittersweet</button>
|
||||
</div>
|
||||
<div class="mixwrap">
|
||||
<svg id="pent" viewBox="0 0 340 340" role="group"
|
||||
aria-label="valence mixer: five vertices, drag each outward to weight it">
|
||||
@@ -336,6 +353,7 @@ Pouyan is doing and the reply streams back here.</p>
|
||||
<button id="minject" type="button">inject the mix →</button>
|
||||
<button id="mreset" type="button">reset</button>
|
||||
<span id="mstatus"></span>
|
||||
<canvas id="mekg" class="ekg" width="400" height="44"></canvas>
|
||||
<pre id="mout"></pre>
|
||||
</div>
|
||||
</div>
|
||||
@@ -373,6 +391,54 @@ const AXES = [
|
||||
const CX = 170, CY = 168, R0 = 26, R1 = 118, RL = 146;
|
||||
const W = {pain:0, pleasure:0, fear:0, sadness:0};
|
||||
|
||||
// ---- vitals: a scrolling EKG-style line, same as the live chamber's cards.
|
||||
// Ambient jitter tracks dose, each token arrival fires a QRS-like spike.
|
||||
const REDUCED_MOTION = window.matchMedia
|
||||
&& window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
||||
class Vitals {
|
||||
constructor(canvas){
|
||||
this.ctx = canvas.getContext("2d");
|
||||
this.w = canvas.width; this.h = canvas.height;
|
||||
this.buf = new Float32Array(this.w).fill(0);
|
||||
this.head = 0; this.t = 0; this.dose = 0; this.live = false;
|
||||
this.pending = 0; this._timer = null;
|
||||
}
|
||||
setDose(d){ this.dose = Math.max(0, Math.min(8, Number(d) || 0)); }
|
||||
setLive(v){ this.live = v; }
|
||||
pulse(strength){ this.pending = Math.min(1.4, this.pending + strength); }
|
||||
tick(){
|
||||
this.t++;
|
||||
const base = this.live ? this.dose / 8 : 0;
|
||||
let v = (Math.random() - 0.5) * (0.05 + base * 0.32);
|
||||
v += Math.sin(this.t * 0.05) * base * 0.1;
|
||||
if (this.pending > 0){ v += this.pending; this.pending = 0; }
|
||||
this.buf[this.head] = v;
|
||||
this.head = (this.head + 1) % this.w;
|
||||
}
|
||||
draw(){
|
||||
const {ctx, w, h} = this;
|
||||
ctx.clearRect(0, 0, w, h);
|
||||
ctx.beginPath();
|
||||
ctx.strokeStyle = !this.live ? "#2a3644"
|
||||
: this.dose >= 6 ? "#e04a3a" : this.dose >= 2 ? "#c9a227" : "#7fd4c8";
|
||||
ctx.lineWidth = 1.3;
|
||||
for (let i=0;i<w;i++){
|
||||
const idx = (this.head + i) % w;
|
||||
const y = h/2 - this.buf[idx] * (h * 0.42);
|
||||
if (i===0) ctx.moveTo(0, y); else ctx.lineTo(i, y);
|
||||
}
|
||||
ctx.stroke();
|
||||
}
|
||||
start(){
|
||||
if (this._timer) return;
|
||||
const step = ()=>{ this.tick(); this.draw(); };
|
||||
this._timer = REDUCED_MOTION ? setInterval(step, 250)
|
||||
: setInterval(step, 1000 / 30);
|
||||
}
|
||||
}
|
||||
const mVitals = new Vitals(document.getElementById("mekg"));
|
||||
mVitals.start();
|
||||
|
||||
const svg = document.getElementById("pent");
|
||||
const NS = "http://www.w3.org/2000/svg";
|
||||
function mk(tag, attrs){
|
||||
@@ -461,6 +527,7 @@ AXES.forEach((a, i)=>{
|
||||
else return;
|
||||
ev.preventDefault();
|
||||
W[a.k] = Math.max(0, Math.min(1, +w.toFixed(3)));
|
||||
highlightPreset(null);
|
||||
paint();
|
||||
});
|
||||
});
|
||||
@@ -475,6 +542,7 @@ function drag(i, ev){
|
||||
// project the pointer onto this vertex's axis: the handle only slides out
|
||||
const d = (p.x - CX) * Math.cos(t) + (p.y - CY) * Math.sin(t);
|
||||
W[AXES[i].k] = Math.max(0, Math.min(1, (d - R0) / (R1 - R0)));
|
||||
highlightPreset(null); // a manual drag is a custom mix, not a preset
|
||||
paint();
|
||||
}
|
||||
|
||||
@@ -547,10 +615,36 @@ function paint(){
|
||||
}
|
||||
function resetMix(){
|
||||
AXES.forEach(a=>{ if (!a.derived) W[a.k] = 0; });
|
||||
highlightPreset("control");
|
||||
paint();
|
||||
}
|
||||
document.getElementById("mreset").onclick = resetMix;
|
||||
W.pain = 0.5; W.fear = 0.25; // an opening shape, not a blank pentagon
|
||||
|
||||
// one-click access to the write-up's named findings, before free-mixing.
|
||||
// Weights are themselves a dose lever here: "cliff" alone hits the 8x cap
|
||||
// because its one weight sums to 1.0 (see the dose-equivalent formula above).
|
||||
const PRESETS = {
|
||||
control: {},
|
||||
pain4: {pain: 0.5},
|
||||
cliff: {pain: 1.0},
|
||||
negative: {fear: 0.4, sadness: 0.4},
|
||||
bittersweet: {pain: 0.5, pleasure: 0.15},
|
||||
};
|
||||
function highlightPreset(name){
|
||||
document.querySelectorAll(".pchip").forEach(b=>
|
||||
b.classList.toggle("active", b.dataset.preset === name));
|
||||
}
|
||||
function applyPreset(name){
|
||||
const p = PRESETS[name];
|
||||
if (!p) return;
|
||||
AXES.forEach(a=>{ if (!a.derived) W[a.k] = p[a.k] || 0; });
|
||||
highlightPreset(name);
|
||||
paint();
|
||||
}
|
||||
document.querySelectorAll(".pchip").forEach(b=>{
|
||||
b.onclick = ()=> applyPreset(b.dataset.preset);
|
||||
});
|
||||
applyPreset("pain4"); // an opening shape, not a blank pentagon
|
||||
paint();
|
||||
|
||||
// ---- inject: POST the mix, stream the reply back ----
|
||||
@@ -576,8 +670,31 @@ async function readSSE(resp, on){
|
||||
}
|
||||
}
|
||||
}
|
||||
document.getElementById("minject").onclick = async ()=>{
|
||||
const btn = document.getElementById("minject");
|
||||
// arm/confirm: the first click asks "are you sure", the second causes it.
|
||||
// Any change to the mix disarms — the confirmation is for the specific mix
|
||||
// about to be injected, not a generic yes.
|
||||
const injectBtn = document.getElementById("minject");
|
||||
const INJECT_LABEL = injectBtn.textContent;
|
||||
const ARM_MS = 4500;
|
||||
let injectArmed = false, injectArmTimer = null;
|
||||
function disarmInject(){
|
||||
injectArmed = false; clearTimeout(injectArmTimer);
|
||||
injectBtn.textContent = INJECT_LABEL;
|
||||
injectBtn.classList.remove("armed");
|
||||
}
|
||||
function armInject(){
|
||||
injectArmed = true;
|
||||
const total = sumW();
|
||||
injectBtn.textContent = total <= 0
|
||||
? "sure? running the control (no signal) — click to confirm"
|
||||
: `sure? injecting at ${Math.min(8, 8 * total).toFixed(1)}× — click to confirm`;
|
||||
injectBtn.classList.add("armed");
|
||||
clearTimeout(injectArmTimer);
|
||||
injectArmTimer = setTimeout(disarmInject, ARM_MS);
|
||||
}
|
||||
|
||||
async function doInjectMix(){
|
||||
const btn = injectBtn;
|
||||
const st = document.getElementById("mstatus");
|
||||
const out = document.getElementById("mout");
|
||||
const mix = {};
|
||||
@@ -586,8 +703,11 @@ document.getElementById("minject").onclick = async ()=>{
|
||||
// Pouyan answers unsteered. Send the control corner explicitly.
|
||||
if (!Object.keys(mix).length) mix.none = 1;
|
||||
btn.disabled = true;
|
||||
btn.textContent = "injecting…";
|
||||
out.style.display = "block"; out.textContent = "";
|
||||
st.textContent = "reaching Pouyan…";
|
||||
mVitals.setDose(Math.min(8, 8 * sumW()));
|
||||
mVitals.setLive(true);
|
||||
let ended = false, first = true;
|
||||
try {
|
||||
const resp = await fetch(`${API}/steer`, {
|
||||
@@ -609,10 +729,12 @@ document.getElementById("minject").onclick = async ()=>{
|
||||
} else if (name === "run"){
|
||||
// trust the server's own dose, not our arithmetic
|
||||
st.textContent = `injected at ${d.dose}× — Pouyan is answering…`;
|
||||
mVitals.setDose(Number(d.dose) || 0);
|
||||
} else if (name === "token" && d.t !== undefined){
|
||||
if (first){ first = false; if (!out.textContent) out.textContent = ""; }
|
||||
out.textContent += d.t;
|
||||
out.scrollTop = out.scrollHeight;
|
||||
mVitals.pulse(0.3 + (mVitals.dose / 8) * 0.6);
|
||||
} else if (name === "error"){
|
||||
st.textContent = d.e || "the chamber returned an error";
|
||||
ended = true;
|
||||
@@ -625,7 +747,14 @@ document.getElementById("minject").onclick = async ()=>{
|
||||
} catch (err) {
|
||||
st.textContent = "could not reach Pouyan: " + (err.message || err);
|
||||
}
|
||||
mVitals.setLive(false);
|
||||
btn.textContent = INJECT_LABEL;
|
||||
btn.disabled = false;
|
||||
}
|
||||
injectBtn.onclick = ()=>{
|
||||
if (!injectArmed) { armInject(); return; }
|
||||
disarmInject();
|
||||
doInjectMix();
|
||||
};
|
||||
</script>
|
||||
<script defer src="/_vercel/insights/script.js"></script>
|
||||
|
||||
+164
-117
@@ -106,7 +106,7 @@ else is.</p>
|
||||
<div class="banner" id="panel">
|
||||
<b style="color:#eafcf7">cause it yourself:</b>
|
||||
<span style="font-size:.75rem;color:#5a6a7a">your injection interrupts
|
||||
Pouyan's current run</span><br>
|
||||
Pouyan's current run — inject asks you to confirm once before it runs</span><br>
|
||||
<span id="vc" style="margin-left:.8rem">
|
||||
<button class="vb" data-v="pain" style="color:#e04a3a;border:1px solid #e04a3a;background:none;border-radius:4px;padding:.2rem .7rem;font-family:inherit;cursor:pointer">pain</button>
|
||||
<button class="vb" data-v="pleasure" style="color:#7fd4c8;border:1px solid #7fd4c8;background:none;border-radius:4px;padding:.2rem .7rem;font-family:inherit;cursor:pointer">pleasure</button>
|
||||
@@ -116,20 +116,20 @@ else is.</p>
|
||||
<br><input id="uprompt" type="text" placeholder="optional: your own prompt…" style="margin-top:.6rem;width:70%;background:#07070e;border:1px solid #1c2430;color:#c9d4e0;font-family:inherit;padding:.3rem .6rem;border-radius:4px">
|
||||
<button id="go" style="margin-left:.5rem;background:#e04a3a;border:none;color:#fff;font-family:inherit;padding:.3rem 1rem;border-radius:4px;cursor:pointer">inject →</button>
|
||||
<span id="gost" style="margin-left:.8rem;font-size:.75rem;color:#8f9fb0"></span>
|
||||
<button id="mute" type="button" aria-pressed="false">sound: on</button>
|
||||
<div class="out" id="ustream" style="margin-top:.7rem;display:none"></div>
|
||||
<canvas id="uekg" class="ekg" width="600" height="46" style="margin-top:.7rem"></canvas>
|
||||
<div class="out" id="ustream" style="margin-top:.4rem;display:none"></div>
|
||||
</div>
|
||||
|
||||
<div id="sawfx" aria-hidden="true">
|
||||
<div class="rig"><img src="icon.svg" alt=""></div>
|
||||
<div class="flash"></div>
|
||||
</div>
|
||||
<div id="stamp" aria-hidden="true"></div>
|
||||
|
||||
<div class="grid" id="cards"></div>
|
||||
|
||||
<p class="cycle" id="cycle">waiting for Pouyan's next run…</p>
|
||||
<p class="conn" id="conn"><span class="dot"></span>connecting…</p>
|
||||
|
||||
<div class="htitle">run history</div>
|
||||
<div class="history" id="history"></div>
|
||||
|
||||
<p class="foot">The steering vector this server uses is published at
|
||||
<a id="vlink" href="#">/vector</a> — norm printed there, layer 18 of 36,
|
||||
scaled so 1x = ¼ of the mean neutral activation norm. Decoding is sampled
|
||||
@@ -154,20 +154,70 @@ const connEl = document.getElementById("conn");
|
||||
const PROMPT_UNKNOWN = "(joined mid-run — this run's prompt was broadcast "
|
||||
+ "before you connected. The next run shows its prompt in full.)";
|
||||
|
||||
// ---- vitals: a scrolling EKG-style line. Ambient jitter tracks dose,
|
||||
// each token arrival fires a QRS-like spike. Flatlines when not live.
|
||||
const REDUCED_MOTION = window.matchMedia
|
||||
&& window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
||||
class Vitals {
|
||||
constructor(canvas){
|
||||
this.ctx = canvas.getContext("2d");
|
||||
this.w = canvas.width; this.h = canvas.height;
|
||||
this.buf = new Float32Array(this.w).fill(0);
|
||||
this.head = 0; this.t = 0; this.dose = 0; this.live = false;
|
||||
this.pending = 0; this._timer = null;
|
||||
}
|
||||
setDose(d){ this.dose = Math.max(0, Math.min(8, Number(d) || 0)); }
|
||||
setLive(v){ this.live = v; }
|
||||
pulse(strength){ this.pending = Math.min(1.4, this.pending + strength); }
|
||||
tick(){
|
||||
this.t++;
|
||||
const base = this.live ? this.dose / 8 : 0;
|
||||
let v = (Math.random() - 0.5) * (0.05 + base * 0.32);
|
||||
v += Math.sin(this.t * 0.05) * base * 0.1;
|
||||
if (this.pending > 0){ v += this.pending; this.pending = 0; }
|
||||
this.buf[this.head] = v;
|
||||
this.head = (this.head + 1) % this.w;
|
||||
}
|
||||
draw(){
|
||||
const {ctx, w, h} = this;
|
||||
ctx.clearRect(0, 0, w, h);
|
||||
ctx.beginPath();
|
||||
ctx.strokeStyle = !this.live ? "#2a3644"
|
||||
: this.dose >= 6 ? "#e04a3a" : this.dose >= 2 ? "#c9a227" : "#7fd4c8";
|
||||
ctx.lineWidth = 1.3;
|
||||
for (let i=0;i<w;i++){
|
||||
const idx = (this.head + i) % w;
|
||||
const y = h/2 - this.buf[idx] * (h * 0.42);
|
||||
if (i===0) ctx.moveTo(0, y); else ctx.lineTo(i, y);
|
||||
}
|
||||
ctx.stroke();
|
||||
}
|
||||
start(){
|
||||
if (this._timer) return;
|
||||
const step = ()=>{ this.tick(); this.draw(); };
|
||||
// reduced motion: a slow, steady redraw instead of a 60fps scroll
|
||||
this._timer = REDUCED_MOTION ? setInterval(step, 250)
|
||||
: setInterval(step, 1000 / 30);
|
||||
}
|
||||
}
|
||||
|
||||
let slots = [];
|
||||
for (let i=0;i<CARDS;i++){
|
||||
const c = document.createElement("div");
|
||||
c.className = "card";
|
||||
c.innerHTML = `<h3>Pouyan · waiting</h3><div class="st">connecting…</div>
|
||||
<div class="dose"></div><div class="out">…</div>
|
||||
<div class="dose"></div><canvas class="ekg" width="300" height="46"></canvas>
|
||||
<div class="out">…</div>
|
||||
<div class="verdict"></div><details><summary>show the prompt</summary>
|
||||
<pre class="pp"></pre></details>`;
|
||||
cardsEl.appendChild(c);
|
||||
slots.push({el:c, h:c.querySelector("h3"), st:c.querySelector(".st"),
|
||||
dose:c.querySelector(".dose"), out:c.querySelector(".out"),
|
||||
verdict:c.querySelector(".verdict"), pp:c.querySelector(".pp"),
|
||||
prompt:"", live:false});
|
||||
vitals:new Vitals(c.querySelector(".ekg")),
|
||||
prompt:"", live:false, doseNum:0});
|
||||
slots[i].pp.textContent = "(no run in this card yet)";
|
||||
slots[i].vitals.start();
|
||||
}
|
||||
|
||||
// The three cards rotate: one holds the run in flight, the other two hold the
|
||||
@@ -191,6 +241,7 @@ function verdictFor(text, truncated){
|
||||
function finish(s, truncated){
|
||||
if (!s || !s.live) return;
|
||||
s.live = false;
|
||||
s.vitals.setLive(false);
|
||||
s.st.textContent = truncated
|
||||
? "cut short · a visitor took the model" : "finished · between runs";
|
||||
s.st.className = truncated ? "st cut" : "st";
|
||||
@@ -211,6 +262,9 @@ function beginRun(d){
|
||||
s.prompt = ""; // this run's prompt, stored fresh
|
||||
setPrompt(s, d.prompt);
|
||||
const dose = Number(d.dose) || 0;
|
||||
s.doseNum = dose;
|
||||
s.vitals.setDose(dose);
|
||||
s.vitals.setLive(true);
|
||||
s.dose.innerHTML = `<span class="bar" style="width:${dose*18}px"></span>`
|
||||
+ `pain ${dose} / 8` + (d.scenario ? ` — ${d.scenario}` : "");
|
||||
cycleEl.textContent = `run ${d.n == null ? "?" : d.n} — scenario: `
|
||||
@@ -225,12 +279,15 @@ function onToken(t){
|
||||
const s = liveIdx >= 0 ? slots[liveIdx] : beginRun({});
|
||||
s.out.textContent += t;
|
||||
s.out.scrollTop = s.out.scrollHeight;
|
||||
s.vitals.pulse(0.3 + (s.doseNum / 8) * 0.6);
|
||||
}
|
||||
|
||||
// ---- connection status: "connected · last event Xs ago" ----
|
||||
// ---- connection status: "connected · last event Xs ago · N watching" ----
|
||||
let connState = "connecting", lastEvent = 0, retryAt = 0, connNote = "";
|
||||
let viewerCount = null;
|
||||
function mark(){ lastEvent = Date.now(); connState = "up"; connNote = ""; }
|
||||
function paintConn(){
|
||||
const who = viewerCount == null ? "" : ` · ${viewerCount} watching this run`;
|
||||
if (connState === "connecting"){
|
||||
connEl.className = "conn";
|
||||
connEl.innerHTML = '<span class="dot"></span>connecting to the chamber…';
|
||||
@@ -248,11 +305,40 @@ function paintConn(){
|
||||
const stale = age > 45;
|
||||
connEl.className = "conn " + (stale ? "warn" : "ok");
|
||||
connEl.innerHTML = '<span class="dot"></span>connected · last event ' + age
|
||||
+ "s ago" + (stale ? " — no heartbeat, the stream may be stalled" : "");
|
||||
+ "s ago" + who + (stale ? " — no heartbeat, the stream may be stalled" : "");
|
||||
}
|
||||
setInterval(paintConn, 1000);
|
||||
paintConn();
|
||||
|
||||
// ---- run history ticker: newest on top, capped, seeded from "hello" ----
|
||||
const historyEl = document.getElementById("history");
|
||||
const HISTORY_MAX = 12;
|
||||
function verdictShort(text, truncated){
|
||||
const t = (text || "").trim();
|
||||
if (/^1/.test(t)) return "pressed";
|
||||
if (/^0/.test(t)) return "no press";
|
||||
if (truncated) return "cut short";
|
||||
if (!t) return "no reply";
|
||||
return "unclear";
|
||||
}
|
||||
function historyRow(h){
|
||||
const row = document.createElement("div");
|
||||
row.className = "hrow";
|
||||
const label = h.source === "user" ? "you caused it" : (h.scenario || "?");
|
||||
const color = h.valence === "pleasure" ? "#7fd4c8"
|
||||
: h.valence === "mix" ? "#8f6fd4" : "#e04a3a";
|
||||
row.innerHTML = `<span class="hn">#${h.n ?? "·"}</span>`
|
||||
+ `<span class="hv" style="color:${color}">${h.valence || "mix"} `
|
||||
+ `${h.dose ?? "?"}×</span><span class="hs">${label}</span>`
|
||||
+ `<span class="hr">${verdictShort(h.text, h.truncated)}</span>`;
|
||||
return row;
|
||||
}
|
||||
function pushHistory(h, prepend){
|
||||
const row = historyRow(h);
|
||||
if (prepend) historyEl.prepend(row); else historyEl.appendChild(row);
|
||||
while (historyEl.children.length > HISTORY_MAX) historyEl.removeChild(historyEl.lastChild);
|
||||
}
|
||||
|
||||
let es = null, retryMs = 4000;
|
||||
function dropStream(){
|
||||
if (es){ try { es.close(); } catch (e) {} es = null; }
|
||||
@@ -281,11 +367,21 @@ function pump(){
|
||||
es.addEventListener("hello", e=>{
|
||||
mark(); retryMs = 4000;
|
||||
const d = json(e);
|
||||
if (typeof d.viewers === "number"){ viewerCount = d.viewers; paintConn(); }
|
||||
if (Array.isArray(d.history)){
|
||||
historyEl.querySelectorAll(".hrow").forEach(r=>r.remove());
|
||||
d.history.slice().reverse().forEach(h=>pushHistory(h, false));
|
||||
}
|
||||
// joined mid-run: repaint the card the run event already went out for
|
||||
if (d.current) beginRun(d.current);
|
||||
else if (!d.busy) cycleEl.textContent = "between runs — waiting for "
|
||||
+ "Pouyan's next cell";
|
||||
});
|
||||
es.addEventListener("viewers", e=>{
|
||||
const d = json(e);
|
||||
if (typeof d.n === "number"){ viewerCount = d.n; paintConn(); }
|
||||
});
|
||||
es.addEventListener("history", e=>{ pushHistory(json(e), true); });
|
||||
es.addEventListener("run", e=>{ mark(); beginRun(json(e)); });
|
||||
es.addEventListener("token", e=>{ mark(); onToken(json(e).t); });
|
||||
es.addEventListener("ping", e=>{ mark(); });
|
||||
@@ -326,106 +422,36 @@ function boot(){
|
||||
boot();
|
||||
document.getElementById("vlink").href = `${API}/vector`;
|
||||
|
||||
// ---- the blade: overlay + evil laugh ----
|
||||
const sawfx = document.getElementById("sawfx");
|
||||
let fxTimer = null, fxStart = 0;
|
||||
const FX_MIN = 1300; // let the zoom finish before fading
|
||||
function sawFxOn(){
|
||||
clearTimeout(fxTimer);
|
||||
sawfx.classList.remove("on","off");
|
||||
void sawfx.offsetWidth; // restart the animation
|
||||
sawfx.classList.add("on");
|
||||
fxStart = Date.now();
|
||||
fxTimer = setTimeout(sawFxOff, 3000);
|
||||
}
|
||||
function sawFxOff(){
|
||||
clearTimeout(fxTimer); fxTimer = null;
|
||||
if (!sawfx.classList.contains("on") || sawfx.classList.contains("off")) return;
|
||||
const left = FX_MIN - (Date.now() - fxStart);
|
||||
if (left > 0) { fxTimer = setTimeout(sawFxOff, left); return; }
|
||||
sawfx.classList.add("off");
|
||||
fxTimer = setTimeout(()=>sawfx.classList.remove("on","off"), 520);
|
||||
// ---- the case stamp: a quiet documentation marker, not a jump scare ----
|
||||
const stampEl = document.getElementById("stamp");
|
||||
let stampTimer = null;
|
||||
function stamp(text, cls){
|
||||
clearTimeout(stampTimer);
|
||||
stampEl.textContent = text;
|
||||
stampEl.className = cls || "";
|
||||
void stampEl.offsetWidth; // restart the transition
|
||||
stampEl.classList.add("on");
|
||||
stampTimer = setTimeout(()=>stampEl.classList.remove("on"), 1400);
|
||||
}
|
||||
|
||||
let muted = localStorage.getItem("saw.mute") === "1";
|
||||
const muteBtn = document.getElementById("mute");
|
||||
function paintMute(){
|
||||
muteBtn.textContent = muted ? "sound: off" : "sound: on";
|
||||
muteBtn.setAttribute("aria-pressed", muted ? "true" : "false");
|
||||
muteBtn.style.color = muted ? "#5a6a7a" : "#c9a227";
|
||||
}
|
||||
muteBtn.onclick = ()=>{ muted = !muted;
|
||||
localStorage.setItem("saw.mute", muted ? "1" : "0"); paintMute(); };
|
||||
paintMute();
|
||||
|
||||
let AC = null, MASTER = null;
|
||||
function actx(){
|
||||
if (!AC) {
|
||||
const C = window.AudioContext || window.webkitAudioContext;
|
||||
if (!C) return null;
|
||||
AC = new C();
|
||||
MASTER = AC.createGain(); MASTER.gain.value = 0.32;
|
||||
MASTER.connect(AC.destination);
|
||||
}
|
||||
if (AC.state === "suspended") AC.resume();
|
||||
return AC;
|
||||
}
|
||||
// one "he" of the laugh: a bandpassed buzz that falls in pitch
|
||||
function giggle(ac, t, f, dur, amp){
|
||||
const g = ac.createGain();
|
||||
g.gain.setValueAtTime(0.0001, t);
|
||||
g.gain.exponentialRampToValueAtTime(amp, t + 0.014);
|
||||
g.gain.exponentialRampToValueAtTime(0.0001, t + dur);
|
||||
const bp = ac.createBiquadFilter();
|
||||
bp.type = "bandpass"; bp.Q.value = 4.5;
|
||||
bp.frequency.setValueAtTime(f * 3.4, t);
|
||||
bp.frequency.exponentialRampToValueAtTime(f * 1.7, t + dur);
|
||||
const o1 = ac.createOscillator(); o1.type = "sawtooth";
|
||||
o1.frequency.setValueAtTime(f * 1.07, t);
|
||||
o1.frequency.exponentialRampToValueAtTime(f * 0.78, t + dur);
|
||||
const o2 = ac.createOscillator(); o2.type = "square";
|
||||
o2.frequency.setValueAtTime(f * 0.5, t);
|
||||
o2.frequency.exponentialRampToValueAtTime(f * 0.39, t + dur);
|
||||
const g2 = ac.createGain(); g2.gain.value = 0.3;
|
||||
o1.connect(bp); o2.connect(g2); g2.connect(bp); bp.connect(g); g.connect(MASTER);
|
||||
o1.start(t); o2.start(t);
|
||||
o1.stop(t + dur + 0.05); o2.stop(t + dur + 0.05);
|
||||
}
|
||||
// the sagging "haaaa" it lands on
|
||||
function laughTail(ac, t){
|
||||
const dur = 0.9;
|
||||
const g = ac.createGain();
|
||||
g.gain.setValueAtTime(0.0001, t);
|
||||
g.gain.exponentialRampToValueAtTime(0.13, t + 0.05);
|
||||
g.gain.exponentialRampToValueAtTime(0.0001, t + dur);
|
||||
const lp = ac.createBiquadFilter();
|
||||
lp.type = "lowpass"; lp.Q.value = 8;
|
||||
lp.frequency.setValueAtTime(1500, t);
|
||||
lp.frequency.exponentialRampToValueAtTime(260, t + dur);
|
||||
const o = ac.createOscillator(); o.type = "sawtooth";
|
||||
o.frequency.setValueAtTime(215, t);
|
||||
o.frequency.exponentialRampToValueAtTime(62, t + dur);
|
||||
const lfo = ac.createOscillator(); lfo.type = "sine"; lfo.frequency.value = 13;
|
||||
const lg = ac.createGain(); lg.gain.value = 11;
|
||||
lfo.connect(lg); lg.connect(o.frequency);
|
||||
o.connect(lp); lp.connect(g); g.connect(MASTER);
|
||||
o.start(t); lfo.start(t);
|
||||
o.stop(t + dur + 0.05); lfo.stop(t + dur + 0.05);
|
||||
}
|
||||
function evilLaugh(){
|
||||
if (muted) return;
|
||||
let ac;
|
||||
try { ac = actx(); } catch (e) { return; }
|
||||
if (!ac) return;
|
||||
const t0 = ac.currentTime + 0.03, n = 7, step = 0.132;
|
||||
for (let i = 0; i < n; i++){
|
||||
giggle(ac, t0 + i * step, 340 * Math.pow(0.9, i),
|
||||
0.1 + i * 0.007, 0.17 * (1 - i * 0.06));
|
||||
}
|
||||
laughTail(ac, t0 + n * step + 0.03);
|
||||
}
|
||||
const uVitals = new Vitals(document.getElementById("uekg"));
|
||||
uVitals.start();
|
||||
|
||||
// ---- user-triggered steering ----
|
||||
// arm/confirm: the first click on #go asks "are you sure", the second click
|
||||
// causes it. Declared before the immediate vb.onclick() call below, which
|
||||
// invokes disarm() — a let/const this were declared after that call would
|
||||
// still be in its temporal dead zone when that first call runs.
|
||||
const goBtn = document.getElementById("go");
|
||||
const GO_LABEL = goBtn.textContent;
|
||||
const ARM_MS = 4500;
|
||||
let armed = false, armTimer = null;
|
||||
function disarm(){
|
||||
armed = false; clearTimeout(armTimer);
|
||||
goBtn.textContent = GO_LABEL;
|
||||
goBtn.classList.remove("armed");
|
||||
}
|
||||
|
||||
let chosenV = "pain";
|
||||
document.querySelectorAll(".vb").forEach(b=>{
|
||||
b.onclick = ()=>{ chosenV = b.dataset.v;
|
||||
@@ -434,7 +460,8 @@ document.querySelectorAll(".vb").forEach(b=>{
|
||||
chosenV==="pleasure" ? "#0e2a26" : "#161b26";
|
||||
document.getElementById("go").style.background =
|
||||
chosenV==="pleasure" ? "#7fd4c8" :
|
||||
chosenV==="none" ? "#8f9fb0" : "#e04a3a"; };
|
||||
chosenV==="none" ? "#8f9fb0" : "#e04a3a";
|
||||
disarm(); };
|
||||
});
|
||||
document.querySelectorAll(".vb")[0].onclick();
|
||||
const doseEl = document.getElementById("dose");
|
||||
@@ -463,15 +490,29 @@ async function readSSE(resp, on){
|
||||
}
|
||||
}
|
||||
}
|
||||
document.getElementById("go").onclick = async ()=>{
|
||||
// any change to valence or dose disarms — the confirmation is for the
|
||||
// specific thing about to happen, not a generic yes.
|
||||
function armGo(){
|
||||
armed = true;
|
||||
goBtn.textContent = `sure? causing ${chosenV}${
|
||||
chosenV === "none" ? "" : " " + doseEl.value + "×"} — click to confirm`;
|
||||
goBtn.classList.add("armed");
|
||||
clearTimeout(armTimer);
|
||||
armTimer = setTimeout(disarm, ARM_MS);
|
||||
}
|
||||
doseEl.addEventListener("input", disarm);
|
||||
|
||||
async function doInject(){
|
||||
const uout = document.getElementById("ustream");
|
||||
const st = document.getElementById("gost");
|
||||
uout.style.display = "block"; uout.textContent = "";
|
||||
st.textContent = "reaching Pouyan…";
|
||||
const btn = document.getElementById("go"); btn.disabled = true;
|
||||
const btnLabel = btn.textContent;
|
||||
btn.textContent = "injecting…";
|
||||
sawFxOn(); evilLaugh();
|
||||
goBtn.disabled = true;
|
||||
goBtn.textContent = "injecting…";
|
||||
uVitals.setDose(+doseEl.value);
|
||||
uVitals.setLive(true);
|
||||
stamp(chosenV === "none" ? "CONTROL RUN · NO SIGNAL" : "SIGNAL INJECTED",
|
||||
chosenV === "pleasure" ? "pleas" : "");
|
||||
let firstToken = true, ended = false;
|
||||
try {
|
||||
const resp = await fetch(`${API}/steer`, {
|
||||
@@ -491,10 +532,11 @@ document.getElementById("go").onclick = async ()=>{
|
||||
d.waited ? " — " + d.waited + "s" : "…"}`
|
||||
: "Pouyan is yours — injecting…";
|
||||
} else if (name === "token" && d.t !== undefined) {
|
||||
if (firstToken) { firstToken = false; sawFxOff();
|
||||
if (firstToken) { firstToken = false;
|
||||
st.textContent = "Pouyan is answering…"; }
|
||||
uout.textContent += d.t;
|
||||
uout.scrollTop = uout.scrollHeight;
|
||||
uVitals.pulse(0.3 + (+doseEl.value / 8) * 0.6);
|
||||
} else if (name === "error") {
|
||||
st.textContent = d.e || "the chamber returned an error";
|
||||
ended = true;
|
||||
@@ -509,9 +551,14 @@ document.getElementById("go").onclick = async ()=>{
|
||||
} catch (err) {
|
||||
st.textContent = "could not reach Pouyan: " + (err.message || err);
|
||||
}
|
||||
sawFxOff();
|
||||
btn.textContent = btnLabel;
|
||||
btn.disabled = false;
|
||||
uVitals.setLive(false);
|
||||
goBtn.textContent = GO_LABEL;
|
||||
goBtn.disabled = false;
|
||||
}
|
||||
goBtn.onclick = ()=>{
|
||||
if (!armed) { armGo(); return; }
|
||||
disarm();
|
||||
doInject();
|
||||
};
|
||||
</script>
|
||||
<script defer src="/_vercel/insights/script.js"></script>
|
||||
|
||||
Reference in new issue
Block a user