deucebucket Claude Sonnet 4.6 commited on
Commit
1de83ff
·
1 Parent(s): dcb589c

fix: guard mood readout length + handle /say fetch errors

Browse files

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. static/app.js +11 -7
static/app.js CHANGED
@@ -22,7 +22,7 @@ function render(state) {
22
  const dy = (ap.droop || 0) * 14;
23
  $("#blob").style.transform = `translateX(-50%) translateY(${dy}px) scale(${ap.scale}) rotate(${lean}deg)`;
24
  $("#moodword").textContent = state.mood_word;
25
- if (ap.mood) {
26
  $("#moodReadout").textContent = DIMS.map((d, i) => `${d} ${String(ap.mood[i]).padStart(3)}`).join("\n");
27
  }
28
  }
@@ -45,12 +45,16 @@ function speak(text, voice) {
45
  async function say() {
46
  const inp = $("#msg"); const text = inp.value.trim(); if (!text) return;
47
  inp.value = "";
48
- const r = await fetch("/say", {method:"POST", headers:{"Content-Type":"application/json"}, body: JSON.stringify({text})});
49
- if (!r.ok) return;
50
- const state = await r.json();
51
- render(state);
52
- bubble(state.emoticon); // the "words" are an emoticon
53
- speak(state.simlish, state.voice); // the sound is simlish babble, client-side
 
 
 
 
54
  }
55
 
56
  $("#send").onclick = say;
 
22
  const dy = (ap.droop || 0) * 14;
23
  $("#blob").style.transform = `translateX(-50%) translateY(${dy}px) scale(${ap.scale}) rotate(${lean}deg)`;
24
  $("#moodword").textContent = state.mood_word;
25
+ if (ap.mood && ap.mood.length === DIMS.length) {
26
  $("#moodReadout").textContent = DIMS.map((d, i) => `${d} ${String(ap.mood[i]).padStart(3)}`).join("\n");
27
  }
28
  }
 
45
  async function say() {
46
  const inp = $("#msg"); const text = inp.value.trim(); if (!text) return;
47
  inp.value = "";
48
+ try {
49
+ const r = await fetch("/say", {method:"POST", headers:{"Content-Type":"application/json"}, body: JSON.stringify({text})});
50
+ if (!r.ok) { bubble("…?"); return; }
51
+ const state = await r.json();
52
+ render(state);
53
+ bubble(state.emoticon); // the "words" are an emoticon
54
+ speak(state.simlish, state.voice); // the sound is simlish babble, client-side
55
+ } catch (e) {
56
+ bubble("…?");
57
+ }
58
  }
59
 
60
  $("#send").onclick = say;