Initial commit.
Basic docker deployment with Local LLM integration and simple game state.
This commit is contained in:
115
web/static/app.js
Normal file
115
web/static/app.js
Normal file
@@ -0,0 +1,115 @@
|
||||
(() => {
|
||||
const el = {
|
||||
statusDot: document.getElementById("statusDot"),
|
||||
messages: document.getElementById("messages"),
|
||||
form: document.getElementById("chatForm"),
|
||||
input: document.getElementById("messageInput"),
|
||||
sendBtn: document.getElementById("sendBtn"),
|
||||
tplUser: document.getElementById("msg-user"),
|
||||
tplAssistant: document.getElementById("msg-assistant"),
|
||||
};
|
||||
|
||||
const state = {
|
||||
sending: false,
|
||||
};
|
||||
|
||||
function setStatus(ok) {
|
||||
el.statusDot.classList.toggle("ok", !!ok);
|
||||
el.statusDot.classList.toggle("err", !ok);
|
||||
}
|
||||
|
||||
async function healthCheck() {
|
||||
try {
|
||||
const res = await fetch("/api/health", { cache: "no-store" });
|
||||
setStatus(res.ok);
|
||||
} catch {
|
||||
setStatus(false);
|
||||
}
|
||||
}
|
||||
|
||||
function appendMessage(role, text) {
|
||||
const tpl = role === "user" ? el.tplUser : el.tplAssistant;
|
||||
const node = tpl.content.cloneNode(true);
|
||||
const bubble = node.querySelector(".bubble");
|
||||
bubble.textContent = text;
|
||||
el.messages.appendChild(node);
|
||||
el.messages.scrollTop = el.messages.scrollHeight;
|
||||
}
|
||||
|
||||
function setSending(sending) {
|
||||
state.sending = sending;
|
||||
el.input.disabled = sending;
|
||||
el.sendBtn.disabled = sending;
|
||||
el.sendBtn.textContent = sending ? "Sending..." : "Send";
|
||||
}
|
||||
|
||||
async function sendMessage(text) {
|
||||
setSending(true);
|
||||
try {
|
||||
const res = await fetch("/api/chat", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
credentials: "same-origin",
|
||||
body: JSON.stringify({ message: text }),
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
let detail = "";
|
||||
try {
|
||||
const data = await res.json();
|
||||
detail = data.detail || res.statusText;
|
||||
} catch {
|
||||
detail = res.statusText;
|
||||
}
|
||||
throw new Error(detail || `HTTP ${res.status}`);
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
appendMessage("assistant", data.reply ?? "");
|
||||
setStatus(true);
|
||||
} catch (err) {
|
||||
appendMessage("assistant", `Error: ${err.message || err}`);
|
||||
setStatus(false);
|
||||
} finally {
|
||||
setSending(false);
|
||||
}
|
||||
}
|
||||
|
||||
el.form.addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
const text = (el.input.value || "").trim();
|
||||
if (!text || state.sending) return;
|
||||
appendMessage("user", text);
|
||||
el.input.value = "";
|
||||
await sendMessage(text);
|
||||
});
|
||||
|
||||
// Submit on Enter, allow Shift+Enter for newline (if we switch to textarea later)
|
||||
el.input.addEventListener("keydown", (e) => {
|
||||
if (e.key === "Enter" && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
el.form.requestSubmit();
|
||||
}
|
||||
});
|
||||
|
||||
// Initial status check
|
||||
healthCheck();
|
||||
|
||||
// Initialize session and show start message if configured
|
||||
(async function initSession() {
|
||||
try {
|
||||
const res = await fetch("/api/session", { credentials: "same-origin" });
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
if (data.start_message) {
|
||||
appendMessage("assistant", data.start_message);
|
||||
}
|
||||
}
|
||||
} catch (_) {
|
||||
// no-op
|
||||
}
|
||||
})();
|
||||
|
||||
// Periodic health check
|
||||
setInterval(healthCheck, 15000);
|
||||
})();
|
||||
46
web/static/index.html
Normal file
46
web/static/index.html
Normal file
@@ -0,0 +1,46 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Text Adventure - Web UI</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="stylesheet" href="/static/styles.css" />
|
||||
</head>
|
||||
<body>
|
||||
<header class="app-header">
|
||||
<h1>Text Adventure</h1>
|
||||
<div class="status" id="statusDot" title="Backend status"></div>
|
||||
</header>
|
||||
|
||||
<main class="container">
|
||||
<section id="chat" class="chat">
|
||||
<div id="messages" class="messages" aria-live="polite"></div>
|
||||
</section>
|
||||
|
||||
<form id="chatForm" class="input-row" autocomplete="off">
|
||||
<input
|
||||
id="messageInput"
|
||||
type="text"
|
||||
placeholder="Type your message..."
|
||||
aria-label="Message"
|
||||
required
|
||||
/>
|
||||
<button id="sendBtn" type="submit">Send</button>
|
||||
</form>
|
||||
</main>
|
||||
|
||||
<template id="msg-user">
|
||||
<div class="msg msg-user">
|
||||
<div class="bubble"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template id="msg-assistant">
|
||||
<div class="msg msg-assistant">
|
||||
<div class="bubble"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script src="/static/app.js" defer></script>
|
||||
</body>
|
||||
</html>
|
||||
175
web/static/styles.css
Normal file
175
web/static/styles.css
Normal file
@@ -0,0 +1,175 @@
|
||||
:root {
|
||||
--bg: #0e1116;
|
||||
--panel: #161b22;
|
||||
--muted: #8b949e;
|
||||
--text: #e6edf3;
|
||||
--accent: #2f81f7;
|
||||
--accent-2: #3fb950;
|
||||
--danger: #f85149;
|
||||
--bubble-user: #1f6feb22;
|
||||
--bubble-assistant: #30363d;
|
||||
--radius: 10px;
|
||||
--shadow: 0 8px 24px rgba(0,0,0,0.25);
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
|
||||
html, body {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji";
|
||||
background: linear-gradient(180deg, #0e1116 0%, #0b0e13 100%);
|
||||
color: var(--text);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.app-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 14px 18px;
|
||||
background: rgba(22,27,34,0.8);
|
||||
backdrop-filter: blur(6px);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 10;
|
||||
border-bottom: 1px solid #21262d;
|
||||
}
|
||||
|
||||
.app-header h1 {
|
||||
font-size: 16px;
|
||||
margin: 0;
|
||||
letter-spacing: 0.3px;
|
||||
color: var(--text);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.status {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 999px;
|
||||
background: var(--muted);
|
||||
box-shadow: 0 0 0 1px #21262d inset, 0 0 8px rgba(0,0,0,0.35);
|
||||
}
|
||||
.status.ok { background: var(--accent-2); box-shadow: 0 0 0 1px #2e7d32 inset, 0 0 16px rgba(63,185,80,0.6); }
|
||||
.status.err { background: var(--danger); box-shadow: 0 0 0 1px #7f1d1d inset, 0 0 16px rgba(248,81,73,0.6); }
|
||||
|
||||
.container {
|
||||
width: 100%;
|
||||
max-width: 900px;
|
||||
margin: 18px auto 24px;
|
||||
padding: 0 14px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
|
||||
.chat {
|
||||
background: var(--panel);
|
||||
border: 1px solid #21262d;
|
||||
border-radius: var(--radius);
|
||||
min-height: 420px;
|
||||
max-height: calc(100vh - 230px);
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
|
||||
.messages {
|
||||
flex: 1 1 auto;
|
||||
overflow-y: auto;
|
||||
padding: 16px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.msg {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.msg-user { justify-content: flex-end; }
|
||||
.msg-assistant { justify-content: flex-start; }
|
||||
|
||||
.msg .bubble {
|
||||
max-width: 78%;
|
||||
padding: 10px 12px;
|
||||
line-height: 1.35;
|
||||
border-radius: 14px;
|
||||
font-size: 14px;
|
||||
border: 1px solid #30363d;
|
||||
word-wrap: break-word;
|
||||
word-break: break-word;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.msg-user .bubble {
|
||||
background: var(--bubble-user);
|
||||
border-color: #1f6feb55;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.msg-assistant .bubble {
|
||||
background: var(--bubble-assistant);
|
||||
border-color: #30363d;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.input-row {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
background: var(--panel);
|
||||
border: 1px solid #21262d;
|
||||
border-radius: var(--radius);
|
||||
padding: 10px;
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
|
||||
.input-row input[type="text"] {
|
||||
flex: 1 1 auto;
|
||||
background: #0d1117;
|
||||
color: var(--text);
|
||||
border: 1px solid #30363d;
|
||||
border-radius: 8px;
|
||||
padding: 12px 12px;
|
||||
outline: none;
|
||||
transition: border-color 0.2s ease, box-shadow 0.2s ease;
|
||||
}
|
||||
|
||||
.input-row input[type="text"]:focus {
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 3px rgba(47,129,247,0.25);
|
||||
}
|
||||
|
||||
.input-row button {
|
||||
flex: 0 0 auto;
|
||||
background: linear-gradient(180deg, #238636 0%, #2ea043 100%);
|
||||
color: #fff;
|
||||
border: 1px solid #2ea043;
|
||||
border-radius: 8px;
|
||||
padding: 0 16px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
min-width: 92px;
|
||||
transition: transform 0.05s ease-in-out, filter 0.2s ease;
|
||||
}
|
||||
|
||||
.input-row button:hover { filter: brightness(1.05); }
|
||||
.input-row button:active { transform: translateY(1px); }
|
||||
.input-row button:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.7;
|
||||
filter: grayscale(0.2);
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.messages { padding: 12px; }
|
||||
.msg .bubble { max-width: 90%; }
|
||||
}
|
||||
Reference in New Issue
Block a user