fix(app): 대화 screen keeps loaded pages when new items fill the window and loads one older page at a time
- paging moves to app/ui/talk.js (pure, node --test app/tests/ui/talk.test.mjs) - items the full live window no longer reaches join the older pages instead of being dropped - "이전 기록 더 보기" runs one request at a time and never adds a loaded item twice - the screen and spec state that only the newest 2,000 items are re-read live Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -739,12 +739,17 @@ Plain HTML, CSS and an ES module, no build step, dark theme after `DESIGN.md`. A
|
||||
notes it was given, the tools offered, the plan, the model's thinking, each tool call (name,
|
||||
arguments, success, failure or skipped and why, its result) and the answer. Filters: the three
|
||||
kinds as chips, where (음성, 채팅, 정기 작업), person, channel, one day and text; "실시간" (on by
|
||||
default) re-reads every item from the oldest one shown on (`from`, up to 2,000; older pages beyond
|
||||
that stay as loaded) every 3 seconds and redraws only when an item changed, an edited message
|
||||
included, keeping the cards the user opened open and the scroll where it was unless it was at the
|
||||
end; "이전 기록 더 보기" adds the 200 items before the oldest shown (`before`), with no end to how far
|
||||
back it goes; a filter change drops every answer to a request made before it, and a live answer
|
||||
older than the newest one asked is dropped; "생각 모두 펼치기/접기"; a count of each kind shown.
|
||||
default) re-reads the live window every 3 seconds: every item from its first one on (`from`, up to
|
||||
2,000). Only items in that window change on screen, an edited message included; items paged back
|
||||
past it stay as they were loaded (edits and deletes there show after a reload of the screen). The
|
||||
screen redraws only when an item changed, keeping the cards the user opened open and the scroll
|
||||
where it was unless it was at the end. When more new items arrive than the window holds, the
|
||||
shown items it no longer reaches join the pages kept as loaded, so nothing on screen disappears.
|
||||
"이전 기록 더 보기" adds the 200 items before the oldest loaded (`before`), one request at a time
|
||||
(the button is off meanwhile, and an item already loaded is never added again), with no end to
|
||||
how far back it goes; a filter change drops every answer to a request made before it, and a live
|
||||
answer older than the newest one asked is dropped; "생각 모두 펼치기/접기"; a count of each kind
|
||||
shown. The paging is `app/ui/talk.js`, pure, checked by `node --test app/tests/ui/talk.test.mjs`.
|
||||
- **한 일**: the activity (time, kind, target, who asked, outcome and why it failed), newest 200,
|
||||
with a refresh button.
|
||||
- **업데이트**: the version here, the state, "다시 확인", "받기" (with its percentage) and "설치하고
|
||||
|
||||
48
app/tests/ui/talk.test.mjs
Normal file
48
app/tests/ui/talk.test.mjs
Normal file
@@ -0,0 +1,48 @@
|
||||
// The 대화 screen's paging (app/ui/talk.js; admin.spec.md, "Screens"). Run: node --test app/tests/ui/talk.test.mjs
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { PAGE, PAGE_MAX, compare, empty, withLive, withOlder } from "../../ui/talk.js";
|
||||
|
||||
const rec = (n) => ({ key: `h${n}`, at: n, type: "said", text: `말 ${n}` });
|
||||
const range = (a, b) => Array.from({ length: b - a }, (_, i) => rec(a + i));
|
||||
const keys = (s) => s.older.concat(s.shown).map((i) => i.key);
|
||||
|
||||
/** The screen's state after the first page and as many "이전 기록 더 보기" as the store allows. */
|
||||
function allLoaded(total) {
|
||||
const store = range(0, total);
|
||||
let s = withLive(empty(), store.slice(-PAGE), total > PAGE);
|
||||
while (s.hasOlder) {
|
||||
const oldest = (s.older[0] || s.shown[0]).at;
|
||||
const before = store.filter((i) => i.at < oldest);
|
||||
s = withOlder(s, before.slice(-PAGE), before.length > PAGE);
|
||||
}
|
||||
return { s, store };
|
||||
}
|
||||
|
||||
test("every older page joins once, past the live window", () => {
|
||||
const { s } = allLoaded(2501);
|
||||
assert.equal(s.shown.length, PAGE_MAX);
|
||||
assert.deepEqual(keys(s), range(0, 2501).map((i) => i.key));
|
||||
});
|
||||
|
||||
test("the same older page arriving twice is not added twice", () => {
|
||||
let s = withLive(empty(), range(300, 500), true);
|
||||
s = withOlder(s, range(100, 300), true);
|
||||
s = withOlder(s, range(100, 300), true);
|
||||
assert.deepEqual(keys(s), range(100, 500).map((i) => i.key));
|
||||
});
|
||||
|
||||
test("a new item on a full window keeps everything loaded, in order and once", () => {
|
||||
const { s, store } = allLoaded(2501);
|
||||
const now = store.concat(rec(2501));
|
||||
// The live answer: from the window's start, at most PAGE_MAX, newest first cut.
|
||||
const since = now.filter((i) => compare(i, s.shown[0]) >= 0);
|
||||
const next = withLive(s, since.slice(-PAGE_MAX), since.length > PAGE_MAX);
|
||||
assert.deepEqual(keys(next), range(0, 2502).map((i) => i.key));
|
||||
assert.equal(next.shown.length, PAGE_MAX);
|
||||
});
|
||||
|
||||
test("items are ordered by time, then records before traces, then id", () => {
|
||||
const items = [{ key: "t2", at: 1 }, { key: "h10", at: 1 }, { key: "h9", at: 1 }, { key: "h1", at: 0 }];
|
||||
assert.deepEqual(items.sort(compare).map((i) => i.key), ["h1", "h9", "h10", "t2"]);
|
||||
});
|
||||
@@ -2,6 +2,8 @@
|
||||
// the Tauri shell and the development server load the same files. Every action goes through
|
||||
// api(command, args), which the shell answers with AdminApi::call.
|
||||
|
||||
import { PAGE, PAGE_MAX, cursorOf, empty, withLive, withOlder } from "./talk.js";
|
||||
|
||||
const $ = (sel, el = document) => el.querySelector(sel);
|
||||
const h = (tag, attrs = {}, ...kids) => {
|
||||
const el = document.createElement(tag);
|
||||
@@ -446,13 +448,10 @@ function conversationScreen() {
|
||||
const find = h("input", { type: "text", placeholder: "찾기 (말, 답, 생각)", style: "max-width:220px" });
|
||||
const live = h("input", { type: "checkbox", class: "switch", checked: true });
|
||||
const open = new Set(); // traces the user opened stay open across refreshes
|
||||
// The window shown: every item from the cursor `from` on, re-read live (at most PAGE_MAX), plus
|
||||
// `older` pages that no longer fit it. Each filter change starts a new epoch; answers from an
|
||||
// earlier epoch, and live answers older than the newest one asked, are dropped.
|
||||
const PAGE = 200, PAGE_MAX = 2000;
|
||||
const cursorOf = (i) => ({ at: i.at, key: i.key });
|
||||
let expandAll = false, sig = null, shown = [], older = [], from = null, hasOlder = false, missing = false;
|
||||
let epoch = 0, liveSeq = 0, first = true;
|
||||
// `page`: the live window and the older pages (talk.js). Each filter change starts a new epoch;
|
||||
// answers from an earlier epoch, and live answers older than the newest one asked, are dropped.
|
||||
let expandAll = false, sig = null, page = empty(), missing = false;
|
||||
let epoch = 0, liveSeq = 0, first = true, loadingOlder = false;
|
||||
const box = h("div", { class: "talk" });
|
||||
const summary = h("div", { class: "small muted" });
|
||||
const more = h("button", { class: "btn", hidden: true, onclick: () => loadOlder() }, "이전 기록 더 보기");
|
||||
@@ -500,9 +499,9 @@ function conversationScreen() {
|
||||
}
|
||||
|
||||
function render(keepTop = false) {
|
||||
const items = older.concat(shown);
|
||||
const items = page.older.concat(page.shown);
|
||||
// The whole items, so an edited message or a changed answer is redrawn too.
|
||||
const s = JSON.stringify([items, expandAll, hasOlder, missing]);
|
||||
const s = JSON.stringify([items, expandAll, page.hasOlder, missing]);
|
||||
if (s === sig) return;
|
||||
sig = s;
|
||||
const stick = box.scrollTop + box.clientHeight >= box.scrollHeight - 30, fromBottom = box.scrollHeight - box.scrollTop;
|
||||
@@ -515,9 +514,9 @@ function conversationScreen() {
|
||||
}
|
||||
box.replaceChildren(...(kids.length ? kids : [h("div", { class: "muted" },
|
||||
missing ? "아직 대화 기록이 없습니다. 서비스를 켜고 자비스와 이야기하면 여기에 나옵니다." : "조건에 맞는 기록이 없습니다.")]));
|
||||
more.hidden = !hasOlder;
|
||||
more.hidden = !page.hasOlder;
|
||||
const n = (t) => items.filter((i) => i.type === t).length;
|
||||
summary.textContent = `사람 말 ${n("said")} · 자비스 말 ${n("answered")} · 생각 ${n("thought")}` + (hasOlder ? " (이전 기록 더 있음)" : "");
|
||||
summary.textContent = `사람 말 ${n("said")} · 자비스 말 ${n("answered")} · 생각 ${n("thought")}` + (page.hasOlder ? " (이전 기록 더 있음)" : "");
|
||||
if (keepTop) box.scrollTop = box.scrollHeight - fromBottom;
|
||||
else if (stick || first) box.scrollTop = box.scrollHeight;
|
||||
first = false;
|
||||
@@ -529,41 +528,39 @@ function conversationScreen() {
|
||||
fill(channel, r.channels, channelLabel);
|
||||
}
|
||||
|
||||
/** The window from `from` on (the newest page at first), re-read on every live tick. */
|
||||
/** The live window, from its first item on (the newest page at first), re-read on every tick. */
|
||||
async function load() {
|
||||
const ep = epoch, my = ++liveSeq;
|
||||
const ep = epoch, my = ++liveSeq, from = page.from;
|
||||
try {
|
||||
const r = await api("history_query", { ...filters(), ...(from ? { from, limit: PAGE_MAX } : { limit: PAGE }) });
|
||||
if (ep !== epoch || my !== liveSeq) return;
|
||||
lists(r);
|
||||
missing = !!r.missing;
|
||||
if (!from) hasOlder = r.more;
|
||||
else if (r.more) { older = []; hasOlder = true; } // more new ones than a window holds: page back from them
|
||||
shown = r.items;
|
||||
if (shown.length) from = cursorOf(shown[0]);
|
||||
page = withLive(page, r.items, r.more);
|
||||
render();
|
||||
} catch (e) { fail(e); }
|
||||
}
|
||||
|
||||
/** The page before the oldest item shown; it joins the live window while that stays under PAGE_MAX. */
|
||||
/** The page before the oldest item loaded; one at a time, so a double click adds it once. */
|
||||
async function loadOlder() {
|
||||
const oldest = older[0] || shown[0];
|
||||
if (!oldest) return;
|
||||
const oldest = page.older[0] || page.shown[0];
|
||||
if (!oldest || loadingOlder) return;
|
||||
const ep = epoch;
|
||||
loadingOlder = more.disabled = true;
|
||||
try {
|
||||
const r = await api("history_query", { ...filters(), before: cursorOf(oldest), limit: PAGE });
|
||||
if (ep !== epoch) return;
|
||||
++liveSeq; // a live answer asked with the old window would drop this page
|
||||
hasOlder = r.more;
|
||||
if (!older.length && shown.length + r.items.length <= PAGE_MAX) {
|
||||
shown = r.items.concat(shown);
|
||||
if (shown.length) from = cursorOf(shown[0]);
|
||||
} else older = r.items.concat(older);
|
||||
page = withOlder(page, r.items, r.more);
|
||||
render(true);
|
||||
} catch (e) { fail(e); }
|
||||
} catch (e) { fail(e); } finally {
|
||||
if (ep === epoch) loadingOlder = more.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
const reload = () => { epoch++; sig = null; shown = []; older = []; from = null; hasOlder = false; first = true; load(); };
|
||||
const reload = () => {
|
||||
epoch++; sig = null; page = empty(); first = true; loadingOlder = more.disabled = false; load();
|
||||
};
|
||||
for (const el of [said, answered, thought, via, person, channel, day]) el.addEventListener("change", reload);
|
||||
find.addEventListener("input", () => { clearTimeout(find.t); find.t = setTimeout(reload, 300); });
|
||||
const view = h("div", {}, h("h1", {}, "대화"),
|
||||
@@ -573,7 +570,7 @@ function conversationScreen() {
|
||||
h("div", { class: "row" }, h("label", { class: "row small muted" }, live, "실시간"),
|
||||
h("button", { class: "btn", onclick: () => { expandAll = !expandAll; if (!expandAll) open.clear(); sig = null; load(); } }, "생각 모두 펼치기/접기"),
|
||||
h("button", { class: "btn", onclick: () => { sig = null; load(); } }, "새로 고침"), summary)),
|
||||
h("div", { class: "hint", style: "margin:8px 0" }, "사람이 한 말, 자비스의 답, 자비스가 답을 만든 과정(참고한 기록, 고른 도구, 계획, 도구 호출과 결과, 모델 생각)을 시간순으로 보여 줍니다. 모델 생각은 생각 모드가 켜진 답에만 있습니다. 생각 기록은 30일 동안 둡니다."),
|
||||
h("div", { class: "hint", style: "margin:8px 0" }, "사람이 한 말, 자비스의 답, 자비스가 답을 만든 과정(참고한 기록, 고른 도구, 계획, 도구 호출과 결과, 모델 생각)을 시간순으로 보여 줍니다. 모델 생각은 생각 모드가 켜진 답에만 있습니다. 생각 기록은 30일 동안 둡니다. 실시간으로 다시 읽는 것은 최근 2,000개까지이고, 그보다 앞서 불러온 기록의 수정과 삭제는 화면을 다시 열면 보입니다."),
|
||||
h("div", { class: "row", style: "justify-content:center" }, more), box);
|
||||
load();
|
||||
return { view, tick: () => live.checked && load() };
|
||||
|
||||
42
app/ui/talk.js
Normal file
42
app/ui/talk.js
Normal file
@@ -0,0 +1,42 @@
|
||||
// Paging of the 대화 screen (app/src/admin.spec.md, "Screens"). Pure, so app/tests/ui checks it.
|
||||
//
|
||||
// The screen keeps a live window, every item from the cursor `from` on (re-read on each tick, at
|
||||
// most PAGE_MAX), and before it the `older` pages kept as loaded. Items are ordered like
|
||||
// history_query: time, then records (`h<id>`) before traces (`t<id>`), then id.
|
||||
|
||||
export const PAGE = 200, PAGE_MAX = 2000;
|
||||
|
||||
export const cursorOf = (i) => ({ at: i.at, key: i.key });
|
||||
|
||||
export function compare(a, b) {
|
||||
return a.at - b.at || (a.key[0] === b.key[0] ? 0 : a.key[0] < b.key[0] ? -1 : 1)
|
||||
|| Number(a.key.slice(1)) - Number(b.key.slice(1));
|
||||
}
|
||||
|
||||
export const empty = () => ({ shown: [], older: [], from: null, hasOlder: false });
|
||||
|
||||
/** A live answer: the items from `from` on (the newest page while there is no `from`), and
|
||||
* whether there were more than it holds. */
|
||||
export function withLive(s, items, more) {
|
||||
let { older, hasOlder } = s;
|
||||
if (!s.from) hasOlder = more;
|
||||
else if (more && items.length) {
|
||||
// More new items than the window holds: the shown ones it no longer reaches join the pages
|
||||
// kept as loaded, so nothing the user had on screen disappears.
|
||||
const seen = new Set(older.map((i) => i.key));
|
||||
older = older.concat(s.shown.filter((i) => compare(i, items[0]) < 0 && !seen.has(i.key)));
|
||||
}
|
||||
return { shown: items, older, hasOlder, from: items.length ? cursorOf(items[0]) : s.from };
|
||||
}
|
||||
|
||||
/** The page before the oldest item loaded: it joins the live window while that stays within
|
||||
* PAGE_MAX, else the older pages. Items already loaded are not added again. */
|
||||
export function withOlder(s, page, more) {
|
||||
const seen = new Set(s.older.concat(s.shown).map((i) => i.key));
|
||||
const fresh = page.filter((i) => !seen.has(i.key));
|
||||
if (!s.older.length && s.shown.length + fresh.length <= PAGE_MAX) {
|
||||
const shown = fresh.concat(s.shown);
|
||||
return { ...s, shown, hasOlder: more, from: shown.length ? cursorOf(shown[0]) : s.from };
|
||||
}
|
||||
return { ...s, older: fresh.concat(s.older), hasOlder: more };
|
||||
}
|
||||
Reference in New Issue
Block a user