feat(webui): draw each transcript entry with its Trace pattern (#1718)
Quality / check (pull_request) Successful in 3m38s

Record the model's reasoning parts. The step run view shows reasoning as a
Thought row, shell calls as a terminal, the gate as a test run, web_fetch as a
source, finish as the verdict, and each fan-out branch as a subagent.
This commit is contained in:
sam committed 2026-11-01 22:09:53 +11:00
1 parent 6f10ecc04f
commit 69a46249cc
5 files changed
+254 -113

No files matched your search

+94 -112
View File
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { CircleAlertIcon, CircleCheckIcon, FoldVerticalIcon, ScrollTextIcon, SparklesIcon, TargetIcon } from "@lucide/vue";
import { BotIcon, BrainIcon, CircleAlertIcon, FoldVerticalIcon, ScrollTextIcon, SparklesIcon, TargetIcon } from "@lucide/vue";
import { createReusableTemplate } from "@vueuse/core";
import { computed, onUnmounted, ref, watch } from "vue";
import { Bubble, BubbleContent } from "@/components/ui/bubble";
@@ -22,34 +23,21 @@ import { api } from "@/lib/api";
import { useLiveResource } from "@/stores/session";
import { duration } from "@/tasks/timeline-event";
import type { TaskEvent } from "@/tasks/task-run";
import TranscriptTool from "./TranscriptTool.vue";
import { withClip, type TranscriptEntry as Entry } from "./transcript";
/** One step's agent conversations for one attempt, oldest first. */
const props = defineProps<{ taskId: number | string; attempt: number; match: (event: TaskEvent) => boolean; running: boolean }>();
interface Usage { prompt_tokens?: number; completion_tokens?: number; cached_tokens?: number }
interface Entry {
seq: number;
kind: string;
text?: string;
text_bytes?: number;
tool_calls?: { id?: string; name: string }[];
call_id?: string;
tool?: string;
args?: string;
args_bytes?: number;
output?: string;
output_bytes?: number;
error?: string;
finish_reason?: string;
usage?: Usage;
latency_ms?: number;
}
interface Step { model: Entry; tools: Entry[] }
type Row =
| { kind: "prompt"; title: string; entry: Entry }
| { kind: "user"; entry: Entry }
| { kind: "compaction"; entry: Entry }
| { kind: "step"; number: number; step: Step };
interface Conversation { key: string; label: string; rows: Row[]; steps: number; tools: number; failed: number }
const [DefineConversation, ConversationView] = createReusableTemplate<{ conversation: Conversation }>();
const events = ref<TaskEvent[]>();
const failed = ref(false);
@@ -76,11 +64,6 @@ watch(() => props.running, (running) => {
useLiveResource("tasks", () => void load(), 1000);
onUnmounted(() => { generation++; clearInterval(timer); });
function withClip(text: string | undefined, bytes: number | undefined): string {
if (!bytes) return text ?? "";
return `${text ?? ""}\n… clipped, ${(bytes / 1024).toFixed(1)} KB in full`;
}
function usage(entry: Entry): string {
const u = entry.usage;
const parts = [];
@@ -91,48 +74,38 @@ function usage(entry: Entry): string {
return parts.join(" · ");
}
// The row names the call by its main value, as "read src/main.go" rather than
// its JSON: the first string argument, else nothing.
function argument(entry: Entry): string {
try {
const args: unknown = JSON.parse(entry.args ?? "");
if (args && typeof args === "object" && !Array.isArray(args)) {
const first = Object.values(args).find((v) => typeof v === "string" && v);
if (typeof first === "string") return first.split("\n", 1)[0] ?? "";
}
} catch {
// Clipped or not JSON.
}
return "";
function plural(n: number, word: string): string {
return `${n} ${word}${n === 1 ? "" : "s"}`;
}
// Tool results sit under the step whose response asked for them.
function rows(entries: Entry[]): Row[] {
const out: Row[] = [];
function conversation(key: string, label: string, entries: Entry[]): Conversation {
const rows: Row[] = [];
const owner = new Map<string, Step>();
let prompted = false;
let steps = 0;
for (const entry of entries) {
if (entry.kind === "system") out.push({ kind: "prompt", title: "System prompt", entry });
if (entry.kind === "system") rows.push({ kind: "prompt", title: "System prompt", entry });
else if (entry.kind === "user") {
out.push(prompted ? { kind: "user", entry } : { kind: "prompt", title: "Mission", entry });
rows.push(prompted ? { kind: "user", entry } : { kind: "prompt", title: "Mission", entry });
prompted = true;
} else if (entry.kind === "compaction") out.push({ kind: "compaction", entry });
} else if (entry.kind === "compaction") rows.push({ kind: "compaction", entry });
else if (entry.kind === "model") {
const step: Step = { model: entry, tools: [] };
for (const call of entry.tool_calls ?? []) if (call.id) owner.set(call.id, step);
out.push({ kind: "step", number: ++steps, step });
rows.push({ kind: "step", number: ++steps, step });
} else if (entry.kind === "tool") {
const step = entry.call_id ? owner.get(entry.call_id) : undefined;
if (step) step.tools.push(entry);
else out.push({ kind: "step", number: ++steps, step: { model: { seq: entry.seq, kind: "model" }, tools: [entry] } });
else rows.push({ kind: "step", number: ++steps, step: { model: { seq: entry.seq, kind: "model" }, tools: [entry] } });
}
}
return out;
const tools = entries.filter((entry) => entry.kind === "tool");
return { key, label, rows, steps, tools: tools.length, failed: tools.filter((tool) => tool.error).length };
}
// A step can hold several agents (parallel branches, retries); each keeps its
// own conversation, numbered from 1.
// Each agent in the step (a fan-out branch, or a retry) keeps its own
// conversation, numbered from 1.
const conversations = computed(() => {
const byAgent = new Map<string, Entry[][]>();
for (const event of (events.value ?? []).filter(props.match)) {
@@ -143,76 +116,85 @@ const conversations = computed(() => {
runs.at(-1)!.push(entry);
byAgent.set(key, runs);
}
return [...byAgent.entries()].flatMap(([label, runs]) => runs.map((entries, i) => ({ key: `${label}#${i}`, label, rows: rows(entries) })));
return [...byAgent.entries()].flatMap(([label, runs]) => runs.map((entries, i) => conversation(`${label}#${i}`, label, entries)));
});
</script>
<template>
<DefineConversation v-slot="{ conversation: c }">
<div class="flex flex-col gap-4">
<template v-for="row in c.rows" :key="`${row.kind}-${row.kind === 'step' ? row.number : row.entry.seq}`">
<Trace v-if="row.kind === 'prompt' || row.kind === 'compaction'">
<TraceCollapsible>
<TraceCollapsibleTrigger>
<TraceLine>
<TraceIcon>
<FoldVerticalIcon v-if="row.kind === 'compaction'" />
<TargetIcon v-else-if="row.title === 'Mission'" />
<ScrollTextIcon v-else />
</TraceIcon>
<TraceTitle>{{ row.kind === 'compaction' ? 'Compacted the history' : row.title }}</TraceTitle>
<TraceDescription v-if="row.kind === 'compaction' && usage(row.entry)">{{ usage(row.entry) }}</TraceDescription>
</TraceLine>
</TraceCollapsibleTrigger>
<TraceCollapsibleContent>
<CodeBlock size="sm">
<CodeBlockContent wrap class="max-h-96">{{ withClip(row.entry.text || row.entry.error, row.entry.text_bytes) }}</CodeBlockContent>
</CodeBlock>
</TraceCollapsibleContent>
</TraceCollapsible>
</Trace>
<Message v-else-if="row.kind === 'user'" align="end">
<MessageContent>
<Bubble align="end" variant="muted">
<BubbleContent class="whitespace-pre-wrap [overflow-wrap:anywhere]">{{ withClip(row.entry.text, row.entry.text_bytes) }}</BubbleContent>
</Bubble>
</MessageContent>
</Message>
<Message v-else>
<MessageContent class="gap-2">
<Trace v-if="row.step.model.reasoning">
<TraceCollapsible>
<TraceCollapsibleTrigger>
<TraceLine>
<TraceIcon><BrainIcon /></TraceIcon>
<TraceTitle>Thought</TraceTitle>
</TraceLine>
</TraceCollapsibleTrigger>
<TraceCollapsibleContent class="whitespace-pre-wrap">{{ withClip(row.step.model.reasoning, row.step.model.reasoning_bytes) }}</TraceCollapsibleContent>
</TraceCollapsible>
</Trace>
<ChatMarkdown v-if="row.step.model.text" :text="withClip(row.step.model.text, row.step.model.text_bytes)" />
<Trace>
<TraceLine :status="row.step.model.error ? 'error' : undefined">
<TraceIcon><CircleAlertIcon v-if="row.step.model.error" /><SparklesIcon v-else /></TraceIcon>
<TraceTitle>{{ row.step.model.error ? `Step ${row.number} failed: ${row.step.model.error}` : `Step ${row.number}` }}</TraceTitle>
<TraceDescription v-if="usage(row.step.model)">{{ usage(row.step.model) }}</TraceDescription>
</TraceLine>
<TranscriptTool v-for="tool in row.step.tools" :key="tool.seq" :tool="tool" />
</Trace>
</MessageContent>
</Message>
</template>
</div>
</DefineConversation>
<p v-if="failed" role="alert" class="text-danger">Could not load the transcript</p>
<Spinner v-else-if="!events" />
<Empty v-else-if="!conversations.length"><EmptyHeader><EmptyTitle>No transcript recorded</EmptyTitle></EmptyHeader></Empty>
<div v-for="conversation in conversations" :key="conversation.key" class="flex flex-col gap-4">
<h4 v-if="conversations.length > 1" class="font-mono text-xs">{{ conversation.label }}</h4>
<template v-for="row in conversation.rows" :key="`${row.kind}-${row.kind === 'step' ? row.number : row.entry.seq}`">
<Trace v-if="row.kind === 'prompt' || row.kind === 'compaction'">
<TraceCollapsible>
<TraceCollapsibleTrigger>
<TraceLine>
<TraceIcon>
<FoldVerticalIcon v-if="row.kind === 'compaction'" />
<TargetIcon v-else-if="row.title === 'Mission'" />
<ScrollTextIcon v-else />
</TraceIcon>
<TraceTitle>{{ row.kind === 'compaction' ? 'Compacted the history' : row.title }}</TraceTitle>
<TraceDescription v-if="row.kind === 'compaction' && usage(row.entry)">{{ usage(row.entry) }}</TraceDescription>
</TraceLine>
</TraceCollapsibleTrigger>
<TraceCollapsibleContent>
<CodeBlock size="sm">
<CodeBlockContent wrap class="max-h-96">{{ withClip(row.entry.text || row.entry.error, row.entry.text_bytes) }}</CodeBlockContent>
</CodeBlock>
</TraceCollapsibleContent>
</TraceCollapsible>
</Trace>
<Message v-else-if="row.kind === 'user'" align="end">
<MessageContent>
<Bubble align="end" variant="muted">
<BubbleContent class="whitespace-pre-wrap [overflow-wrap:anywhere]">{{ withClip(row.entry.text, row.entry.text_bytes) }}</BubbleContent>
</Bubble>
</MessageContent>
</Message>
<Message v-else>
<MessageContent class="gap-2">
<ChatMarkdown v-if="row.step.model.text" :text="withClip(row.step.model.text, row.step.model.text_bytes)" />
<Trace>
<TraceLine :status="row.step.model.error ? 'error' : undefined">
<TraceIcon><CircleAlertIcon v-if="row.step.model.error" /><SparklesIcon v-else /></TraceIcon>
<TraceTitle>{{ row.step.model.error ? `Step ${row.number} failed: ${row.step.model.error}` : `Step ${row.number}` }}</TraceTitle>
<TraceDescription v-if="usage(row.step.model)">{{ usage(row.step.model) }}</TraceDescription>
</TraceLine>
<TraceCollapsible v-for="tool in row.step.tools" :key="tool.seq" :default-open="!!tool.error">
<TraceCollapsibleTrigger>
<TraceLine :status="tool.error ? 'error' : undefined">
<TraceIcon><CircleAlertIcon v-if="tool.error" /><CircleCheckIcon v-else /></TraceIcon>
<TraceTitle>{{ tool.error ? 'Failed to run' : 'Ran' }} <span class="font-mono">{{ tool.tool }}</span> {{ argument(tool) }}</TraceTitle>
<TraceDescription v-if="tool.latency_ms">{{ duration(tool.latency_ms) }}</TraceDescription>
</TraceLine>
</TraceCollapsibleTrigger>
<TraceCollapsibleContent class="flex flex-col gap-2">
<CodeBlock size="sm">
<CodeBlockContent wrap class="max-h-48">{{ withClip(tool.args, tool.args_bytes) }}</CodeBlockContent>
</CodeBlock>
<CodeBlock v-if="tool.error" size="sm" variant="destructive">
<CodeBlockContent wrap class="max-h-64">{{ tool.error }}</CodeBlockContent>
</CodeBlock>
<CodeBlock v-if="tool.output || !tool.error" size="sm">
<CodeBlockContent wrap class="max-h-64">{{ withClip(tool.output, tool.output_bytes) }}</CodeBlockContent>
</CodeBlock>
</TraceCollapsibleContent>
</TraceCollapsible>
</Trace>
</MessageContent>
</Message>
</template>
</div>
<ConversationView v-else-if="conversations.length === 1" :conversation="conversations[0]!" />
<Trace v-else>
<TraceCollapsible v-for="c in conversations" :key="c.key">
<TraceCollapsibleTrigger>
<TraceLine :status="c.failed ? 'error' : undefined">
<TraceIcon><BotIcon /></TraceIcon>
<TraceTitle class="font-mono">{{ c.label }}</TraceTitle>
<TraceDescription>{{ plural(c.steps, 'step') }} · {{ plural(c.tools, 'tool call') }}{{ c.failed ? `, ${c.failed} failed` : '' }}</TraceDescription>
</TraceLine>
</TraceCollapsibleTrigger>
<TraceCollapsibleContent>
<ConversationView :conversation="c" />
</TraceCollapsibleContent>
</TraceCollapsible>
</Trace>
</template>