feat(webui): inspect file context in a live graph sidebar (#6562)

* feat(webui): inspect file context in a live graph sidebar

* refactor(webui): place preview controls in the shared sidebar header

* fix(webui): synchronize npm lockfile for graph dependencies

* fix(webui): preserve compacted context and refine graph inspection

* fix(context): harden provenance, request usage, and drawer lifecycle

* fix(webui): align source skeleton and browser fixtures

* perf(context): reuse source analysis and capture request graphs once

* perf(webui): compact graph history and render graph motion on canvas

* fix(webui): remove redundant context sidebar header

* style(webui): clarify context replay icon

* perf(webui): pace context replay on an adaptive timeline

* feat(webui): briefly reveal labels for new context nodes

* fix(webui): reveal new labels only for loaded context files

* fix(webui): restart graph animation clock after idle

* fix(webui): reveal labels when replay reverses node exit

* refactor(context): project file-use facts without retention tracking

* refactor(context): observe file reads outside agent execution

* fix(webui): animate context sidebar closing

* refactor(context): remove unused graph and usage panel code

* refactor(context): isolate prompt observation from execution metadata

* fix(webui): clarify cache rate and show context token usage

* fix(webui): abbreviate context token counts in thousands

* fix(webui): omit token unit from context usage details

* fix(webui): restore large source preview highlighting and panel elevation

* fix(webui): distinguish modifier scrolling from keyboard focus

* fix(webui): align preview tab and panel corner radii

* fix(webui): attach file tabs to the header divider

* fix(webui): use one action to toggle file preview mode

* fix(webui): use hover hint for context replay

* fix(webui): share composer layout between graph and file sidebars

* fix(webui): align sidebar bottom with composer surface

* fix(webui): restore mobile graph drawing and touch file details

* test(webui): align legacy cache assertions with current label

* perf(context): retain source analysis and bound graph animation work

* style(webui): add light elevation to user messages

* test(webui): await lazy graph scene before replay assertions

* fix(webui): align preview skeleton and browser contracts
This commit is contained in:
chengyongru authored and GitHub committed 2026-11-05 17:09:20 +08:00
1 parent 2b44088413
commit 519ed81132
132 files changed
+4673 -1159

No files matched your search

+59 -8
View File
@@ -1,3 +1,4 @@
import { isContextGraph, isContextInspection } from "@/lib/context-graph";
import { isCompactionPhase, isCompactionReason } from "../../../packages/client-events/notifications";
import type {
ApiServicePayload,
@@ -10,6 +11,7 @@ import type {
ChannelConnectPayload,
ChannelValidationPayload,
ChatSummary,
ContextGraph,
CliAppsPayload,
FilePreviewPayload,
FileReferenceMetadata,
@@ -315,7 +317,7 @@ function isProjectionTraceDetail(value: unknown): boolean {
&& value.traceCount >= 0;
}
function parseThreadProjectionEvent(value: unknown): ThreadProjectionEvent {
function parseThreadProjectionEvent(value: unknown, validatedGraphs: ReadonlySet<unknown> = new Set()): ThreadProjectionEvent {
if (!isRecord(value) || typeof value.event !== "string" || typeof value.chat_id !== "string") {
throw new Error("Invalid WebUI thread event");
}
@@ -383,11 +385,13 @@ function parseThreadProjectionEvent(value: unknown): ThreadProjectionEvent {
if (value.text !== undefined && typeof value.text !== "string") break;
return value as unknown as ThreadProjectionEvent;
case "context_compaction":
if (value.context_snapshot !== undefined && !isContextInspection(value.context_snapshot, (graph): graph is ContextGraph => validatedGraphs.has(graph) || isContextGraph(graph))) break;
if (typeof value.compaction_id !== "string" || !value.compaction_id
|| !isCompactionPhase(value.phase)
|| (value.reason !== undefined && !isCompactionReason(value.reason))) break;
return value as unknown as ThreadProjectionEvent;
case "model_request": {
if (value.context_graph !== undefined && !validatedGraphs.has(value.context_graph) && !isContextGraph(value.context_graph)) break;
const isUsage = (usage: unknown) => isRecord(usage)
&& Object.values(usage).every((count) => typeof count === "number" && Number.isFinite(count) && count >= 0);
if (typeof value.request_id !== "string" || !value.request_id
@@ -395,6 +399,7 @@ function parseThreadProjectionEvent(value: unknown): ThreadProjectionEvent {
|| !Number.isSafeInteger(value.sequence) || Number(value.sequence) < 0
|| !["started", "completed", "failed", "cancelled"].includes(String(value.phase))
|| (value.usage !== undefined && !isUsage(value.usage))
|| (value.request_usage != null && !isUsage(value.request_usage))
|| (value.round_usages !== undefined && (!Array.isArray(value.round_usages) || !value.round_usages.every(isUsage)))
|| (value.context_window_tokens !== undefined && (typeof value.context_window_tokens !== "number"
|| !Number.isFinite(value.context_window_tokens) || value.context_window_tokens < 0))) break;
@@ -413,12 +418,57 @@ export function parseWebuiThreadPayload(value: unknown): WebuiThreadPersistedPay
if (value.projection !== "events" || !Array.isArray(value.events)) {
throw new Error("Invalid WebUI thread events");
}
const events = value.events.map(parseThreadProjectionEvent);
return {
...value,
projection: "events",
events,
} as unknown as WebuiThreadPersistedPayload;
const graphs = new Map<string, ContextGraph>();
if (value.context_graphs !== undefined) {
if (!isRecord(value.context_graphs)) throw new Error("Invalid context graph dictionary");
const table = { nodes: value.context_graph_nodes, edges: value.context_graph_edges };
if (!isContextGraph(table)) throw new Error("Invalid context graph entity table");
const resolveIndex = <T,>(entries: readonly T[], index: unknown): T => {
if (typeof index !== "number" || !Number.isSafeInteger(index) || index < 0 || index >= entries.length) {
throw new Error("Unknown context graph entity reference");
}
return entries[index];
};
for (const [key, descriptor] of Object.entries(value.context_graphs)) {
if (!isRecord(descriptor) || !Array.isArray(descriptor.nodes) || !Array.isArray(descriptor.edges)) {
throw new Error("Invalid context graph dictionary entry");
}
const nodes = descriptor.nodes.map((index: unknown) => resolveIndex(table.nodes, index));
const paths = new Set(nodes.map((node) => node.path));
const edges = descriptor.edges.map((index: unknown) => {
const edge = resolveIndex(table.edges, index);
if (!paths.has(edge.source) || !paths.has(edge.target)) throw new Error("Invalid context graph edge reference");
return edge;
});
graphs.set(key, { nodes, edges });
}
}
const validatedGraphs = new Set(graphs.values());
const resolveGraph = (key: unknown): ContextGraph => {
const graph = typeof key === "string" ? graphs.get(key) : undefined;
if (!graph) throw new Error("Unknown context graph reference");
return graph;
};
const events = value.events.map((raw) => {
if (!isRecord(raw)) return parseThreadProjectionEvent(raw);
const event = { ...raw };
if (event.context_graph_ref !== undefined) {
if (event.context_graph !== undefined) throw new Error("Ambiguous context graph reference");
event.context_graph = resolveGraph(event.context_graph_ref);
delete event.context_graph_ref;
}
if (isRecord(event.context_snapshot) && event.context_snapshot.graph_ref !== undefined) {
if (event.context_snapshot.graph !== undefined) throw new Error("Ambiguous context graph reference");
const { graph_ref, ...snapshot } = event.context_snapshot;
event.context_snapshot = { ...snapshot, graph: resolveGraph(graph_ref) };
}
return parseThreadProjectionEvent(event, validatedGraphs);
});
const body: Record<string, unknown> = { ...value, projection: "events", events };
delete body.context_graphs;
delete body.context_graph_nodes;
delete body.context_graph_edges;
return body as unknown as WebuiThreadPersistedPayload;
}
function parseWebuiThreadTraceDetailPayload(value: unknown): WebuiThreadTraceDetailPayload {
@@ -432,7 +482,7 @@ function parseWebuiThreadTraceDetailPayload(value: unknown): WebuiThreadTraceDet
}
return {
message_id: value.message_id,
events: value.events.map(parseThreadProjectionEvent),
events: value.events.map((event) => parseThreadProjectionEvent(event)),
};
}
@@ -450,6 +500,7 @@ export async function fetchWebuiThread(
if (options?.before) params.set("before", options.before);
if (options?.after) params.set("after", options.after);
params.set("include_model_requests", "1");
params.set("context_graph_encoding", "references-v1");
const query = params.toString();
const suffix = query ? `?${query}` : "";
const url = `${resolvedBase}/api/sessions/${encodeURIComponent(key)}/webui-thread${suffix}`;