From 4661596ce37fb920a75fb005e4e79d9191d4694a Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Mon, 26 Oct 2026 20:22:05 +0100 Subject: [PATCH] Web page: the chat view in eight languages, and the page's docs Everything the Chat view shows (header, tabs, message box, settings, toasts, tool blocks, the sidebar, the history and Load/Unload texts) now goes through the translation catalog: serve/web/locales/{de,es,ja,ko,pt,ru,zh}.json beside en.json (written from the English text in the code by tools/web_i18n.py). Plurals follow the language (Russian has few and many, Japanese and Korean only one form). serve/test_web_i18n.py fails when a catalog lacks a key, has a stale one or changes a {placeholder}. A ninth language is one file plus one line in serve/web/i18n.js. The Monitor, Images and About views are still English (the language setting says so); they are the next step. Browser tests: a language pick translates and is kept, /?lang= is for one visit, an unknown code stays English, all seven catalogs load without an error. docs/DETAILS.md: a section "The web page" (every switch, what the preview can and cannot reach, the languages, the tests), the Sampling drawer's new name, and the credits (KaTeX and the contributors of the PRs ported into the page). --- docs/DETAILS.md | 57 ++++++- serve/web/app.js | 61 ++++---- serve/web/index.html | 18 +-- serve/web/locales/de.json | 249 +++++++++++++++++++++++++++++++ serve/web/locales/en.json | 264 +++++++++++++++++++++++++++++++++ serve/web/locales/es.json | 249 +++++++++++++++++++++++++++++++ serve/web/locales/ja.json | 249 +++++++++++++++++++++++++++++++ serve/web/locales/ko.json | 249 +++++++++++++++++++++++++++++++ serve/web/locales/pt.json | 249 +++++++++++++++++++++++++++++++ serve/web/locales/ru.json | 249 +++++++++++++++++++++++++++++++ serve/web/locales/zh.json | 249 +++++++++++++++++++++++++++++++ tools/web_i18n.py | 2 +- tools/webtest/browser_test.mjs | 45 ++++++ 13 files changed, 2153 insertions(+), 37 deletions(-) create mode 100644 serve/web/locales/de.json create mode 100644 serve/web/locales/en.json create mode 100644 serve/web/locales/es.json create mode 100644 serve/web/locales/ja.json create mode 100644 serve/web/locales/ko.json create mode 100644 serve/web/locales/pt.json create mode 100644 serve/web/locales/ru.json create mode 100644 serve/web/locales/zh.json diff --git a/docs/DETAILS.md b/docs/DETAILS.md index e5c23659..92360d80 100644 --- a/docs/DETAILS.md +++ b/docs/DETAILS.md @@ -676,6 +676,56 @@ curl -X POST "http://127.0.0.1:8080/slots/0?action=restore" -H "Content-Type: ap only for this feature. Exact token replay across restarts is not guaranteed: expert residency and CPU/GPU rounding can change later output. +### The web page (Chat, Images, Monitor, About) + +Open the server's address in a browser. Everything in it runs from the server's own files: no CDN, no outside address. Chats, +settings and the API key stay in the browser. + +**Chat settings** (the button next to the message box) holds the sampling and thinking settings and the switches below. Every +switch below is **off by default**; with all of them off the page behaves as it did before. + +- **Render math.** Equations written as `\( ... \)`, `\[ ... \]`, `$x$` or `$$ ... $$` are drawn as formulas by KaTeX 0.19.0, which + ships in `serve/web/vendor/katex` (MIT; `PROVENANCE.json` there lists the package and a hash of every file). The text of a + message is never changed: copying, the Markdown export and the next request all carry what the model wrote. Code, prices + (`$5 and $10`) and a formula still being written stay text. A formula KaTeX cannot read stays as its source. A formula can only + draw: it cannot make a link, load a picture or run anything (`\href`, `\url`, `\includegraphics` and `\htmlClass` are shown as + their own names). +- **Saved chats list.** Keeps every chat in a list on the left, with search over titles and text, rename, delete (with Undo) and + days as headings. The chats live in this browser's IndexedDB; a picture or file is kept by name only. Nothing goes to the server. + In a private window, or when the browser's storage is full, the list stays in memory and the page says so once. Turning it on + keeps the chat on the screen as the first one in the list; turning it off keeps that chat as the single chat. +- **Edit and rewind messages.** Under each message: **Regenerate** (a new answer to the same question), **Edit answer** (correct its + text; the old thinking and tool calls go and no request is sent) and **Rewind to here**. Rewind asks what you want. On your + message, **Edit and send again here** hides it and the messages after it and puts it in the box; on an answer, **Continue from + here** hides the messages after it. **Branch from here** (needs the saved chats list) starts a new chat from the messages up to + that point and leaves this chat as it is; the branch keeps a name such as "Branch of ..." and links back to the original. An + **Undo** bar above the box brings back what was hidden, until your next question, another chat or a reload. A picture or file + that was only kept by name is not sent again: the page asks you to attach it again. +- **When you send while it is answering.** *Wait* (the default): Send is off until the answer is done. *Send after*: your message + waits and goes when the answer is done. *Interrupt*: the answer stops where it is, what was written stays and is marked + interrupted, and your message goes at once; a tool that is running finishes first. Only one message waits, and **Take back** + returns it to the box. Stop keeps a waiting message for you to send yourself. + +An answer's ` ```svg ` or ` ```html ` block gets a **Preview** button. The code is drawn in a frame that is cut off from the page: +an empty sandbox (no scripts, forms, popups or downloads, and no access to the page, its storage or the server), a policy inside +the frame that allows no address at all, and a page header (`Content-Security-Policy: frame-src 'none'`) that keeps a link or a +redirect in the model's HTML from loading a web page into it. An svg is shown as a picture. For an HTML page there is also a +warning button, **Run scripts**: after you confirm, that one block runs with scripts, still with no way to the page and no network, +until you close the preview. It can still use your CPU, and it is code the model wrote. + +**Load / Unload** in the header loads the model or frees the GPU (`POST /load`, `POST /unload`). It asks before unloading and is off +while an answer is being written or an image is made. + +**Language.** About > Settings lists the page's languages: English (the default), German, Spanish, Japanese, Korean, Portuguese, +Russian and Chinese. The Chat view, its settings and the header are translated; Monitor, Images and About are still English. A +language is a file `serve/web/locales/.json`; the English text lives in the code next to its key, and +`python tools/web_i18n.py` checks every file for the same keys and placeholders (`--write` rewrites `en.json`). `/?lang=de` shows a +language for one visit. + +Tests: `serve/test_web_*.py` and `serve/test_web_*.js` (Node), and a browser run against a stand-in server with no model: +`WEBTEST_MODULES= node tools/webtest/browser_test.mjs`. `tools/webtest/shots.mjs` takes the page's +screenshots. + ### API request monitor Off by default, because it keeps prompts and answers in memory. Turn it on with `"api_monitor": true` or @@ -765,7 +815,7 @@ after a change. needed for `npx` servers. An **address** (`url`, optional `headers`) uses MCP's Streamable HTTP transport (the older SSE-only transport is not supported). `"disabled": true` leaves an entry out. - Servers start with Strata. The server window says what each offers or why it did not start. The Monitor tab lists them, and - the Sampling drawer has **Use tools from MCP servers** (on by default). A server that stops later is started again at its next call. + Chat settings has **Use tools from MCP servers** (on by default). A server that stops later is started again at its next call. - In the chat each call shows as a small block. The model reads the result and goes on, up to `max_rounds` calls in a row. A tool that fails or takes longer than `timeout_s` gives the model an `error: ...` result. Results longer than `max_result_chars` are cut with a note. Stop stops a running tool too. @@ -1042,7 +1092,7 @@ your own prompts. The Monitor marks every request ESP or stock. ``` The engine log then says `control vector mode = project, dir = per-layer, layers 4..44 (41 steered)`. A loaded vector is on for -every request unless it says otherwise: the Sampling drawer has a switch, and the API takes `"experimental_speed_projection": false` +every request unless it says otherwise: Chat settings has a switch, and the API takes `"experimental_speed_projection": false` (config default: `"sampling": {"experimental_speed_projection": false}`). Switching drops the conversation cache once. Switched off, the output is token for token the stock model's. @@ -1154,6 +1204,9 @@ Strata itself: [MIT](../LICENSE). The model files are not part of it; their lice [HyperQwen](https://github.com/syv-ai/HyperQwen); references in the paper. - The web app's font: [Outfit](https://github.com/Outfitio/Outfit-Fonts) (SIL Open Font License 1.1, see `serve/web/fonts/OFL.txt`). Its Monitor tab started from @code-martin's dashboard idea (PR #22). + Math is drawn by [KaTeX](https://katex.org) (MIT, vendored in `serve/web/vendor/katex`). The chat page's wide-window layout, svg/html preview, math, Load/Unload, saved + chats, edit and rewind came from PRs #3176 (@mnott), #1628 (@thoives), #2972 and #2974 (@CC-David-CC), #3550 (@sakuumomo), #1787 (@Scotty-Hudson) and + #2615 (@uppet), and the rewind choice and sending while answering from issues #3823 and #4004 (@xvcezrqpbxtpzblrt). - The experimental speed projection's vector (`data/experimental-speed-projection/`): Qwen Community License 1.0, made from the model's activations (see its README). diff --git a/serve/web/app.js b/serve/web/app.js index e0ad80aa..46d79bea 100644 --- a/serve/web/app.js +++ b/serve/web/app.js @@ -50,7 +50,7 @@ async function copyText(text, btn) { use.setAttribute("href", `${SPRITE}#i-check`); setTimeout(() => use.setAttribute("href", `${SPRITE}#i-copy`), 1500); } - toast("success", "Copied to clipboard", "", 1800); + toast("success", tr("toast.copied", "Copied to clipboard"), "", 1800); } // ------------------------------------------------------------------ theme and tabs @@ -108,12 +108,16 @@ $("api-key").oninput = () => saveApiKey(); $("api-key").onchange = () => saveApiKey(true); let health = {model: "strata", images: false, max_context: 0}; +// the texts that depend on what this server offers: the empty chat's line and the attach button's hint +function renderEmptyChat() { + $("attach-btn").title = health.images ? tr("composer.attachPictures", "Attach a text file or a picture (or drop it here)") + : tr("composer.attach", "Attach a text file (or drop it here)"); + $("chat-empty-sub").textContent = tr("chat.emptyModel", "{model} runs on this PC. Nothing leaves it.", {model: health.model}); +} async function loadHealth() { try { health = await (await fetch("health")).json(); - $("attach-btn").title = health.images ? "Attach a text file or a picture (or drop it here)" - : "Attach a text file (or drop it here)"; - $("chat-empty-sub").textContent = `${health.model} runs on this PC. Nothing leaves it.`; + renderEmptyChat(); $("tab-btn-images").hidden = !health.image_generation; if (location.hash === "#images" && health.image_generation) showTab("images"); } catch (e) { @@ -817,8 +821,8 @@ function msgEl(m, i) { const wrap = document.createElement("div"); wrap.className = "msg-images"; for (const im of m.images) { - if (im.url) { const img = document.createElement("img"); img.src = im.url; img.alt = im.name || "image"; wrap.appendChild(img); } - else { const c = document.createElement("span"); c.className = "chip"; c.innerHTML = icon("image", "st-icon st-icon--sm"); c.append(im.name || "image"); wrap.appendChild(c); } + if (im.url) { const img = document.createElement("img"); img.src = im.url; img.alt = im.name || tr("chat.image", "image"); wrap.appendChild(img); } + else { const c = document.createElement("span"); c.className = "chip"; c.innerHTML = icon("image", "st-icon st-icon--sm"); c.append(im.name || tr("chat.image", "image")); wrap.appendChild(c); } } el.appendChild(wrap); } @@ -828,13 +832,13 @@ function msgEl(m, i) { el.appendChild(b); const meta = document.createElement("div"); meta.className = "st-msg__meta"; - meta.textContent = `You · ${timeStr(m.time)}`; + meta.textContent = `${tr("chat.you", "You")} · ${timeStr(m.time)}`; el.appendChild(meta); } else { el.innerHTML = `` + `
` + - `
`; + ``; updateAssistant(el, m, false); } const actions = msgActions(m, i); // edit / regenerate / rewind (chats-ui.js), when switched on @@ -843,18 +847,20 @@ function msgEl(m, i) { } // One MCP tool call in the answer: a compact block (name, state, a one-line preview) that opens to the arguments and // the result as the model read it. Its body is built only while open: a result can be 20,000 characters. -const TOOL_STATE = {writing: ["st-badge--reading", "Writing"], running: ["st-badge--generating", "Running"], done: ["", "Done"], - error: ["st-badge--error", "Error"], skipped: ["st-badge--queued", "Not run"]}; +const TOOL_STATE = {writing: ["st-badge--reading", () => tr("tool.writing", "Writing")], running: ["st-badge--generating", () => tr("tool.running", "Running")], + done: ["", () => tr("tool.done", "Done")], error: ["st-badge--error", () => tr("tool.error", "Error")], + skipped: ["st-badge--queued", () => tr("tool.skipped", "Not run")]}; function toolHtml(t, k) { - const [cls, label] = TOOL_STATE[t.state] || ["", t.state]; + const [cls, labelOf] = TOOL_STATE[t.state] || ["", () => t.state]; + const label = labelOf(); const args = t.arguments == null ? "" : JSON.stringify(t.arguments, null, 2); const preview = t.result != null ? t.result : args.replace(/\s+/g, " "); let body = ""; if (t.open) { - body = `
Arguments
${esc(args || "(being written)")}
`; + body = `
${esc(tr("tool.arguments", "Arguments"))}
${esc(args || tr("tool.beingWritten", "(being written)"))}
`; if (t.result != null) { - body += `
${t.ok ? "Result" : "Error"}${t.chars ? ` · ${fmt(t.chars)} characters` : ""}` + - `${t.truncated ? ", cut for the model" : ""}
${esc(t.result)}
`; + body += `
${esc(t.ok ? tr("tool.result", "Result") : tr("tool.error", "Error"))}${t.chars ? ` · ${esc(tr("tool.chars", "{n} characters", {n: fmt(t.chars)}))}` : ""}` + + `${t.truncated ? esc(tr("tool.cut", ", cut for the model")) : ""}
${esc(t.result)}
`; } } return `
` + @@ -898,8 +904,8 @@ function updateAssistant(el, m, streaming) { if (m.reasoning) { det.hidden = false; const thinkingNow = streaming && !m.text; - el.querySelector(".think-title").textContent = thinkingNow ? "Thinking…" : - m.thinkSecs != null ? `Thought for ${fmt(m.thinkSecs, 1)} s` : "Thoughts"; + el.querySelector(".think-title").textContent = thinkingNow ? tr("think.now", "Thinking…") : + m.thinkSecs != null ? tr("think.for", "Thought for {s} s", {s: fmt(m.thinkSecs, 1)}) : tr("think.done", "Thoughts"); const body = el.querySelector(".thinking"); if (det.open || thinkingNow) body.textContent = m.reasoning; else body.dataset.pending = "1"; @@ -918,7 +924,7 @@ function updateAssistant(el, m, streaming) { if (settings.math) StrataMath.hydrate(bubble); if (streaming) bubble.classList.add("cursor"); else bubble.classList.remove("cursor"); } - el.querySelector(".meta-text").textContent = m.meta || (streaming ? "" : m.stopped ? "Stopped" : ""); + el.querySelector(".meta-text").textContent = m.meta || (streaming ? "" : m.stopped ? tr("chat.stopped", "Stopped") : ""); el.querySelector("[data-msg-copy]").hidden = streaming || !m.text; } function renderChat() { @@ -1256,7 +1262,7 @@ $("new-btn").onclick = () => { }}); }; $("export-btn").onclick = () => { - if (!messages.length) { toast("info", "Nothing to save yet"); return; } + if (!messages.length) { toast("info", tr("export.nothing", "Nothing to save yet")); return; } const tools = (m) => (m.tools || []).filter((t) => t.result != null).map((t) => `
Tool ${t.server ? `${t.server} / ` : ""}${t.tool || t.name}${t.ok ? "" : " (error)"}\n\n` + `\`\`\`json\n${JSON.stringify(t.arguments || {}, null, 2)}\n\`\`\`\n\n\`\`\`\n${t.result}\n\`\`\`\n\n
\n\n`).join(""); @@ -1279,19 +1285,20 @@ function isTextFile(f) { function addFiles(files) { for (const f of files) { if (f.type.startsWith("image/")) { - if (!health.images) { toast("warn", "Pictures are off", "This model was set up for text only."); continue; } - if (f.size > 20e6) { toast("warn", "Picture too large", `${f.name} is over 20 MB.`); continue; } + if (!health.images) { toast("warn", tr("file.picturesOff", "Pictures are off"), tr("file.picturesOffText", "This model was set up for text only.")); continue; } + if (f.size > 20e6) { toast("warn", tr("file.pictureBig", "Picture too large"), tr("file.pictureBigText", "{name} is over 20 MB.", {name: f.name})); continue; } const r = new FileReader(); - r.onload = () => { attachments.push({kind: "image", name: f.name || "pasted image", url: r.result}); renderAttachments(); }; + r.onload = () => { attachments.push({kind: "image", name: f.name || tr("file.pasted", "pasted image"), url: r.result}); renderAttachments(); }; r.readAsDataURL(f); continue; } - if (!isTextFile(f)) { toast("warn", "Not a text file", `${f.name}: attach text files (code, notes, logs, data)${health.images ? " or pictures" : ""}.`); continue; } - if (f.size > MAX_TEXT_FILE) { toast("warn", "File too large", `${f.name} is over 512 KB.`); continue; } + if (!isTextFile(f)) { toast("warn", tr("file.notText", "Not a text file"), health.images ? tr("file.notTextPictures", "{name}: attach text files (code, notes, logs, data) or pictures.", {name: f.name}) + : tr("file.notTextOnly", "{name}: attach text files (code, notes, logs, data).", {name: f.name})); continue; } + if (f.size > MAX_TEXT_FILE) { toast("warn", tr("file.big", "File too large"), tr("file.bigText", "{name} is over 512 KB.", {name: f.name})); continue; } const r = new FileReader(); r.onload = () => { const text = String(r.result); - if (text.includes("\u0000")) { toast("warn", "Not a text file", `${f.name} looks like a binary file.`); return; } + if (text.includes("\u0000")) { toast("warn", tr("file.notText", "Not a text file"), tr("file.binaryText", "{name} looks like a binary file.", {name: f.name})); return; } attachments.push({kind: "file", name: f.name, text}); renderAttachments(); }; @@ -1318,7 +1325,7 @@ function renderAttachments() { c.innerHTML = icon(a.kind === "file" ? "attach" : "image", "st-icon st-icon--sm"); c.append(a.name); const x = document.createElement("button"); - x.type = "button"; x.className = "st-btn st-btn--icon"; x.setAttribute("aria-label", "Remove"); + x.type = "button"; x.className = "st-btn st-btn--icon"; x.setAttribute("aria-label", tr("file.remove", "Remove")); x.innerHTML = icon("trash"); x.onclick = () => { attachments.splice(i, 1); renderAttachments(); }; c.appendChild(x); @@ -1472,6 +1479,9 @@ const urlLang = new URLSearchParams(location.search).get("lang"); $("lang").innerHTML = StrataI18n.LANGUAGES.map(([code, name]) => ``).join(""); function showLanguage() { $("lang").value = StrataI18n.lang; + renderEmptyChat(); + setSidebar(sidebarOpen, false); + outputs(); renderChat(); setBusy(!!busy); if (lastMetrics) render(lastMetrics); @@ -1486,6 +1496,7 @@ $("lang").onchange = async () => { async function start() { await StrataI18n.setLanguage(urlLang || store.get("lang", "en")); $("lang").value = StrataI18n.lang; + renderEmptyChat(); initChats(); if (settings.chatList) await setChatList(true, false); // the saved-chats list is read before the first draw setBusy(false); diff --git a/serve/web/index.html b/serve/web/index.html index 0511153d..4de2fc44 100644 --- a/serve/web/index.html +++ b/serve/web/index.html @@ -20,21 +20,21 @@
Strata -
@@ -61,7 +61,7 @@
Ask anything
-
The model runs on this PC. Nothing leaves it.
+
The model runs on this PC. Nothing leaves it.
@@ -70,7 +70,7 @@
-