Update index.html
Browse files- index.html +9 -5
index.html
CHANGED
|
@@ -30,15 +30,18 @@
|
|
| 30 |
const cmd = document.getElementById("cmd");
|
| 31 |
const btn = document.getElementById("primary");
|
| 32 |
|
| 33 |
-
let SID = "";
|
|
|
|
| 34 |
|
| 35 |
function scrollBottom(){ log.scrollTop = log.scrollHeight; }
|
|
|
|
| 36 |
function render(s){
|
| 37 |
if (s.sid) SID = s.sid;
|
|
|
|
| 38 |
log.textContent = s.transcript || "";
|
| 39 |
btn.textContent = s.primary_label || "Start";
|
| 40 |
cmd.placeholder = s.placeholder || "";
|
| 41 |
-
btn.style.display = (
|
| 42 |
cmd.focus();
|
| 43 |
scrollBottom();
|
| 44 |
}
|
|
@@ -70,17 +73,18 @@
|
|
| 70 |
}
|
| 71 |
|
| 72 |
async function init(){
|
|
|
|
| 73 |
render(await fetchState());
|
| 74 |
|
| 75 |
btn.addEventListener("click", async () => { await callPrimary(); });
|
| 76 |
|
|
|
|
| 77 |
cmd.addEventListener("keydown", async (e) => {
|
| 78 |
if (e.key !== "Enter") return;
|
| 79 |
e.preventDefault();
|
| 80 |
-
|
| 81 |
-
if (s.mode === "awaiting_action"){
|
| 82 |
await callAction(cmd.value.trim());
|
| 83 |
-
} else if (
|
| 84 |
await callPrimary();
|
| 85 |
}
|
| 86 |
});
|
|
|
|
| 30 |
const cmd = document.getElementById("cmd");
|
| 31 |
const btn = document.getElementById("primary");
|
| 32 |
|
| 33 |
+
let SID = "";
|
| 34 |
+
let MODE = "awaiting_start"; // authoritative client state
|
| 35 |
|
| 36 |
function scrollBottom(){ log.scrollTop = log.scrollHeight; }
|
| 37 |
+
|
| 38 |
function render(s){
|
| 39 |
if (s.sid) SID = s.sid;
|
| 40 |
+
if (s.mode) MODE = s.mode;
|
| 41 |
log.textContent = s.transcript || "";
|
| 42 |
btn.textContent = s.primary_label || "Start";
|
| 43 |
cmd.placeholder = s.placeholder || "";
|
| 44 |
+
btn.style.display = (MODE === "awaiting_action") ? "none" : "inline-block";
|
| 45 |
cmd.focus();
|
| 46 |
scrollBottom();
|
| 47 |
}
|
|
|
|
| 73 |
}
|
| 74 |
|
| 75 |
async function init(){
|
| 76 |
+
// Single initial state fetch. After that, trust MODE from the last successful response.
|
| 77 |
render(await fetchState());
|
| 78 |
|
| 79 |
btn.addEventListener("click", async () => { await callPrimary(); });
|
| 80 |
|
| 81 |
+
// Enter uses local MODE. No pre-Enter GET /state (prevents the /primary loop).
|
| 82 |
cmd.addEventListener("keydown", async (e) => {
|
| 83 |
if (e.key !== "Enter") return;
|
| 84 |
e.preventDefault();
|
| 85 |
+
if (MODE === "awaiting_action"){
|
|
|
|
| 86 |
await callAction(cmd.value.trim());
|
| 87 |
+
} else if (MODE === "awaiting_continue" || MODE === "awaiting_start"){
|
| 88 |
await callPrimary();
|
| 89 |
}
|
| 90 |
});
|