Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
import { CircleAlert } from "lucide-react";
import { useTranslation } from "react-i18next";
import { MarkdownText } from "@/components/MarkdownText";
import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import type { SessionAutomationJob } from "@/lib/types";
import { cn } from "@/lib/utils";
export type AutomationRunRecord = NonNullable<SessionAutomationJob["state"]["run_history"]>[number];
export type AutomationRunResult = {
status: "loading" | "loaded" | "error";
response: string | null;
};
export function AutomationRunDialogView({ job, run, locale, open, result, onRetry, onOpenChange, onCloseAutoFocus }: {
job: SessionAutomationJob;
run: AutomationRunRecord;
locale: string;
open: boolean;
result: AutomationRunResult;
onRetry: () => void;
onOpenChange: (open: boolean) => void;
onCloseAutoFocus: (event: Event) => void;
}) {
const { t } = useTranslation();
const failed = run.status === "error";
const status = run.status === "ok"
? t("settings.automations.status.completed")
: failed ? t("settings.automations.status.failed")
: run.status === "skipped" ? t("settings.automations.skipped")
: t("settings.automations.calendar.recorded");
const duration = run.duration_ms;
const chatKey = run.webui_session_key !== undefined ? run.webui_session_key
: job.origin?.channel === "websocket" ? job.origin.session_key : null;
const chatHref = chatKey ? `#/chat/${encodeURIComponent(chatKey)}` : null;
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent
{...(!open ? { inert: "", "aria-hidden": true } : {})}
className="flex max-h-[calc(100dvh-2rem)] max-w-[520px] flex-col gap-0 p-0 text-sm font-normal leading-normal text-foreground"
onCloseAutoFocus={onCloseAutoFocus}
>
<DialogHeader className="shrink-0 px-6 pb-4 pr-14 pt-5 text-left">
<DialogTitle className="min-w-0 break-words text-lg font-medium leading-snug tracking-normal text-balance">
{job.name || job.id}
</DialogTitle>
<DialogDescription className="text-sm font-normal text-muted-foreground">
<time dateTime={new Date(run.run_at_ms).toISOString()}>
{new Intl.DateTimeFormat(locale, { dateStyle: "medium", timeStyle: "short" }).format(run.run_at_ms)}
</time>
</DialogDescription>
</DialogHeader>
<div className="min-h-0 space-y-4 overflow-y-auto overscroll-contain px-6 pb-6">
<dl className="space-y-3">
<div className="flex items-start justify-between gap-4">
<dt className="text-muted-foreground">{t("settings.automations.runDetails.result")}</dt>
<dd className={cn("flex items-center gap-1.5 text-end", failed && "text-destructive")}>
{failed ? <CircleAlert className="h-3.5 w-3.5 shrink-0" strokeWidth={1.5} aria-hidden /> : null}
{status}
</dd>
</div>
{duration != null && Number.isFinite(duration) && duration >= 0 ? (
<div className="flex items-start justify-between gap-4">
<dt className="text-muted-foreground">{t("settings.automations.runDetails.duration")}</dt>
<dd className="text-end tabular-nums">{new Intl.NumberFormat(locale, {
style: "unit", unit: "second", unitDisplay: "short",
maximumFractionDigits: duration < 1000 ? 3 : 1,
}).format(duration / 1000)}</dd>
</div>
) : null}
</dl>
{run.error ? <p className={cn("whitespace-pre-wrap break-words [overflow-wrap:anywhere]", failed && "text-destructive")}>{run.error}</p> : null}
{result.status === "loading" ? (
<p role="status" className="text-muted-foreground">{t("settings.automations.runDetails.loading")}</p>
) : result.status === "error" ? (
<div className="flex flex-wrap items-center justify-between gap-2">
<p role="alert" className="text-muted-foreground">{t("settings.automations.runDetails.loadError")}</p>
<Button variant="ghost" size="sm" onClick={onRetry}>
{t("settings.automations.runDetails.retry")}
</Button>
</div>
) : result.response?.trim() ? (
<MarkdownText className="min-w-0 [overflow-wrap:anywhere]">{result.response}</MarkdownText>
) : (
<p className="text-muted-foreground">{t(result.response === null
? "settings.automations.runDetails.noOutput"
: "settings.automations.runDetails.emptyOutput")}</p>
)}
</div>
{chatHref ? (
<div className="flex shrink-0 justify-end border-t border-border/45 px-6 py-3">
<Button asChild variant="ghost" size="sm" className="font-normal text-muted-foreground">
<a href={chatHref}>{t("settings.automations.emptyAction")}</a>
</Button>
</div>
) : null}
</DialogContent>
</Dialog>
);
}