2026-08-15 18:37:30 +02:00
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
|
|
2026-08-15 20:52:11 +02:00
|
|
|
import type { Metadata } from "next";
|
2026-08-16 00:32:30 +02:00
|
|
|
import Link from "next/link";
|
2026-08-15 18:37:30 +02:00
|
|
|
import { eq } from "drizzle-orm";
|
|
|
|
|
import { notFound } from "next/navigation";
|
2026-08-16 00:32:30 +02:00
|
|
|
import { RotateCw } from "lucide-react";
|
2026-08-15 18:37:30 +02:00
|
|
|
import { getDb } from "@/lib/db/client";
|
|
|
|
|
import { runs } from "@/lib/db/schema";
|
2026-08-16 00:11:27 +02:00
|
|
|
import { getScript } from "@/lib/config/load";
|
2026-08-16 00:02:57 +02:00
|
|
|
import { readLogTail } from "@/lib/runner/log-file";
|
2026-08-15 18:37:30 +02:00
|
|
|
import { RunTerminal } from "@/components/runs/run-terminal";
|
2026-08-16 00:32:30 +02:00
|
|
|
import { buttonVariants } from "@/components/ui/button";
|
|
|
|
|
import {
|
|
|
|
|
Card,
|
|
|
|
|
CardAction,
|
|
|
|
|
CardContent,
|
|
|
|
|
CardHeader,
|
|
|
|
|
CardTitle,
|
|
|
|
|
} from "@/components/ui/card";
|
2026-08-15 18:37:30 +02:00
|
|
|
|
2026-08-15 20:52:11 +02:00
|
|
|
interface RunDetailPageProps {
|
|
|
|
|
params: Promise<{ runId: string }>;
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-16 00:11:27 +02:00
|
|
|
function formatVariableValue(value: unknown): string {
|
|
|
|
|
if (value === undefined || value === null || value === "") return "—";
|
|
|
|
|
if (Array.isArray(value)) return value.length ? value.join(", ") : "—";
|
|
|
|
|
if (typeof value === "boolean") return value ? "true" : "false";
|
|
|
|
|
return String(value);
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-15 20:52:11 +02:00
|
|
|
export async function generateMetadata({
|
|
|
|
|
params,
|
|
|
|
|
}: RunDetailPageProps): Promise<Metadata> {
|
|
|
|
|
const { runId } = await params;
|
|
|
|
|
const run = getDb()
|
|
|
|
|
.select({ scriptName: runs.scriptName })
|
|
|
|
|
.from(runs)
|
|
|
|
|
.where(eq(runs.id, runId))
|
|
|
|
|
.get();
|
|
|
|
|
return { title: run ? `${run.scriptName} run` : "Run not found" };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default async function RunDetailPage({ params }: RunDetailPageProps) {
|
2026-08-15 18:37:30 +02:00
|
|
|
const { runId } = await params;
|
|
|
|
|
const db = getDb();
|
|
|
|
|
const run = db.select().from(runs).where(eq(runs.id, runId)).get();
|
|
|
|
|
if (!run) notFound();
|
|
|
|
|
|
2026-08-16 00:02:57 +02:00
|
|
|
const { text: initialLog, size: initialLogBytes } = readLogTail(
|
|
|
|
|
run.logFilePath,
|
|
|
|
|
);
|
2026-08-15 18:37:30 +02:00
|
|
|
|
2026-08-16 00:11:27 +02:00
|
|
|
const script = getScript(run.scriptId);
|
|
|
|
|
const variableEntries = script
|
|
|
|
|
? script.variables.map((variable) => ({
|
|
|
|
|
key: variable.name,
|
|
|
|
|
label: variable.label ?? variable.name,
|
|
|
|
|
value: run.variables[variable.name],
|
|
|
|
|
}))
|
|
|
|
|
: Object.entries(run.variables).map(([key, value]) => ({
|
|
|
|
|
key,
|
|
|
|
|
label: key,
|
|
|
|
|
value,
|
|
|
|
|
}));
|
|
|
|
|
|
2026-08-15 18:37:30 +02:00
|
|
|
return (
|
2026-08-16 06:08:40 +02:00
|
|
|
<div className="mx-auto flex max-w-2xl flex-col gap-4">
|
2026-08-15 18:37:30 +02:00
|
|
|
<Card>
|
|
|
|
|
<CardHeader>
|
|
|
|
|
<CardTitle>{run.scriptName}</CardTitle>
|
2026-08-16 00:32:30 +02:00
|
|
|
{script && (
|
|
|
|
|
<CardAction>
|
|
|
|
|
<Link
|
|
|
|
|
href={`/scripts/${run.scriptId}?fromRun=${run.id}`}
|
|
|
|
|
className={buttonVariants({ variant: "outline", size: "sm" })}
|
|
|
|
|
>
|
|
|
|
|
<RotateCw className="size-3.5" />
|
|
|
|
|
Re-run
|
|
|
|
|
</Link>
|
|
|
|
|
</CardAction>
|
|
|
|
|
)}
|
2026-08-16 00:11:27 +02:00
|
|
|
<dl className="text-muted-foreground grid grid-cols-2 gap-x-4 gap-y-1 text-xs sm:grid-cols-3">
|
2026-08-15 18:37:30 +02:00
|
|
|
<div>
|
|
|
|
|
<dt className="font-medium">Triggered by</dt>
|
|
|
|
|
<dd>{run.triggeredBy}</dd>
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<dt className="font-medium">Started</dt>
|
|
|
|
|
<dd>
|
|
|
|
|
{run.startedAt ? new Date(run.startedAt).toLocaleString() : "-"}
|
|
|
|
|
</dd>
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<dt className="font-medium">Run ID</dt>
|
|
|
|
|
<dd className="truncate font-mono">{run.id}</dd>
|
|
|
|
|
</div>
|
|
|
|
|
</dl>
|
|
|
|
|
</CardHeader>
|
2026-08-16 00:11:27 +02:00
|
|
|
<CardContent className="flex flex-col gap-4">
|
|
|
|
|
<div className="flex flex-col gap-1.5">
|
|
|
|
|
<span className="text-muted-foreground text-xs font-medium">
|
|
|
|
|
Command
|
|
|
|
|
</span>
|
|
|
|
|
<pre className="bg-muted overflow-x-auto rounded-md p-3 font-mono text-xs whitespace-pre">
|
|
|
|
|
{run.resolvedCommand}
|
|
|
|
|
</pre>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{variableEntries.length > 0 && (
|
|
|
|
|
<div className="flex flex-col gap-1.5">
|
|
|
|
|
<span className="text-muted-foreground text-xs font-medium">
|
|
|
|
|
Variables
|
|
|
|
|
</span>
|
|
|
|
|
<dl className="grid gap-x-6 gap-y-2 rounded-md border p-3 text-xs sm:grid-cols-2">
|
|
|
|
|
{variableEntries.map(({ key, label, value }) => (
|
|
|
|
|
<div key={key} className="flex flex-col gap-0.5">
|
|
|
|
|
<dt className="text-muted-foreground">{label}</dt>
|
|
|
|
|
<dd className="font-mono break-all">
|
|
|
|
|
{formatVariableValue(value)}
|
|
|
|
|
</dd>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</dl>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2026-08-15 18:37:30 +02:00
|
|
|
<RunTerminal
|
|
|
|
|
runId={run.id}
|
|
|
|
|
initialStatus={run.status}
|
|
|
|
|
initialLog={initialLog}
|
2026-08-16 00:02:57 +02:00
|
|
|
initialLogBytes={initialLogBytes}
|
2026-08-15 18:37:30 +02:00
|
|
|
initialExitCode={run.exitCode}
|
|
|
|
|
/>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|