okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-027-web: the served web chat page for 0.2.75d9f47922

main
7.4 KiB160 linesraw
1// Screenshots of the served web page (serve/web) in its new states, against the mock server (no model):
2//   WEBTEST_MODULES=<folder with node_modules/puppeteer-core> node tools/webtest/shots.mjs <out folder> [name-substring]
3import { startMock } from "./mock.mjs";
4import { launch, openPage, say, idle, sleep, shot } from "./lib.mjs";
5
6const out = process.argv[2] || "shots";
7const only = process.argv[3];
8const mock = await startMock();
9const browser = await launch();
10const turn = (role, text, extra = {}) => ({ role, text, time: Date.now(), ...extra });
11const fence = (lang, code) => "```" + lang + "\n" + code + "\n```\n";
12const on = (extra = {}) => ({ sampling: { chatList: true, chatEdit: true, ...extra } });
13const day = 86400000;
14
15const LONG = "Here is a short plan.\n\n1. Read the notes the user attached.\n2. Write the summary in plain words.\n3. List the open questions.\n\n" +
16  "The summary is **short** on purpose: three sentences, no jargon, and one next step.\n\n| Step | Who | When |\n|---|---|---|\n| Read | You | Today |\n| Summary | Me | Now |\n";
17const CHAT = [turn("user", "Can you plan how to summarise my notes?"), turn("assistant", LONG, { meta: "212 tokens · 41.3 tok/s" }),
18              turn("user", "Make it shorter, please."), turn("assistant", "Sure. Read the notes, write three sentences, list what is still open.", { meta: "24 tokens · 40.8 tok/s" })];
19
20// the saved-chats list with chats from different days (put into the page's own store, then the page is reloaded)
21async function seedChats(page) {
22  await page.evaluate(async (base, d) => {
23    const mk = (id, title, days, text) => ({ id, title, time: Date.now() - days * d, messages: [{ role: "user", text, time: 1 }, { role: "assistant", text: "Sure.", time: 2 }] });
24    for (const c of [mk("s1", "", 0.1, "Plan my week"), mk("s2", "Garden plan", 0.2, "Which tomatoes grow in shade?"), mk("s3", "", 1.5, "Translate this letter"),
25                     mk("s4", "Branch of Recipe ideas", 3, "Recipe ideas"), mk("s5", "", 12, "Explain compound interest"), mk("s6", "", 50, "Old question about the printer")]) {
26      chatStore.put(StrataHistory.cleanChat(c));
27    }
28  }, null, day);
29  await sleep(300);
30  await page.reload({ waitUntil: "networkidle0" });
31}
32
33const shots = [
34  ["01-wide-window", async () => {
35    const p = await openPage(browser, mock, { width: 2560, height: 1300, seed: { chat: CHAT, ...on() } });
36    await seedChats(p);
37    return p;
38  }],
39  ["02-saved-chats-list", async () => {
40    const p = await openPage(browser, mock, { width: 1280, height: 800, seed: { chat: CHAT, ...on() } });
41    await seedChats(p);
42    return p;
43  }],
44  ["03-rewind-choice", async () => {
45    const p = await openPage(browser, mock, { width: 1280, height: 800, seed: { chat: CHAT, ...on() } });
46    await p.evaluate(() => { const i = 2; openRewind(i); });
47    await sleep(200);
48    return p;
49  }],
50  ["04-undo-bar", async () => {
51    const p = await openPage(browser, mock, { width: 1280, height: 800, seed: { chat: CHAT, ...on() } });
52    await p.evaluate(() => { openRewind(2); });
53    await p.$eval(".history-panel .st-btn--primary", (b) => b.click());
54    await sleep(200);
55    return p;
56  }],
57  ["05-edit-answer", async () => {
58    const p = await openPage(browser, mock, { width: 1280, height: 800, seed: { chat: CHAT, ...on() } });
59    await p.evaluate(() => { editAnswerAt(3); });
60    await sleep(200);
61    return p;
62  }],
63  ["06-branch-from-here", async () => {
64    const p = await openPage(browser, mock, { width: 1280, height: 800, seed: { chat: CHAT, ...on() } });
65    await p.evaluate(() => { openRewind(2); });
66    await p.evaluate(() => [...document.querySelectorAll(".history-panel .st-btn")].find((b) => b.textContent === "Branch from here").click());
67    await sleep(300);
68    return p;
69  }],
70  ["07-math", async () => {
71    const p = await openPage(browser, mock, { width: 1100, height: 760, seed: { sampling: { math: true } } });
72    await say(p, "#math show me"); await idle(p); await sleep(900);
73    return p;
74  }],
75  ["08-math-dark", async () => {
76    const p = await openPage(browser, mock, { width: 1100, height: 760, dark: true, seed: { sampling: { math: true } } });
77    await say(p, "#math show me"); await idle(p); await sleep(900);
78    return p;
79  }],
80  ["09-svg-preview", async () => {
81    const p = await openPage(browser, mock, { width: 1100, height: 760 });
82    await say(p, "#svg draw a circle"); await idle(p); await sleep(200);
83    await p.click("[data-preview-toggle]"); await sleep(400);
84    return p;
85  }],
86  ["10-html-preview-and-scripts", async () => {
87    const p = await openPage(browser, mock, { width: 1100, height: 760 });
88    await say(p, "#html make a page"); await idle(p); await sleep(200);
89    await p.click("[data-preview-toggle]"); await sleep(300);
90    await p.click("[data-preview-scripts]"); await sleep(500);
91    return p;
92  }],
93  ["11-narrow-chat", async () => {
94    const p = await openPage(browser, mock, { width: 390, height: 780, seed: { chat: CHAT, ...on() } });
95    await sleep(200);
96    return p;
97  }],
98  ["12-narrow-saved-chats-open", async () => {
99    const p = await openPage(browser, mock, { width: 390, height: 780, seed: { chat: CHAT, ...on() } });
100    await seedChats(p);
101    await p.click("#sidebar-toggle"); await sleep(300);
102    return p;
103  }],
104  ["13-narrow-header-320", async () => openPage(browser, mock, { width: 320, height: 640, seed: { chat: CHAT } })],
105  ["14-chat-settings", async () => {
106    const p = await openPage(browser, mock, { width: 1280, height: 900, seed: { chat: CHAT } });
107    await p.click("#sampling-btn"); await sleep(500);
108    await p.$eval(".st-drawer__body", (e) => { e.scrollTop = e.scrollHeight; });
109    await sleep(200);
110    return p;
111  }],
112  ["15-send-while-answering", async () => {
113    const p = await openPage(browser, mock, { width: 1100, height: 760, seed: on({ whileBusy: "queue" }) });
114    await say(p, "#hold start a long answer");
115    await p.waitForFunction(() => busy !== null);
116    await sleep(500);
117    await say(p, "And then summarise it for me");
118    await sleep(300);
119    return p;
120  }],
121  ["16-load-unload", async () => {
122    mock.state.loaded = false;
123    const p = await openPage(browser, mock, { width: 1100, height: 520 });
124    await sleep(1500);
125    return p;
126  }],
127  ["18-german-chat", async () => {
128    const p = await openPage(browser, mock, { width: 1280, height: 800, query: "?lang=de", seed: { chat: CHAT, ...on() } });
129    await p.evaluate(() => { openRewind(2); });
130    await sleep(200);
131    return p;
132  }],
133  ["19-german-chat-settings", async () => {
134    const p = await openPage(browser, mock, { width: 1280, height: 900, query: "?lang=de", seed: { chat: CHAT } });
135    await p.click("#sampling-btn"); await sleep(500);
136    await p.$eval(".st-drawer__body", (e) => { e.scrollTop = e.scrollHeight; });
137    await sleep(200);
138    return p;
139  }],
140  ["20-dark-saved-chats", async () => {
141    const p = await openPage(browser, mock, { width: 1280, height: 800, dark: true, seed: { chat: CHAT, ...on() } });
142    await seedChats(p);
143    return p;
144  }],
145  ["17-narrow-wide-mid-900", async () => openPage(browser, mock, { width: 900, height: 700, seed: { chat: CHAT, ...on() } })],
146];
147
148try {
149  for (const [name, make] of shots) {
150    if (only && !name.includes(only)) continue;
151    mock.state.loaded = true;
152    const page = await make();
153    await sleep(300);
154    console.log(await shot(page, out, name), page.errors.length ? "ERRORS " + page.errors.join(" | ") : "");
155    await page.close();
156  }
157} finally {
158  await browser.close();
159  await mock.stop();
160}