World's first open-source enterprise world model.
Rust agent-memorybitemporalgraphragknowledge-baseknowledge-graphllmontologypgvectorpostgresqlragrustself-hostedsemantic-searchtemporal-knowledge-graphworld-model
The review page opens on an overview (#382)
WaylandYang11ba60aa8316
diff --git a/web/src/api.ts b/web/src/api.tsindex ede67710..4119b141 100644--- a/web/src/api.ts+++ b/web/src/api.ts@@ -673,6 +673,42 @@ export interface ReviewHistoryEvent {created_at: string;}+/** 一档队列里等着的:多少条、最老的一条从什么时候起等(空队列是 null) */+export interface QueueWait {+ count: number;+ oldest_at: string | null;+}++/** 一个时间窗口里的决定 */+export interface DecidedWindow {+ total: number;+ /** 其中台账上没有 actor 的——AI 裁决器自己办的 */+ automatic: number;+ by_action: { action: string; count: number }[];+ /** actor_id 为 null 的一行是裁决器;label 是台账里的身份快照 */+ by_actor: { actor_id: string | null; label: string | null; count: number }[];+}++/** 审核台总览(#377):等着办的、办过的、库的成色。与左栏计数同一套口径 */+export interface ReviewSummary {+ waiting: Record<+ "pending" | "duplicates" | "conflicts" | "unconfirmed" | "lowconf" | "violations" | "defects",+ QueueWait+ >;+ decided: {+ last_7d: DecidedWindow;+ last_30d: DecidedWindow;+ /** 近 14 天,一天一条,含零 */+ daily: { day: string; count: number }[];+ };+ health: {+ facts: number;+ low_confidence: number;+ unconfirmed: number;+ contested: number;+ };+}+export interface MergeLog {id: string;source_name: string;@@ -2010,6 +2046,8 @@ export const api = {request<{ ok: boolean }>(`/api/v1/kbs/${kbId}/merges/${mergeId}/revert`, {method: "POST",}),+ reviewSummary: (kbId: string) =>+ request<ReviewSummary>(`/api/v1/kbs/${kbId}/review/summary`),reviewHistory: (kbId: string, page: number, per = 20) =>request<{ events: ReviewHistoryEvent[]; total: number }>(`/api/v1/kbs/${kbId}/review/history?page=${page}&per=${per}`,diff --git a/web/src/i18n/en.ts b/web/src/i18n/en.tsindex ec96b719..116d2560 100644--- a/web/src/i18n/en.ts+++ b/web/src/i18n/en.ts@@ -1447,11 +1447,11 @@ export const en = {review: {title: "Review",hint: "Duplicates & low-confidence facts",- tabQueue: "Queue",tabHistory: "History",empty: "Nothing to review — the graph is clean.",historyEmpty: "No merges yet.",// 左栏分类导航+ railOverview: "Overview",railPending: "Awaiting your nod",railDuplicates: "Duplicates",railConflicts: "Conflicts",@@ -1463,6 +1463,28 @@ export const en = {railDecisions: "Decisions",railMerges: "Merges",categoryEmpty: "This queue is clear.",+ // 总览(#377)+ overviewTitle: "Overview",+ overviewHint:+ "What the base needs from you: how much is waiting and for how long, what has been decided, and how much of the base is still provisional.",+ overviewWaiting: "Waiting",+ overviewAllClear: "Nothing is waiting — the base is clean.",+ overviewOldest: (days: number) =>+ days === 0 ? "oldest since today" : days === 1 ? "oldest since yesterday" : `oldest waiting ${days} days`,+ overviewOpen: "Review these",+ overviewDecided: "Decided",+ overviewLast7: "Last 7 days",+ overviewLast30: "Last 30 days",+ overviewAutomatic: (n: number) =>+ n === 1 ? "1 by the adjudicator" : `${n} by the adjudicator`,+ overviewDaily: "Decisions per day, last 14 days",+ overviewByAction: "By kind",+ overviewByActor: "Who decided",+ overviewNoDecisions: "No decisions in the last 30 days.",+ overviewHealth: "Base health",+ overviewFacts: (n: number) =>+ n === 1 ? "1 fact currently held. Of it:" : `${n} facts currently held. Of them:`,+ overviewContested: "Contested",// 决策台账decisionsTitle: "Decisions",decisionsHint:@@ -1482,6 +1504,7 @@ export const en = {"conflict.reject_new": "Rejected new","merge.revert": "Reverted merge","merge.manual": "Merged manually",+ "fact.time_corrected": "Time corrected",} as Record<string, string>,/** 升格给人裁决的原因。服务端存 code(可选 |detail),措辞在这里 */escalated: {diff --git a/web/src/i18n/zh.ts b/web/src/i18n/zh.tsindex 2be852e0..ba074cae 100644--- a/web/src/i18n/zh.ts+++ b/web/src/i18n/zh.ts@@ -1266,10 +1266,10 @@ export const zh: Strings = {review: {title: "审阅",hint: "重复项与低置信度事实",- tabQueue: "队列",tabHistory: "历史",empty: "没有待审阅的——图谱是干净的。",historyEmpty: "还没有合并记录。",+ railOverview: "总览",railPending: "等你点头",railDuplicates: "重复项",railConflicts: "冲突",@@ -1281,6 +1281,23 @@ export const zh: Strings = {railDecisions: "决定",railMerges: "合并",categoryEmpty: "这个队列是空的。",+ overviewTitle: "总览",+ overviewHint: "这个库要你做什么:有多少在等、等了多久、办过什么、还有多少是暂定的。",+ overviewWaiting: "等着办的",+ overviewAllClear: "没有在等的——库是干净的。",+ overviewOldest: (days) => (days === 0 ? "最老的今天进来" : days === 1 ? "最老的昨天进来" : `最老的等了 ${days} 天`),+ overviewOpen: "去处理",+ overviewDecided: "办过的",+ overviewLast7: "近 7 天",+ overviewLast30: "近 30 天",+ overviewAutomatic: (n) => `其中裁决器自裁 ${n} 条`,+ overviewDaily: "近 14 天每天的决定",+ overviewByAction: "按类型",+ overviewByActor: "谁办的",+ overviewNoDecisions: "近 30 天没有决定。",+ overviewHealth: "库的成色",+ overviewFacts: (n) => `现在持有 ${n} 条事实。其中:`,+ overviewContested: "有争议",decisionsTitle: "决定",decisionsHint:"每一次审阅决定、由谁在何时做出——快照在决定当时留存,即使底下的事实已经不在了也保留。",@@ -1299,6 +1316,7 @@ export const zh: Strings = {"conflict.reject_new": "驳回新的","merge.revert": "撤销合并","merge.manual": "手动合并",+ "fact.time_corrected": "改了时间",},escalated: {escalate_no_model: "没有对话模型——裁决跑不起来",diff --git a/web/src/pages/Review.tsx b/web/src/pages/Review.tsxindex de11b932..d6d38b02 100644--- a/web/src/pages/Review.tsx+++ b/web/src/pages/Review.tsx@@ -1,4 +1,5 @@-import { useEffect, useState } from "react";+import { useState } from "react";+import { LayoutDashboard } from "lucide-react";import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";import { useNavigate, useSearch } from "@tanstack/react-router";import {@@ -16,6 +17,7 @@ import {type ViolationResolution,} from "../api";import { PendingFactRow, useCanDecide } from "./PendingFacts";+import { ReviewOverview } from "./ReviewOverview";import { S } from "../i18n";import { useKb, useKbId } from "../kb";import {@@ -742,6 +744,9 @@ function ContradictionRow({/* ---------- 页面:左栏分类 + 单类内容区 ---------- */type Sel =+ // 总览(#377):落地页。回答的是「有多少在等、等了多久、队列在消还是在涨」,+ // 不是任何一档队列+ | "overview"// 记忆抽出、等人点头的事实(0015)。排第一:它是人自己说的话,// 而且在这一档里的东西**还没进图**——别处每一档审的都是已经在图上的| "pending"@@ -778,7 +783,10 @@ const QUEUE_ORDER: Sel[] = ["violations","defects",];-const PAGE_SIZE: Record<Sel, number> = {+/** 有内容区、要翻页的那些档——总览不翻页 */+type Paged = Exclude<Sel, "overview">;++const PAGE_SIZE: Record<Paged, number> = {pending: FACT_PAGE,duplicates: DUP_PAGE,conflicts: CONFLICT_PAGE,@@ -827,8 +835,8 @@ export function Review() {api.review(kb!.id,queueSel,- PAGE_SIZE[queueSel as Sel],- page * PAGE_SIZE[queueSel as Sel],+ PAGE_SIZE[queueSel as Paged],+ page * PAGE_SIZE[queueSel as Paged],),enabled: !!kb,// 翻页时别把上一页闪成空白——计数与骨架都还在,只有条目在换@@ -841,8 +849,16 @@ export function Review() {enabled: !!kb && sel === "decisions",});+ // 总览:只在落在它上面时拉;每一次决定之后连它一起作废——它数的正是这些+ const summary = useQuery({+ queryKey: ["reviewSummary", kb?.id],+ queryFn: () => api.reviewSummary(kb!.id),+ enabled: !!kb && (sel ?? "overview") === "overview",+ });+const invalidate = () => {queryClient.invalidateQueries({ queryKey: ["review", kb?.id] });+ queryClient.invalidateQueries({ queryKey: ["reviewSummary", kb?.id] });queryClient.invalidateQueries({ queryKey: ["reviewHistory", kb?.id] });queryClient.invalidateQueries({ queryKey: ["graph"] });};@@ -938,6 +954,7 @@ export function Review() {// mappings 不是本页的一档(审批在「数据映射」页),但计数照收:// 收件箱该说「有几条等你」const counts: Record<Sel | "mappings", number> = {+ overview: 0,pending: c?.pending ?? 0,duplicates: c?.duplicates ?? 0,conflicts: c?.conflicts ?? 0,@@ -961,22 +978,18 @@ export function Review() {const asMerges = () => rows as MergeLog[];const queueEmpty = QUEUE_ORDER.every((k) => counts[k] === 0);- // 首批数据到达:定位到第一个非空队列(全空落在 duplicates 显示"干净"文案)- useEffect(() => {- if (sel === null && c)- setSel(QUEUE_ORDER.find((k) => counts[k] > 0) ?? "duplicates");- // eslint-disable-next-line react-hooks/exhaustive-deps- }, [c]);-+ // 没带 ?queue= 进来就落在总览上——从前是「第一个非空队列」,那等于替人+ // 决定先看哪一档;现在先给全貌,哪一档先办由人挑const select = (s: Sel) => {setSel(s);setPage(0);};- const active = sel ?? "duplicates";+ const active: Sel = sel ?? "overview";const isQueueSel = QUEUE_ORDER.includes(active);const SECTION: Record<Sel, { title: string; hint: string | null }> = {+ overview: { title: S.review.overviewTitle, hint: S.review.overviewHint },pending: { title: S.review.pending, hint: S.review.pendingHint },duplicates: { title: S.review.duplicates, hint: S.review.duplicatesHint },conflicts: { title: S.review.conflicts, hint: S.review.conflictsHint },@@ -1004,8 +1017,18 @@ export function Review() {的出口——没有滚动它会被裁掉且够不着。`mt-auto` 只在有富余空间时把它压到底,两者要一起给 */}<aside className={`${RAIL_CLS} flex flex-col overflow-y-auto u-scroll`}>- <RailHeader label={S.review.tabQueue} />- <div className="px-2 space-y-1">+ {/* 总览在最上面,七档队列直接排在它下面,不另起标题——「队列」这个词+ 说的是它们是什么,而人要的是它们有多少 */}+ <div className="px-2 pt-3 space-y-1">+ <RailItem+ active={active === "overview"}+ icon={<LayoutDashboard size={14} />}+ onClick={() => select("overview")}+ >+ {S.review.railOverview}+ </RailItem>+ </div>+ <div className="px-2 pt-2 space-y-1"><RailItemactive={active === "pending"}count={counts.pending}@@ -1126,6 +1149,17 @@ export function Review() {</div>)}+ {active === "overview" &&+ (summary.isPending ? (+ <p className="text-body text-ink-3">{S.nav.loading}</p>+ ) : summary.isError ? (+ <p className="text-body text-danger">+ {(summary.error as Error).message}+ </p>+ ) : summary.data ? (+ <ReviewOverview summary={summary.data} onPick={select} />+ ) : null)}+{active === "duplicates" && counts.duplicates > 0 && (<div className="space-y-3">{asDuplicates().map((item) => (@@ -1345,8 +1379,8 @@ export function Review() {</div>))}- {/* 单一分页:queue/merges 走客户端切片,decisions 服务端分页 */}- {active !== "decisions" && (+ {/* 单一分页:queue/merges 走客户端切片,decisions 服务端分页;总览没有页 */}+ {active !== "decisions" && active !== "overview" && (<Pagertotal={counts[active]}pageSize={PAGE_SIZE[active]}diff --git a/web/src/pages/ReviewOverview.tsx b/web/src/pages/ReviewOverview.tsxnew file mode 100644index 00000000..62ed4812--- /dev/null+++ b/web/src/pages/ReviewOverview.tsx@@ -0,0 +1,207 @@+// 审核台的落地页(#377):一个审核者进来时的三个问题——有多少在等、等了多久、+// 队列在消还是在涨。数据全来自 GET /review/summary,这里只画,不算:七档的数+// 与左栏是同一套口径(服务端共用 WHERE),页面上不再各自数一遍。+import type { ReviewSummary } from "../api";+import { S } from "../i18n";+import { Chip, LinkButton } from "../ui";++/** 总览里能点进去的七档 */+export type WaitingQueue = keyof ReviewSummary["waiting"];++/** 七档队列在总览里的顺序与左栏一致 */+const WAITING: { key: WaitingQueue; label: string }[] = [+ { key: "pending", label: S.review.railPending },+ { key: "duplicates", label: S.review.railDuplicates },+ { key: "conflicts", label: S.review.railConflicts },+ { key: "unconfirmed", label: S.review.railUnconfirmed },+ { key: "lowconf", label: S.review.railLowConfidence },+ { key: "violations", label: S.review.railViolations },+ { key: "defects", label: S.review.railDefects },+];++/** 从某个时刻到现在整几天;不满一天算 0 */+function daysSince(iso: string): number {+ return Math.max(0, Math.floor((Date.now() - new Date(iso).getTime()) / 86_400_000));+}++function SectionHead({ children }: { children: string }) {+ return (+ <h3 className="mb-3 text-fine font-medium uppercase tracking-[0.08em] text-ink-3">+ {children}+ </h3>+ );+}++/** 一格统计:大数在上,说明在下。卡片本身不是控件——想进那一档,点下面的+ * 句子;数字只是数字 */+function Stat({+ value,+ label,+ note,+ action,+}: {+ value: number | string;+ label: string;+ note?: string | null;+ action?: { label: string; onClick: () => void };+}) {+ return (+ <div className="glass flex flex-col gap-1 rounded-xl p-4">+ <div className="u-num text-display text-ink">{value}</div>+ <div className="text-body text-ink-2">{label}</div>+ {note && <div className="text-fine text-ink-3">{note}</div>}+ {action && (+ <div className="mt-2">+ <LinkButton onClick={action.onClick}>{action.label}</LinkButton>+ </div>+ )}+ </div>+ );+}++/** 近 14 天每天一根柱。**等距、含零**:服务端已把没有决定的天补成 0,这里+ * 不再插值。高度按这 14 天里的最大值归一,最矮留 2px 当基线,免得全零+ * 时什么都看不见 */+function DailyBars({ days }: { days: ReviewSummary["decided"]["daily"] }) {+ const max = Math.max(1, ...days.map((d) => d.count));+ return (+ <div>+ <div className="flex h-16 items-end gap-1">+ {days.map((d) => (+ <div+ key={d.day}+ className="flex-1 rounded-none bg-accent"+ style={{+ height: `${Math.max(2, Math.round((d.count / max) * 64))}px`,+ opacity: d.count === 0 ? 0.25 : 1,+ }}+ title={`${d.day} · ${d.count}`}+ />+ ))}+ </div>+ <div className="mt-1 flex justify-between text-fine text-ink-3">+ <span>{days[0]?.day}</span>+ <span>{days[days.length - 1]?.day}</span>+ </div>+ </div>+ );+}++export function ReviewOverview({+ summary,+ onPick,+}: {+ summary: ReviewSummary;+ /** 点某一档的「去处理」:落到左栏那一档 */+ onPick: (queue: WaitingQueue) => void;+}) {+ const { waiting, decided, health } = summary;+ const waitingTotal = WAITING.reduce((n, w) => n + waiting[w.key].count, 0);+ const share = (n: number) =>+ health.facts === 0 ? "—" : `${Math.round((n / health.facts) * 1000) / 10}%`;++ return (+ <div className="space-y-8">+ {/* 等着办的 */}+ <section>+ <SectionHead>{S.review.overviewWaiting}</SectionHead>+ {waitingTotal === 0 ? (+ <div className="glass rounded-xl p-8 text-center text-body text-ink-3">+ {S.review.overviewAllClear}+ </div>+ ) : (+ <div className="grid grid-cols-2 gap-3 md:grid-cols-3 lg:grid-cols-4">+ {WAITING.filter((w) => waiting[w.key].count > 0).map((w) => {+ const q = waiting[w.key];+ return (+ <Stat+ key={w.key}+ value={q.count}+ label={w.label}+ note={q.oldest_at ? S.review.overviewOldest(daysSince(q.oldest_at)) : null}+ action={{ label: S.review.overviewOpen, onClick: () => onPick(w.key) }}+ />+ );+ })}+ </div>+ )}+ </section>++ {/* 办过的 */}+ <section>+ <SectionHead>{S.review.overviewDecided}</SectionHead>+ <div className="grid grid-cols-2 gap-3">+ <Stat+ value={decided.last_7d.total}+ label={S.review.overviewLast7}+ note={S.review.overviewAutomatic(decided.last_7d.automatic)}+ />+ <Stat+ value={decided.last_30d.total}+ label={S.review.overviewLast30}+ note={S.review.overviewAutomatic(decided.last_30d.automatic)}+ />+ </div>+ <div className="glass mt-3 rounded-xl p-4">+ <div className="mb-3 text-fine text-ink-3">{S.review.overviewDaily}</div>+ <DailyBars days={decided.daily} />+ </div>+ {decided.last_30d.total === 0 ? (+ <p className="mt-3 text-small text-ink-3">{S.review.overviewNoDecisions}</p>+ ) : (+ <div className="mt-3 grid gap-3 md:grid-cols-2">+ <div className="glass rounded-xl p-4">+ <div className="mb-2 text-fine text-ink-3">{S.review.overviewByAction}</div>+ <div className="flex flex-wrap gap-2">+ {decided.last_30d.by_action.map((a) => (+ <Chip key={a.action}>+ {S.review.decisionActions[a.action] ?? a.action} · {a.count}+ </Chip>+ ))}+ </div>+ </div>+ <div className="glass rounded-xl p-4">+ <div className="mb-2 text-fine text-ink-3">{S.review.overviewByActor}</div>+ <div className="space-y-1">+ {decided.last_30d.by_actor.map((a) => (+ <div+ key={a.actor_id ?? "auto"}+ className="flex items-center justify-between text-body"+ >+ <span className="truncate text-ink-2">+ {a.actor_id === null ? S.review.aiActor : (a.label ?? a.actor_id)}+ </span>+ <span className="u-num text-ink-3">{a.count}</span>+ </div>+ ))}+ </div>+ </div>+ </div>+ )}+ </section>++ {/* 库的成色 */}+ <section>+ <SectionHead>{S.review.overviewHealth}</SectionHead>+ <p className="mb-3 text-small text-ink-3">{S.review.overviewFacts(health.facts)}</p>+ <div className="grid grid-cols-3 gap-3">+ <Stat+ value={health.low_confidence}+ label={S.review.railLowConfidence}+ note={share(health.low_confidence)}+ />+ <Stat+ value={health.unconfirmed}+ label={S.review.railUnconfirmed}+ note={share(health.unconfirmed)}+ />+ <Stat+ value={health.contested}+ label={S.review.overviewContested}+ note={share(health.contested)}+ />+ </div>+ </section>+ </div>+ );+}