refactor(ui): fold one-consumer workflow files into their consumers; move shared ones out (#1958)

This commit is contained in:
sam committed 2026-11-13 14:40:01 +11:00
1 parent ecf4e6b95a
commit 5b3ae6abde
21 files changed
+187 -246

No files matched your search

+116 -4
View File
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { BotIcon, BrainIcon, CircleAlertIcon, FoldVerticalIcon, ScrollTextIcon, SparklesIcon, TargetIcon } from "@lucide/vue";
import { ArrowUpRightIcon, BotIcon, BrainIcon, CircleAlertIcon, CircleCheckIcon, FlagIcon, FlaskConicalIcon, FoldVerticalIcon, GlobeIcon, ScrollTextIcon, SparklesIcon, SquareTerminalIcon, TargetIcon } from "@lucide/vue";
import { createReusableTemplate } from "@vueuse/core";
import { computed, onUnmounted, ref, watch } from "vue";
@@ -25,8 +25,71 @@ import { keepValue } from "@/lib/keep-unchanged";
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 agent_transcript entry, as the State Store records it. */
interface Entry {
seq: number;
kind: string;
text?: string;
text_bytes?: number;
reasoning?: string;
reasoning_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?: { prompt_tokens?: number; completion_tokens?: number; cached_tokens?: number };
latency_ms?: number;
}
/** The text as recorded, with a note when it was clipped. */
function withClip(text: string | undefined, bytes: number | undefined): string {
if (!bytes) return text ?? "";
return `${text ?? ""}\n… clipped, ${(bytes / 1024).toFixed(1)} KB in full`;
}
/**
* How one tool call is drawn: a shell command as a terminal, the gate as a
* test run, a fetch as a source, finish as the run's own verdict, anything
* else as input then output.
*/
function toolView(tool: Entry) {
let args: Record<string, unknown> = {};
try {
const parsed: unknown = JSON.parse(tool.args ?? "");
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) args = parsed as Record<string, unknown>;
} catch {
// Unparseable arguments draw as the raw text below.
}
const failed = !!tool.error;
const kind = tool.tool === "shell" ? "terminal" : tool.tool === "check" ? "tests" : tool.tool === "web_fetch" ? "source" : tool.tool === "finish" ? "finish" : "tool";
const command = String(args.command ?? "");
const url = String(args.url ?? "");
let host = url;
try {
host = new URL(url).hostname;
} catch {
// Not a URL: the row names it as given.
}
// A plain call is named by its main value, as "read src/main.go" rather
// than its JSON: the first string argument.
const first = Object.values(args).find((v) => typeof v === "string" && v);
const argument = typeof first === "string" ? first.split("\n", 1)[0] : "";
const ran = failed ? errors.workflows.transcript.tool.failedToRun : "Ran";
const title =
kind === "terminal" ? `${ran} ${command.split("\n", 1)[0]}`
: kind === "tests" ? (failed ? errors.workflows.transcript.tool.gateFailed : "Ran the gate")
: kind === "source" ? `${failed ? errors.workflows.transcript.tool.failedToRead : "Read"} ${host}`
: kind === "finish" ? `Finished as ${String(args.status ?? "unknown")}`
: `${ran} ${tool.tool} ${argument}`;
return { args, failed, kind, command, url, title, output: withClip(tool.output, tool.output_bytes) };
}
const [DefineTool, ToolView] = createReusableTemplate<{ tool: Entry; view: ReturnType<typeof toolView> }>();
/** One step's agent conversations for one attempt, oldest first. */
const props = defineProps<{ taskId: number | string; attempt: number; match: (event: TaskEvent) => boolean; running: boolean }>();
@@ -123,6 +186,55 @@ const conversations = computed(() => {
</script>
<template>
<DefineTool v-slot="{ tool, view }">
<TraceCollapsible :default-open="view.failed">
<TraceCollapsibleTrigger>
<TraceLine :status="view.failed ? 'error' : undefined">
<TraceIcon>
<CircleAlertIcon v-if="view.failed" />
<SquareTerminalIcon v-else-if="view.kind === 'terminal'" />
<FlaskConicalIcon v-else-if="view.kind === 'tests'" />
<GlobeIcon v-else-if="view.kind === 'source'" />
<FlagIcon v-else-if="view.kind === 'finish'" />
<CircleCheckIcon v-else />
</TraceIcon>
<TraceTitle :class="view.kind === 'terminal' && 'font-mono'">{{ view.title }}</TraceTitle>
<TraceDescription v-if="tool.latency_ms">{{ duration(tool.latency_ms) }}</TraceDescription>
</TraceLine>
</TraceCollapsibleTrigger>
<TraceCollapsibleContent class="flex flex-col gap-2">
<template v-if="view.kind === 'terminal'">
<CodeBlock size="sm" :variant="view.failed ? 'destructive' : 'default'">
<CodeBlockContent wrap class="max-h-64 font-mono">$ {{ view.command }}
{{ view.output }}{{ tool.error ? `\n${tool.error}` : '' }}</CodeBlockContent>
</CodeBlock>
</template>
<template v-else-if="view.kind === 'finish'">
<p class="whitespace-pre-wrap">{{ String(view.args.summary ?? '') }}</p>
</template>
<template v-else>
<Trace v-if="view.kind === 'source' && view.url">
<a :href="view.url" target="_blank" rel="noreferrer">
<TraceLine>
<TraceIcon><GlobeIcon /></TraceIcon>
<TraceTitle>{{ view.url }}<span class="sr-only"> (opens in a new tab)</span></TraceTitle>
<TraceIcon><ArrowUpRightIcon /></TraceIcon>
</TraceLine>
</a>
</Trace>
<CodeBlock v-if="view.kind === 'tool'" 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">{{ view.output }}</CodeBlockContent>
</CodeBlock>
</template>
</TraceCollapsibleContent>
</TraceCollapsible>
</DefineTool>
<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}`">
@@ -173,7 +285,7 @@ const conversations = computed(() => {
<TraceTitle>{{ row.step.model.error ? errors.workflows.transcript.stepFailed(row.number, 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" />
<ToolView v-for="tool in row.step.tools" :key="tool.seq" :tool="tool" :view="toolView(tool)" />
</Trace>
</MessageContent>
</Message>