feat(app): 대화 screen to read what people said, Jarvis's answers and how each answer was made

The management app reads the worker's history store (read only) and shows
people's words, Jarvis's answers and the answer traces in time order, with
filters for kind, place, person, channel, day and text, live follow, older
items on demand and expandable traces (records given, tools offered, plan,
model thinking, tool calls and results).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-16 03:08:38 +09:00
parent a20ebe4eae
commit 46f71e7f03
15 changed files with 724 additions and 4 deletions

View File

@@ -402,6 +402,136 @@ function activityScreen() {
h("div", { class: "field" }, h("button", { class: "btn", onclick: load }, "새로 고침")), list));
}
// ---- conversations ------------------------------------------------------------------------------
const VIA = { voice: "음성", chat: "채팅", task: "정기 작업" };
const SKIPPED = { not_allowed: "허용되지 않은 도구라 부르지 않음", duplicate: "같은 호출을 되풀이해 부르지 않음" };
const p2 = (n) => String(n).padStart(2, "0");
const dayOf = (ts) => { const d = new Date(ts * 1000); return `${d.getFullYear()}-${p2(d.getMonth() + 1)}-${p2(d.getDate())}`; };
const timeOf = (ts) => { const d = new Date(ts * 1000); return `${p2(d.getHours())}:${p2(d.getMinutes())}:${p2(d.getSeconds())}`; };
const pre = (text) => h("pre", { class: "pre" }, text);
/** One step of how an answer was made (history.spec.md, "Traces"). */
function traceStep(s) {
if (s.kind === "records") {
const lines = (title, xs) => xs.length ? h("details", {}, h("summary", { class: "small" }, `${title} ${xs.length}줄`), pre(xs.join("\n"))) : null;
return h("div", { class: "step-row" }, h("div", { class: "k" }, "참고한 기록"),
h("div", {}, (s.recent || []).length + (s.matches || []).length ? null : h("span", { class: "muted" }, "없음"),
lines("최근 대화", s.recent || []), lines("관련 기록", s.matches || []),
s.notes ? h("div", { class: "small muted" }, `사람별 지침 ${s.notes}개`) : null));
}
if (s.kind === "tools") return h("div", { class: "step-row" }, h("div", { class: "k" }, "쓸 수 있게 고른 도구"),
h("div", { class: "row" }, (s.names || []).length ? s.names.map((n) => h("span", { class: "badge" }, n)) : h("span", { class: "muted" }, "없음")));
if (s.kind === "plan") return h("div", { class: "step-row" }, h("div", { class: "k" }, "계획"), h("ol", { class: "plan" }, (s.steps || []).map((x) => h("li", {}, x))));
if (s.kind === "think") return h("div", { class: "step-row" }, h("div", { class: "k" }, "모델 생각"), pre(s.text || ""));
if (s.kind === "tool") {
const state = s.skipped ? ["건너뜀", "warn"] : s.ok ? ["성공", "ok"] : ["실패", "bad"];
return h("div", { class: "step-row" }, h("div", { class: "k" }, "도구 호출"),
h("div", {}, h("div", { class: "row" }, h("b", {}, s.name), h("span", { class: "badge " + state[1] }, state[0])),
Object.keys(s.args || {}).length ? pre(JSON.stringify(s.args, null, 2)) : null,
s.skipped ? h("div", { class: "small muted" }, SKIPPED[s.skipped] || s.skipped) : null,
s.result ? h("details", {}, h("summary", { class: "small" }, "결과"), pre(s.result)) : null));
}
return h("div", { class: "step-row" }, h("div", { class: "k" }, s.kind), pre(JSON.stringify(s, null, 2)));
}
/** The 대화 screen (admin.spec.md, "Conversations"): what people said, what Jarvis answered, how. */
function conversationScreen() {
const chip = (label, on = true) => { const c = h("input", { type: "checkbox", checked: on }); return [c, h("label", { class: "chip" }, c, label)]; };
const [said, saidChip] = chip("사람 말"), [answered, answeredChip] = chip("자비스 말"), [thought, thoughtChip] = chip("자비스 생각");
const via = h("select", {}, h("option", { value: "" }, "모든 곳"), Object.entries(VIA).map(([v, t]) => h("option", { value: v }, t)));
const person = h("select", {}, h("option", { value: "" }, "모든 사람"));
const channel = h("select", {}, h("option", { value: "" }, "모든 채널"));
const day = h("input", { type: "date" });
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
let expandAll = false, limit = 200, sig = null;
const box = h("div", { class: "talk" });
const summary = h("div", { class: "small muted" });
const more = h("button", { class: "btn", hidden: true, onclick: () => { limit += 200; load(true); } }, "이전 기록 더 보기");
const fill = (sel, list, label) => {
const key = JSON.stringify(list);
if (sel.dataset.list === key) return; // an open picker is not rebuilt under the user
sel.dataset.list = key;
const keep = sel.value;
sel.replaceChildren(sel.firstChild, ...list.map((x) => h("option", { value: x.id }, label(x))));
sel.value = list.some((x) => x.id === keep) ? keep : "";
};
const channelLabel = (c) => c.name ? `${c.name} (${VIA[c.via]})` : `${VIA[c.via]} 채널 ${c.id}`;
const channelName = (id) => { const c = (load.channels || []).find((x) => x.id === id); return c ? channelLabel(c) : id || ""; };
const copy = (text) => async () => { try { await navigator.clipboard.writeText(text); toast("복사했습니다"); } catch (e) { fail(e); } };
function item(i) {
const where = h("span", { class: "small muted" }, timeOf(i.at), " · ", VIA[i.via] || i.via, i.channel ? " · " + channelName(i.channel) : "");
if (i.type === "thought") {
const tools = (i.steps || []).filter((s) => s.kind === "tool" && !s.skipped).length;
const d = h("details", { class: "msg thought", open: expandAll || open.has(i.key) },
h("summary", {}, h("span", { class: "who" }, "자비스 생각"), " ",
h("span", { class: "small muted" }, `${i.who.name || i.who.id}의 말에 답하며`, tools ? ` · 도구 ${tools}번` : "",
` · ${(i.ms / 1000).toFixed(1)}초`, i.answer ? "" : " · 답 없음"), " ", where),
h("div", { class: "steps" },
h("div", { class: "step-row" }, h("div", { class: "k" }, "받은 말"), h("div", {}, i.question)),
(i.steps || []).map(traceStep),
h("div", { class: "step-row" }, h("div", { class: "k" }, "답"), i.answer ? h("div", {}, i.answer) : h("span", { class: "badge bad" }, "답하지 못함"))));
d.addEventListener("toggle", () => (d.open ? open.add(i.key) : open.delete(i.key)));
return d;
}
const mine = i.type === "answered";
const who = mine ? (i.to ? `자비스 → ${i.to.name || i.to.id}` : "자비스") : (i.who.name || i.who.id);
return h("div", { class: "msg " + (mine ? "answered" : "said") },
h("div", { class: "row" }, h("span", { class: "who" }, who), where,
h("button", { class: "linkbtn small", title: "글 복사", onclick: copy(i.text) }, "복사")),
h("div", { class: "text" }, i.text));
}
async function load(keepTop = false) {
try {
const since = day.value ? new Date(day.value + "T00:00:00").getTime() / 1000 : null;
const r = await api("history_query", { said: said.checked, answered: answered.checked, thought: thought.checked,
via: via.value || null, person: person.value || null, channel: channel.value || null, find: find.value || null,
since, until: since == null ? null : since + 86400, limit });
load.channels = r.channels;
fill(person, r.people, (p) => `${p.name || p.id}`);
fill(channel, r.channels, channelLabel);
const s = JSON.stringify([r.items.map((i) => i.key + ":" + (i.text || i.answer || "").length), expandAll, r.more]);
if (s === sig) return;
sig = s;
const stick = box.scrollTop + box.clientHeight >= box.scrollHeight - 30, fromBottom = box.scrollHeight - box.scrollTop;
const kids = [];
let lastDay = null;
for (const i of r.items) {
const d = dayOf(i.at);
if (d !== lastDay) { kids.push(h("div", { class: "day" }, d)); lastDay = d; }
kids.push(item(i));
}
box.replaceChildren(...(kids.length ? kids : [h("div", { class: "muted" },
r.missing ? "아직 대화 기록이 없습니다. 서비스를 켜고 자비스와 이야기하면 여기에 나옵니다." : "조건에 맞는 기록이 없습니다.")]));
more.hidden = !r.more;
const n = (t) => r.items.filter((i) => i.type === t).length;
summary.textContent = `사람 말 ${n("said")} · 자비스 말 ${n("answered")} · 생각 ${n("thought")}` + (r.more ? ` (최근 ${limit}개까지)` : "");
if (keepTop) box.scrollTop = box.scrollHeight - fromBottom;
else if (stick || !load.done) box.scrollTop = box.scrollHeight;
load.done = true;
} catch (e) { fail(e); }
}
const reload = () => { limit = 200; sig = null; load.done = 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", {}, "대화"),
h("div", { class: "card filters" },
h("div", { class: "row" }, saidChip, answeredChip, thoughtChip),
h("div", { class: "row" }, via, person, channel, day, find),
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: "row", style: "justify-content:center" }, more), box);
load();
return { view, tick: () => live.checked && load() };
}
async function settingsScreen(screen, title, extra) {
const [all, view] = await Promise.all([fields(), api("settings_view")]);
const list = all.filter((f) => f.screen === screen);
@@ -719,6 +849,7 @@ async function show(name) {
if (name === "dashboard") { screen.replaceChildren(); await refresh(); ticker = setInterval(refresh, 1000); return; }
if (name === "logs") { const l = logsScreen(); screen.replaceChildren(l.view); ticker = setInterval(l.tick, 1000); return; }
if (name === "activity") { screen.replaceChildren(activityScreen()); return; }
if (name === "conversations") { const c = conversationScreen(); screen.replaceChildren(c.view); ticker = setInterval(c.tick, 3000); return; }
if (name === "notes") { screen.replaceChildren(notesScreen()); return; }
if (name === "update") { const u = updateScreen(); screen.replaceChildren(u.view); ticker = setInterval(u.tick, 1000); return; }
const titles = { bot: "봇", channels: "채널·호출", chat: "채팅 채널", memory: "대화 기억", model: "모델", features: "기능",