fix(webui): show per-run automation replies and simplify details

This commit is contained in:
chengyongru authored and chengyongru committed 2026-09-13 05:43:05 +08:00
1 parent e7da868574
commit 037438e7d1
28 files changed
+985 -183

No files matched your search

@@ -571,6 +571,7 @@ export function SettingsPage({
return (
<div className="settings-stack">
<AutomationsSettings
token={token}
payload={automations}
titleOverrides={titleOverrides}
settingsSnapshot={controller.settings}
@@ -1,6 +1,7 @@
import { CircleAlert, Loader2, X } from "lucide-react";
import { useId, useLayoutEffect, useMemo, useRef, useState } from "react";
import { AutomationRunDialog, type AutomationRunRecord } from "@/components/settings/system/AutomationRunDialog";
import { Button } from "@/components/ui/button";
import { formControlFocusClassName } from "@/components/ui/form-control";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
@@ -11,9 +12,8 @@ type CalendarEntry = {
id: string;
job: SessionAutomationJob;
startMs: number;
endMs: number | null;
kind: "planned" | "recorded";
status: string | null;
run: AutomationRunRecord | null;
};
type CalendarCopy = {
@@ -25,10 +25,12 @@ type CalendarCopy = {
close: string;
noEntries: string;
completed: string;
skipped: string;
system: string;
};
interface AutomationCalendarProps {
token?: string;
jobs: SessionAutomationJob[];
month: Date;
locale: string;
@@ -61,17 +63,15 @@ function entriesForJobs(jobs: SessionAutomationJob[]): CalendarEntry[] {
? history
: [{
run_at_ms: job.state.last_run_at_ms,
status: job.state.last_status ?? "ok",
status: job.state.last_status ?? "unknown",
error: job.state.last_error,
}];
const recorded = recordedRuns.map((run, index) => ({
id: `${job.id}:recorded:${run.run_at_ms}:${index}`,
job,
startMs: run.run_at_ms,
endMs: run.duration_ms != null && run.duration_ms > 0
? run.run_at_ms + run.duration_ms
: null,
kind: "recorded" as const,
status: run.status ?? null,
run,
}));
return nextRun == null ? recorded : [
...recorded,
@@ -79,9 +79,8 @@ function entriesForJobs(jobs: SessionAutomationJob[]): CalendarEntry[] {
id: `${job.id}:planned:${nextRun}`,
job,
startMs: nextRun,
endMs: null,
kind: "planned" as const,
status: null,
run: null,
},
];
});
@@ -89,9 +88,7 @@ function entriesForJobs(jobs: SessionAutomationJob[]): CalendarEntry[] {
function entryTime(entry: CalendarEntry, locale: string): string {
const formatter = new Intl.DateTimeFormat(locale, { hour: "2-digit", minute: "2-digit" });
const start = formatter.format(entry.startMs);
if (entry.endMs == null) return start;
return `${start}–${formatter.format(entry.endMs)}`;
return formatter.format(entry.startMs);
}
function isSameDay(left: Date, right: Date): boolean {
@@ -102,34 +99,33 @@ function CalendarEntryRow({ entry, locale, copy, onInspect, compact = false }: {
entry: CalendarEntry;
locale: string;
copy: CalendarCopy;
onInspect: AutomationCalendarProps["onInspect"];
onInspect: (entry: CalendarEntry, trigger: HTMLElement) => void;
compact?: boolean;
}) {
const name = entry.job.name || entry.job.id;
const running = Boolean(entry.job.state.pending) && entry.kind === "planned";
const failed = entry.kind === "recorded" && entry.status === "error";
const completed = entry.kind === "recorded"
&& Boolean(entry.job.delete_after_run)
&& entry.job.state.next_run_at_ms == null
&& entry.job.state.last_status === "ok";
const failed = entry.run?.status === "error";
const completed = entry.run?.status === "ok";
const status = running
? copy.running
: failed
? copy.failed
: completed
? copy.completed
: entry.kind === "planned"
? copy.planned
: copy.recorded;
: entry.run?.status === "skipped"
? copy.skipped
: entry.kind === "planned"
? copy.planned
: copy.recorded;
const content = (
<>
<span className="min-w-0 flex-1">
<span className="block truncate font-medium text-foreground">{name}</span>
<span className="mt-0.5 flex flex-wrap items-center gap-x-2 gap-y-0.5 text-[10px] leading-4 text-muted-foreground">
<span className={cn("block truncate", entry.kind === "recorded" && !failed ? "font-normal text-muted-foreground" : "font-medium text-foreground")}>{name}</span>
<span className={cn("mt-0.5 flex flex-wrap items-center gap-x-2 gap-y-0.5 text-[10px] leading-4", failed ? "text-destructive" : "text-muted-foreground")}>
{running ? <Loader2 className="h-3 w-3 animate-spin motion-reduce:animate-none" aria-hidden /> : null}
{failed ? <CircleAlert className="h-3 w-3" aria-hidden /> : null}
<span className="tabular-nums">{entryTime(entry, locale)}</span>
{compact ? <span>{status}</span> : null}
{compact || entry.kind === "recorded" ? <span>{status}</span> : null}
{entry.job.protected ? <span>{copy.system}</span> : null}
</span>
</span>
@@ -141,7 +137,6 @@ function CalendarEntryRow({ entry, locale, copy, onInspect, compact = false }: {
formControlFocusClassName,
compact && "py-2 text-[12px]",
failed && "bg-destructive/[0.045]",
entry.kind === "recorded" && !failed && "bg-muted/45",
);
return (
@@ -150,7 +145,7 @@ function CalendarEntryRow({ entry, locale, copy, onInspect, compact = false }: {
className={actionClass}
aria-label={`${name}, ${entryTime(entry, locale)}, ${status}${entry.job.protected ? `, ${copy.system}` : ""}`}
aria-haspopup="dialog"
onClick={(event) => onInspect(entry.job, event.currentTarget)}
onClick={(event) => onInspect(entry, event.currentTarget)}
>
{content}
</button>
@@ -162,12 +157,12 @@ function CalendarOverflowEntries({ entries, dayLabel, locale, copy, onInspect }:
dayLabel: string;
locale: string;
copy: CalendarCopy;
onInspect: AutomationCalendarProps["onInspect"];
onInspect: (entry: CalendarEntry, trigger: HTMLElement) => void;
}) {
const [open, setOpen] = useState(false);
const titleId = useId();
const triggerRef = useRef<HTMLButtonElement | null>(null);
const pendingSelection = useRef<SessionAutomationJob | null>(null);
const pendingSelection = useRef<CalendarEntry | null>(null);
return (
<Popover open={open} onOpenChange={setOpen}>
@@ -190,12 +185,12 @@ function CalendarOverflowEntries({ entries, dayLabel, locale, copy, onInspect }:
aria-labelledby={titleId}
className="w-80 max-w-[calc(100vw-2rem)] overscroll-contain p-2"
onCloseAutoFocus={(event) => {
const job = pendingSelection.current;
const entry = pendingSelection.current;
pendingSelection.current = null;
if (!job || !triggerRef.current?.isConnected) return;
if (!entry || !triggerRef.current?.isConnected) return;
// Hand off after the day popover exits, retaining a mounted return target.
event.preventDefault();
onInspect(job, triggerRef.current);
onInspect(entry, triggerRef.current);
}}
>
<div className="mb-1 flex items-center gap-2 px-2 py-1">
@@ -210,8 +205,8 @@ function CalendarOverflowEntries({ entries, dayLabel, locale, copy, onInspect }:
entry={entry}
locale={locale}
copy={copy}
onInspect={(job) => {
pendingSelection.current = job;
onInspect={(entry) => {
pendingSelection.current = entry;
setOpen(false);
}}
compact
@@ -222,8 +217,20 @@ function CalendarOverflowEntries({ entries, dayLabel, locale, copy, onInspect }:
);
}
export function AutomationCalendar({ jobs, month, locale, copy, onInspect }: AutomationCalendarProps) {
export function AutomationCalendar({ token = "", jobs, month, locale, copy, onInspect }: AutomationCalendarProps) {
const calendarRef = useRef<HTMLElement | null>(null);
const runTrigger = useRef<HTMLElement | null>(null);
const [selectedRun, setSelectedRun] = useState<{ job: SessionAutomationJob; run: AutomationRunRecord } | null>(null);
const [runOpen, setRunOpen] = useState(false);
const inspectEntry = (entry: CalendarEntry, trigger: HTMLElement) => {
if (!entry.run) {
onInspect(entry.job, trigger);
return;
}
runTrigger.current = trigger;
setSelectedRun({ job: entry.job, run: entry.run });
setRunOpen(true);
};
const [wideCalendar, setWideCalendar] = useState(true);
const today = startOfDay(new Date());
const gridStart = addDays(month, -mondayIndex(month));
@@ -258,7 +265,7 @@ export function AutomationCalendar({ jobs, month, locale, copy, onInspect }: Aut
}, []);
return (
<section ref={calendarRef} className="automation-calendar overflow-hidden bg-[hsl(var(--settings-surface))]">
<section ref={calendarRef} tabIndex={-1} className="automation-calendar overflow-hidden bg-[hsl(var(--settings-surface))]">
<div className="automation-calendar-header bg-foreground/[0.025]">
{wideCalendar ? <div className="automation-calendar-weekdays" aria-hidden>
{weekdayLabels.map((label) => <div key={label}>{label}</div>)}
@@ -297,7 +304,7 @@ export function AutomationCalendar({ jobs, month, locale, copy, onInspect }: Aut
entry={entry}
locale={locale}
copy={copy}
onInspect={onInspect}
onInspect={inspectEntry}
/>
))}
{entries.length > 3 ? (
@@ -306,7 +313,7 @@ export function AutomationCalendar({ jobs, month, locale, copy, onInspect }: Aut
dayLabel={dayLabel}
locale={locale}
copy={copy}
onInspect={onInspect}
onInspect={inspectEntry}
/>
) : null}
</div>
@@ -329,7 +336,7 @@ export function AutomationCalendar({ jobs, month, locale, copy, onInspect }: Aut
entry={entry}
locale={locale}
copy={copy}
onInspect={onInspect}
onInspect={inspectEntry}
compact
/>
))}
@@ -342,6 +349,18 @@ export function AutomationCalendar({ jobs, month, locale, copy, onInspect }: Aut
)}
</div> : null}
{selectedRun ? <AutomationRunDialog
token={token}
job={selectedRun.job} run={selectedRun.run} locale={locale} open={runOpen}
onOpenChange={setRunOpen}
onCloseAutoFocus={(event) => {
event.preventDefault();
if (runOpen) return;
setSelectedRun(null);
const target = runTrigger.current?.isConnected ? runTrigger.current : calendarRef.current;
target?.focus({ preventScroll: true });
}}
/> : null}
</section>
);
}
@@ -0,0 +1,126 @@
import { CircleAlert } from "lucide-react";
import { useEffect, useState } from "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 { fetchAutomationRunResult } from "@/lib/api";
import { cn } from "@/lib/utils";
export type AutomationRunRecord = NonNullable<SessionAutomationJob["state"]["run_history"]>[number];
export function AutomationRunDialog({ token = "", job, run, locale, open, onOpenChange, onCloseAutoFocus }: {
token?: string;
job: SessionAutomationJob;
run: AutomationRunRecord;
locale: string;
open: boolean;
onOpenChange: (open: boolean) => void;
onCloseAutoFocus: (event: Event) => void;
}) {
const { t } = useTranslation();
const [attempt, setAttempt] = useState(0);
const kind = job.kind === "local_trigger" ? "local_trigger" : "cron";
const resultKey = JSON.stringify([token, kind, job.id, run.run_at_ms, attempt]);
const [result, setResult] = useState<{
key: string; status: "loading" | "loaded" | "error"; response: string | null;
} | null>(null);
useEffect(() => {
if (!open) return;
if (!token) {
setResult({ key: resultKey, status: "loaded", response: null });
return;
}
const controller = new AbortController();
setResult({ key: resultKey, status: "loading", response: null });
void fetchAutomationRunResult(token, job.id, run.run_at_ms, kind, controller.signal)
.then((payload) => {
if (!controller.signal.aborted) {
setResult({ key: resultKey, status: "loaded", response: payload.response });
}
})
.catch(() => {
if (!controller.signal.aborted) {
setResult({ key: resultKey, status: "error", response: null });
}
});
return () => controller.abort();
}, [job.id, kind, open, resultKey, run.run_at_ms, token]);
const currentResult = result?.key === resultKey ? result : null;
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 chatHref = job.origin?.channel === "websocket" && job.origin.session_key
? `#/chat/${encodeURIComponent(job.origin.session_key)}` : 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}
{!currentResult || currentResult.status === "loading" ? (
<p role="status" className="text-muted-foreground">{t("settings.automations.runDetails.loading")}</p>
) : currentResult.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={() => setAttempt((value) => value + 1)}>
{t("settings.automations.runDetails.retry")}
</Button>
</div>
) : currentResult.response?.trim() ? (
<MarkdownText className="min-w-0 text-sm [overflow-wrap:anywhere]">{currentResult.response}</MarkdownText>
) : (
<p className="text-muted-foreground">{t(currentResult.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>
);
}
@@ -3,7 +3,7 @@ import type { FormEvent, ReactNode } from "react";
import type { TFunction } from "i18next";
import {
Check,
ChevronDown,
Info,
CircleAlert,
Clipboard,
ListFilter,
@@ -21,7 +21,8 @@ import {
} from "@/components/thread/model-preset";
import { ThreadComposer } from "@/components/thread/ThreadComposer";
import { Button } from "@/components/ui/button";
import { Disclosure } from "@/components/ui/disclosure";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
import { DropdownMenu, DropdownMenuContent, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
import { ExpandableText } from "@/components/ui/expandable-text";
import {
@@ -54,6 +55,7 @@ export type AutomationAction = "enable" | "disable" | "delete" | "run";
const EMPTY_TITLE_OVERRIDES: Record<string, string> = {};
export function AutomationsSettings({
token = "",
payload, loading, filter, actionKey, error,
titleOverrides = EMPTY_TITLE_OVERRIDES,
settingsSnapshot = null,
@@ -61,6 +63,7 @@ export function AutomationsSettings({
onRequestEdit, onRequestDelete, onStartChat, onManageModels,
returnToDetailJob = null, onReturnToDetailHandled,
}: {
token?: string;
payload: AutomationsPayload | null;
titleOverrides?: Record<string, string>;
settingsSnapshot?: SettingsPayload | null;
@@ -253,8 +256,8 @@ export function AutomationsSettings({
<div className="automation-view-switch" role="group" aria-label={tx("settings.automations.views.label", "Automation view")}>
<SegmentedControl
value={view}
className="bg-[var(--automation-view-track)]"
itemClassName="min-h-8"
className="rounded-[var(--radius-panel)] bg-[var(--automation-view-track)]"
itemClassName="min-h-8 rounded-[calc(var(--radius-panel)-0.25rem)]"
options={[
{ value: "tasks", label: tx("settings.automations.views.tasks", "Tasks") },
{ value: "calendar", label: tx("settings.automations.views.calendar", "Calendar") },
@@ -270,7 +273,7 @@ export function AutomationsSettings({
{filters ? <div className="automation-panel-filters min-w-0">{filters}</div> : null}
{view === "calendar" ? (
<div className="automation-calendar-navigation flex shrink-0 items-center gap-1">
<Button type="button" variant="outline" size="sm" className="h-8 rounded-control px-3 text-[12px]"
<Button type="button" variant="ghost" size="sm" className="h-8 rounded-full bg-background/60 px-3 text-[12px] text-foreground"
onClick={() => { const today = new Date(); setMonth(new Date(today.getFullYear(), today.getMonth(), 1)); }}>
{tx("settings.automations.calendar.today", "Today")}
</Button>
@@ -334,6 +337,7 @@ export function AutomationsSettings({
</section>
) : (
<AutomationCalendar
token={token}
jobs={filtered}
month={month}
locale={locale}
@@ -351,6 +355,7 @@ export function AutomationsSettings({
? tx("settings.automations.noMatches", "No automations match this view.")
: tx("settings.automations.empty", "No automations yet."),
completed: tx("settings.automations.status.completed", "Completed"),
skipped: tx("settings.automations.skipped", "Skipped"),
}}
onInspect={inspectJob}
/>
@@ -412,10 +417,10 @@ export function AutomationDetailDialog({
<Dialog open={open} onOpenChange={onOpenChange}>
{job ? (
<DialogContent
{...(job.protected ? { "aria-describedby": undefined } : {})}
aria-describedby={undefined}
{...(!open ? { inert: "", "aria-hidden": true } : {})}
className={cn(
"flex max-h-[calc(100dvh-2rem)] max-w-[520px] flex-col gap-0 overflow-hidden p-0",
"flex max-h-[calc(100dvh-2rem)] max-w-[520px] flex-col gap-0 p-0 text-sm font-normal leading-normal text-foreground",
job.protected && "max-w-[440px]",
)}
onCloseAutoFocus={onCloseAutoFocus}
@@ -475,40 +480,75 @@ function AutomationDetailPanel({
return (
<>
<DialogHeader className="shrink-0 px-6 pb-3 pr-14 pt-5 text-left">
<DialogTitle className="min-w-0 break-words leading-6 text-balance">{job.name || job.id}</DialogTitle>
{canManage ? (
<DialogDescription className="flex flex-wrap items-center gap-x-4 gap-y-1 text-[13px] leading-5">
<span className="font-medium text-foreground/80">{formatAutomationSchedule(job, locale, tx)}</span>
{!localTrigger ? <span className="inline-flex min-w-0 items-center gap-1.5">
<span>{tx("settings.automations.labels.next", "Next")}</span>
<span className="text-foreground/80" title={formatAutomationNextTitle(job, locale, tx)}>
{formatAutomationNext(job, tx)}
</span>
</span> : null}
</DialogDescription>
) : null}
<div className="absolute right-11 top-2.5">
<Popover>
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<PopoverTrigger asChild>
<Button variant="ghost" size="icon" className="h-7 w-7 shrink-0 rounded-full text-muted-foreground"
aria-label={tx("settings.automations.taskInfo", "Task information")}>
<Info className="h-3.5 w-3.5" strokeWidth={1.5} aria-hidden />
</Button>
</PopoverTrigger>
</TooltipTrigger>
<TooltipContent>{tx("settings.automations.taskInfo", "Task information")}</TooltipContent>
</Tooltip>
</TooltipProvider>
<PopoverContent side="bottom" align="end" collisionPadding={16}
aria-label={tx("settings.automations.taskInfo", "Task information")}
className="w-80 max-w-[calc(100vw-2rem)] p-4 text-sm font-normal">
<dl>
<AutomationDetail label={tx("settings.automations.labels.schedule", "Schedule")}>
{formatAutomationSchedule(job, locale, tx)}
</AutomationDetail>
{!localTrigger ? (
<AutomationDetail label={tx("settings.automations.sort.next", "Next run")} title={formatAutomationNextTitle(job, locale, tx)}>
{formatAutomationNext(job, tx)}
</AutomationDetail>
) : null}
<AutomationDetail label={tx("settings.automations.sort.last", "Last run")} title={job.state.last_run_at_ms ? fmtDateTime(job.state.last_run_at_ms, locale) : undefined}>
{job.state.last_run_at_ms
? <span className="flex flex-wrap gap-x-3 gap-y-1">
{lastStatus ? <span>{lastStatus}</span> : null}
<span>{relativeTime(job.state.last_run_at_ms)}</span>
</span>
: lastStatus || tx("settings.automations.neverRun", "Not run yet")}
</AutomationDetail>
{timezone ? (
<AutomationDetail label={tx("settings.automations.fields.timezone", "Timezone")}>{timezone}</AutomationDetail>
) : null}
{job.delete_after_run ? <AutomationDetail label={tx("settings.automations.oneShot", "One-time")}>{tx("settings.automations.oneShotHint", "Removed after running")}</AutomationDetail> : null}
{job.created_at_ms ? <AutomationDetail label={tx("settings.automations.labels.created", "Created")}>{fmtDateTime(job.created_at_ms, locale)}</AutomationDetail> : null}
{job.updated_at_ms ? <AutomationDetail label={tx("settings.automations.labels.updated", "Updated")}>{fmtDateTime(job.updated_at_ms, locale)}</AutomationDetail> : null}
<AutomationDetail label="ID"><span className="break-all font-mono">{job.id}</span></AutomationDetail>
</dl>
</PopoverContent>
</Popover>
</div>
<DialogHeader className="shrink-0 px-6 pb-3 pr-24 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>
</DialogHeader>
<div className="min-h-0 overflow-y-auto overscroll-contain px-6 pb-3">
{canManage && message.trim() ? <section className="pb-4">
<div className="flex items-center justify-between gap-3 text-[12px] text-muted-foreground">
<span>{localTrigger ? tx("settings.automations.fields.command", "Command") : tx("settings.automations.instructions", "Instructions")}</span>
{localTrigger && command ? (
<Button variant="ghost" size="sm" onClick={() => {
{localTrigger && command ? (
<div className="mb-2 flex items-center justify-between gap-3 text-sm text-muted-foreground">
<span>{tx("settings.automations.fields.command", "Command")}</span>
<Button variant="ghost" size="sm" className="font-normal text-muted-foreground" onClick={() => {
void copyTextToClipboard(command).then((ok) => { if (ok) setCommandCopied(true); });
}}>
{commandCopied ? <Check className="mr-1.5 h-3.5 w-3.5" aria-hidden /> : <Clipboard className="mr-1.5 h-3.5 w-3.5" aria-hidden />}
{commandCopied ? tx("settings.automations.commandCopied", "Copied") : tx("settings.automations.copyCommand", "Copy")}
</Button>
) : null}
</div>
<div className="mt-2">
<ExpandableText id={messageId} expanded={messageExpanded || !messageNeedsExpansion} lines={6} className={cn("whitespace-pre-wrap break-words text-[13px] leading-5 text-foreground [overflow-wrap:anywhere]", localTrigger && "font-mono text-[12px]")}>
</div>
) : null}
<div>
<ExpandableText id={messageId} expanded={messageExpanded || !messageNeedsExpansion} lines={6} className={cn("whitespace-pre-wrap break-words text-sm leading-normal text-foreground [overflow-wrap:anywhere]", localTrigger && "font-mono")}>
{message}
</ExpandableText>
</div>
{messageNeedsExpansion ? (
<button type="button" aria-expanded={messageExpanded} aria-controls={messageId} onClick={() => setMessageExpanded((value) => !value)} className="mt-2 rounded-sm text-[12px] text-muted-foreground underline-offset-4 hover:text-foreground hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
<button type="button" aria-expanded={messageExpanded} aria-controls={messageId} onClick={() => setMessageExpanded((value) => !value)} className="mt-2 rounded-sm text-sm text-muted-foreground underline-offset-4 hover:text-foreground hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
{messageExpanded ? tx("settings.automations.message.showLess", "Show less") : tx("settings.automations.message.showMore", "Show full message")}
</button>
) : null}
@@ -516,65 +556,24 @@ function AutomationDetailPanel({
{job.state.last_error ? <AutomationError message={job.state.last_error} /> : null}
{error ? <AutomationError message={error} /> : null}
<dl>
{job.protected ? (
<>
<AutomationDetail label={tx("settings.automations.labels.schedule", "Schedule")}>
{formatAutomationSchedule(job, locale, tx)}
</AutomationDetail>
{timezone ? (
<AutomationDetail label={tx("settings.automations.fields.timezone", "Timezone")}>
{timezone}
</AutomationDetail>
) : null}
<AutomationDetail label={tx("settings.automations.sort.next", "Next run")} title={formatAutomationNextTitle(job, locale, tx)}>
{formatAutomationNext(job, tx)}
</AutomationDetail>
</>
) : null}
<AutomationDetail label={tx("settings.automations.sort.last", "Last run")} title={job.state.last_run_at_ms ? fmtDateTime(job.state.last_run_at_ms, locale) : undefined}>
{job.state.last_run_at_ms
? <span className="flex flex-wrap justify-end gap-x-3 gap-y-1">
{lastStatus ? <span>{lastStatus}</span> : null}
<span>{relativeTime(job.state.last_run_at_ms)}</span>
</span>
: lastStatus || tx("settings.automations.neverRun", "Not run yet")}
</AutomationDetail>
{!job.protected && job.origin?.channel && job.origin.channel !== "websocket" ? (
<AutomationDetail label={tx("settings.automations.labels.origin", "Linked chat")}>
{automationChannelLabel(job.origin.channel, t)}
</AutomationDetail>
) : null}
</dl>
<Disclosure
className="mt-2"
summaryClassName={cn("flex min-h-10 cursor-pointer items-center justify-between gap-3 rounded-control py-2.5 text-[13px] text-muted-foreground transition-colors hover:text-foreground", formControlFocusClassName)}
summary={<>
{tx("settings.automations.moreDetails", "More details")}
<ChevronDown className="h-3.5 w-3.5 transition-transform duration-200 group-data-[state=open]/disclosure:rotate-180 motion-reduce:transition-none" aria-hidden />
</>}
>
<dl>
{timezone && canManage ? (
<AutomationDetail label={tx("settings.automations.fields.timezone", "Timezone")}>
{timezone}
</AutomationDetail>
) : null}
{job.delete_after_run ? <AutomationDetail label={tx("settings.automations.oneShot", "One-time")}>{tx("settings.automations.oneShotHint", "Removed after running")}</AutomationDetail> : null}
{job.created_at_ms ? <AutomationDetail label={tx("settings.automations.labels.created", "Created")}>{fmtDateTime(job.created_at_ms, locale)}</AutomationDetail> : null}
{job.updated_at_ms ? <AutomationDetail label={tx("settings.automations.labels.updated", "Updated")}>{fmtDateTime(job.updated_at_ms, locale)}</AutomationDetail> : null}
<AutomationDetail label="ID"><span className="break-all font-mono text-[11px]">{job.id}</span></AutomationDetail>
</dl>
</Disclosure>
</div>
{canManage ? (
<div className="flex shrink-0 flex-col gap-2 border-t border-border/45 px-6 py-3 sm:flex-row sm:items-center">
<div className="flex min-w-0 flex-wrap items-center gap-1">
<Button variant="ghost" size="sm" className="text-muted-foreground" disabled={busy || !canToggle} onClick={() => void onAction(job.enabled ? "disable" : "enable", job)}>
{actionKey === `${job.enabled ? "disable" : "enable"}:${job.id}` ? <Loader2 className="mr-1.5 h-3.5 w-3.5 animate-spin" aria-hidden /> : null}
<div className="flex shrink-0 flex-wrap items-center gap-x-6 gap-y-2 border-t border-border/45 px-6 py-3">
<div className="flex max-w-full flex-wrap gap-2">
<Button variant="ghost" size="sm" className="font-normal text-muted-foreground" disabled={busy || !canToggle}
onClick={() => void onAction(job.enabled ? "disable" : "enable", job)}>
{actionKey === `enable:${job.id}` || actionKey === `disable:${job.id}`
? <Loader2 className="mr-1.5 h-3.5 w-3.5 animate-spin" aria-hidden /> : null}
{job.enabled ? tx("settings.automations.pause", "Disable") : tx("settings.automations.resume", "Enable")}
</Button>
{!localTrigger ? (
<Button variant="ghost" size="sm" className="text-muted-foreground" disabled={!canRun || busy} onClick={() => void onAction("run", job)}>
<Button variant="ghost" size="sm" className="font-normal text-muted-foreground" disabled={!canRun || busy} onClick={() => void onAction("run", job)}>
{actionKey === `run:${job.id}` ? <Loader2 className="mr-1.5 h-3.5 w-3.5 animate-spin" aria-hidden /> : null}
{tx("settings.automations.runNow", "Run now")}
</Button>
@@ -582,18 +581,18 @@ function AutomationDetailPanel({
<Button
variant="ghost"
size="sm"
className="text-destructive hover:bg-destructive/10 hover:text-destructive"
className="font-normal text-muted-foreground hover:bg-destructive/10 hover:text-destructive focus-visible:text-destructive"
disabled={busy}
onClick={() => onRequestDelete(job)}
>
{tx("settings.automations.delete", "Delete")}
</Button>
</div>
<div className="flex max-w-full flex-wrap justify-end gap-2 sm:ml-auto">
<Button variant="outline" size="sm" disabled={busy} onClick={() => onRequestEdit(job)}>
<div className="ms-auto flex max-w-full flex-wrap justify-end gap-2">
<Button variant="ghost" size="sm" className="font-normal text-muted-foreground" disabled={busy} onClick={() => onRequestEdit(job)}>
{tx("settings.automations.edit", "Edit")}
</Button>
{originHref ? <Button asChild size="sm"><a href={originHref}>{tx("settings.automations.emptyAction", "Open a chat")}</a></Button> : null}
{originHref ? <Button asChild variant="ghost" size="sm" className="font-normal text-muted-foreground"><a href={originHref}>{tx("settings.automations.emptyAction", "Open a chat")}</a></Button> : null}
</div>
</div>
) : null}
@@ -631,11 +630,11 @@ function automationMessageNeedsExpansion(message: string): boolean {
return message.length > 360 || message.split(/\r?\n/).length > 6;
}
function AutomationDetail({ label, title, children }: { label: string; title?: string; children: ReactNode }) {
function AutomationDetail({ label, title, children }: { label: ReactNode; title?: string; children: ReactNode }) {
return (
<div className="grid min-w-0 grid-cols-[minmax(6.5rem,0.75fr)_minmax(0,1.75fr)] items-start gap-4 py-2.5 text-[13px] leading-5">
<div className="grid min-w-0 grid-cols-[minmax(6.5rem,0.75fr)_minmax(0,1.75fr)] items-start gap-4 py-2.5 text-sm leading-normal">
<dt className="text-muted-foreground">{label}</dt>
<dd className="min-w-0 break-words text-right text-foreground [overflow-wrap:anywhere]" title={title}>{children}</dd>
<dd className="min-w-0 break-words text-start text-foreground [overflow-wrap:anywhere]" title={title}>{children}</dd>
</div>
);
}