Merge pull request #1443 from CREDO23/feature-automations

[Feat] Automation V1 — Scheduled Agent Tasks, Created via Chat (HITL) or JSON
This commit is contained in:
Rohan Verma 2026-05-28 12:41:41 -07:00 committed by GitHub
commit 4dda02c06c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
219 changed files with 13821 additions and 55 deletions

View file

@ -0,0 +1,91 @@
"use client";
import { ShieldAlert } from "lucide-react";
import { useAutomation } from "@/hooks/use-automation";
import { useAutomationPermissions } from "../hooks/use-automation-permissions";
import { AutomationDefinitionSection } from "./components/automation-definition-section";
import { AutomationDetailHeader } from "./components/automation-detail-header";
import { AutomationDetailLoading } from "./components/automation-detail-loading";
import { AutomationNotFound } from "./components/automation-not-found";
import { AutomationRunsSection } from "./components/automation-runs-section";
import { AutomationTriggersSection } from "./components/automation-triggers-section";
interface AutomationDetailContentProps {
searchSpaceId: number;
automationId: number;
}
/**
* Client orchestrator for one automation's detail view. Branches:
* - permissions loading skeleton
* - no read permission access denied panel
* - bad id (NaN) not-found panel
* - detail fetching skeleton
* - detail error / null not-found panel (we don't distinguish 404
* from 403 in the UI)
* - detail loaded header + definition + triggers
*
* Each child component is gated independently on the relevant permission
* so the orchestrator stays thin.
*/
export function AutomationDetailContent({
searchSpaceId,
automationId,
}: AutomationDetailContentProps) {
const perms = useAutomationPermissions();
const validId = Number.isInteger(automationId) && automationId > 0;
const { data: automation, isLoading, error } = useAutomation(validId ? automationId : undefined);
if (perms.loading) {
return <AutomationDetailLoading />;
}
if (!perms.canRead) {
return (
<div className="rounded-lg border border-border/60 bg-muted/20 px-6 py-12 text-center">
<ShieldAlert className="mx-auto h-10 w-10 text-muted-foreground" aria-hidden />
<h2 className="mt-3 text-base font-semibold text-foreground">Access denied</h2>
<p className="mt-1 text-sm text-muted-foreground max-w-md mx-auto">
You don't have permission to view automations in this search space.
</p>
</div>
);
}
if (!validId) {
return <AutomationNotFound searchSpaceId={searchSpaceId} />;
}
if (isLoading) {
return <AutomationDetailLoading />;
}
if (error || !automation) {
return <AutomationNotFound searchSpaceId={searchSpaceId} error={error} />;
}
return (
<>
<AutomationDetailHeader
automation={automation}
searchSpaceId={searchSpaceId}
canUpdate={perms.canUpdate}
canDelete={perms.canDelete}
/>
<div className="grid grid-cols-1 gap-6 lg:grid-cols-3">
<div className="space-y-6 min-w-0 lg:col-span-2">
<AutomationDefinitionSection definition={automation.definition} />
<AutomationRunsSection automationId={automation.id} />
</div>
<div className="space-y-6 min-w-0">
<AutomationTriggersSection
triggers={automation.triggers}
automationId={automation.id}
canUpdate={perms.canUpdate}
canDelete={perms.canDelete}
/>
</div>
</div>
</>
);
}

View file

@ -0,0 +1,98 @@
"use client";
import { ListOrdered, Settings2, Tag, Target } from "lucide-react";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import type { AutomationDefinition } from "@/contracts/types/automation.types";
import { ExecutionSummary } from "./execution-summary";
import { InputsSchemaPreview } from "./inputs-schema-preview";
import { PlanStepCard } from "./plan-step-card";
interface AutomationDefinitionSectionProps {
definition: AutomationDefinition;
}
/**
* The Definition card. Read view; editing happens on the sibling /edit
* route (Edit button in the header). Layout is top-down:
* goal tags execution defaults inputs schema (if any) plan
*
* The schema_version is rendered as a small badge next to the section
* title so it's discoverable but doesn't fight for attention.
*/
export function AutomationDefinitionSection({ definition }: AutomationDefinitionSectionProps) {
const hasTags = definition.metadata.tags.length > 0;
const hasInputs = !!definition.inputs;
return (
<Card className="border-border/60 bg-accent">
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-4">
<CardTitle className="text-base font-semibold">Definition</CardTitle>
<span className="text-xs font-mono text-muted-foreground border border-border/60 rounded px-1.5 py-0.5">
v{definition.schema_version}
</span>
</CardHeader>
<CardContent className="space-y-6">
{definition.goal && (
<Field icon={Target} label="Goal">
<p className="text-sm text-foreground">{definition.goal}</p>
</Field>
)}
{hasTags && (
<Field icon={Tag} label="Tags">
<div className="flex flex-wrap gap-1.5">
{definition.metadata.tags.map((tag) => (
<span
key={tag}
className="inline-flex items-center rounded-md bg-muted px-2 py-0.5 text-xs text-muted-foreground"
>
{tag}
</span>
))}
</div>
</Field>
)}
<Field icon={Settings2} label="Execution defaults">
<ExecutionSummary execution={definition.execution} />
</Field>
{hasInputs && (
<Field icon={Settings2} label="Inputs schema">
{definition.inputs && <InputsSchemaPreview inputs={definition.inputs} />}
</Field>
)}
<Field
icon={ListOrdered}
label={`Plan · ${definition.plan.length} step${definition.plan.length === 1 ? "" : "s"}`}
>
<div className="space-y-2">
{definition.plan.map((step, idx) => (
<PlanStepCard key={step.step_id} step={step} index={idx} />
))}
</div>
</Field>
</CardContent>
</Card>
);
}
function Field({
icon: Icon,
label,
children,
}: {
icon: typeof Target;
label: string;
children: React.ReactNode;
}) {
return (
<div className="space-y-2">
<div className="flex items-center gap-1.5 text-xs font-medium text-muted-foreground uppercase tracking-wider">
<Icon className="h-3.5 w-3.5" aria-hidden />
{label}
</div>
{children}
</div>
);
}

View file

@ -0,0 +1,137 @@
"use client";
import { useAtomValue } from "jotai";
import { ArrowLeft, Pause, Pencil, Play, Trash2 } from "lucide-react";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useCallback, useState } from "react";
import { updateAutomationMutationAtom } from "@/atoms/automations/automations-mutation.atoms";
import { Button } from "@/components/ui/button";
import { Spinner } from "@/components/ui/spinner";
import type { Automation } from "@/contracts/types/automation.types";
import { AutomationStatusBadge } from "../../components/automation-status-badge";
import { DeleteAutomationDialog } from "../../components/delete-automation-dialog";
interface AutomationDetailHeaderProps {
automation: Automation;
searchSpaceId: number;
canUpdate: boolean;
canDelete: boolean;
}
/**
* Title bar for the detail page: back link, name, status badge,
* description, and the two destructive-ish primary actions (pause /
* resume + delete). Same mutation atoms as the list-row actions to
* keep caches coherent.
*
* Archived automations hide the pause/resume toggle (we don't unarchive
* here that flow comes later if we need it).
*/
export function AutomationDetailHeader({
automation,
searchSpaceId,
canUpdate,
canDelete,
}: AutomationDetailHeaderProps) {
const router = useRouter();
const { mutateAsync: updateAutomation, isPending: updating } = useAtomValue(
updateAutomationMutationAtom
);
const [deleteOpen, setDeleteOpen] = useState(false);
const canToggle = canUpdate && automation.status !== "archived";
const nextStatus = automation.status === "active" ? "paused" : "active";
const pauseLabel = automation.status === "active" ? "Pause" : "Resume";
const PauseIcon = automation.status === "active" ? Pause : Play;
const handleDeleted = useCallback(() => {
router.push(`/dashboard/${searchSpaceId}/automations`);
}, [router, searchSpaceId]);
async function handleTogglePause() {
await updateAutomation({
automationId: automation.id,
patch: { status: nextStatus },
});
}
return (
<>
<div className="space-y-3">
<Button asChild variant="ghost" size="sm" className="-ml-2 h-auto px-2 py-1">
<Link
href={`/dashboard/${searchSpaceId}/automations`}
className="text-xs text-muted-foreground"
>
<ArrowLeft className="mr-1.5 h-3.5 w-3.5" />
Back to automations
</Link>
</Button>
<div className="flex items-start justify-between gap-4 flex-wrap">
<div className="space-y-2 min-w-0 flex-1">
<div className="flex items-center gap-3 flex-wrap">
<h1 className="text-xl md:text-2xl font-semibold text-foreground break-words">
{automation.name}
</h1>
<AutomationStatusBadge status={automation.status} />
</div>
{automation.description && (
<p className="text-sm text-muted-foreground max-w-3xl">{automation.description}</p>
)}
</div>
<div className="flex items-center gap-2 shrink-0">
{canUpdate && (
<Button asChild type="button" variant="outline" size="sm">
<Link href={`/dashboard/${searchSpaceId}/automations/${automation.id}/edit`}>
<Pencil className="mr-2 h-4 w-4" />
Edit
</Link>
</Button>
)}
{canToggle && (
<Button
type="button"
variant="outline"
size="sm"
onClick={handleTogglePause}
disabled={updating}
>
{updating ? (
<Spinner size="xs" className="mr-2" />
) : (
<PauseIcon className="mr-2 h-4 w-4" />
)}
{pauseLabel}
</Button>
)}
{canDelete && (
<Button
type="button"
variant="outline"
size="sm"
onClick={() => setDeleteOpen(true)}
className="text-destructive hover:text-destructive hover:bg-destructive/10"
>
<Trash2 className="mr-2 h-4 w-4" />
Delete
</Button>
)}
</div>
</div>
</div>
{canDelete && (
<DeleteAutomationDialog
open={deleteOpen}
onOpenChange={setDeleteOpen}
automationId={automation.id}
automationName={automation.name}
searchSpaceId={searchSpaceId}
onDeleted={handleDeleted}
/>
)}
</>
);
}

View file

@ -0,0 +1,56 @@
"use client";
import { Card, CardContent, CardHeader } from "@/components/ui/card";
import { Skeleton } from "@/components/ui/skeleton";
/**
* Skeleton for the detail page. Mirrors the loaded view's main/sidebar
* grid (Definition + Runs on the left, Triggers on the right) so layout
* doesn't reflow when data arrives.
*/
export function AutomationDetailLoading() {
return (
<>
<div className="space-y-3">
<Skeleton className="h-4 w-32" />
<div className="flex items-center gap-3">
<Skeleton className="h-7 w-64" />
<Skeleton className="h-5 w-16 rounded-md" />
</div>
<Skeleton className="h-4 w-96" />
</div>
<div className="grid grid-cols-1 gap-6 lg:grid-cols-3">
<div className="space-y-6 min-w-0 lg:col-span-2">
<Card className="border-border/60 bg-accent">
<CardHeader>
<Skeleton className="h-5 w-32" />
</CardHeader>
<CardContent className="space-y-4">
<Skeleton className="h-4 w-3/4" />
<Skeleton className="h-4 w-1/2" />
<Skeleton className="h-24 w-full" />
</CardContent>
</Card>
<Card className="border-border/60 bg-accent">
<CardHeader>
<Skeleton className="h-5 w-32" />
</CardHeader>
<CardContent>
<Skeleton className="h-20 w-full" />
</CardContent>
</Card>
</div>
<div className="space-y-6 min-w-0">
<Card className="border-border/60 bg-accent">
<CardHeader>
<Skeleton className="h-5 w-24" />
</CardHeader>
<CardContent>
<Skeleton className="h-20 w-full" />
</CardContent>
</Card>
</div>
</div>
</>
);
}

View file

@ -0,0 +1,34 @@
"use client";
import { ArrowLeft, FileWarning } from "lucide-react";
import Link from "next/link";
import { Button } from "@/components/ui/button";
interface AutomationNotFoundProps {
searchSpaceId: number;
error?: Error | null;
}
/**
* Rendered when the detail fetch fails (404 / 403 / network) or the id
* is not a number. We don't distinguish "missing" from "forbidden" in the
* UI on purpose leaking that an id exists you can't read is worse than
* a vague message.
*/
export function AutomationNotFound({ searchSpaceId, error }: AutomationNotFoundProps) {
return (
<div className="rounded-lg border border-border/60 bg-muted/20 px-6 py-12 text-center">
<FileWarning className="mx-auto h-10 w-10 text-muted-foreground" aria-hidden />
<h2 className="mt-3 text-base font-semibold text-foreground">Automation not found</h2>
<p className="mt-1 text-sm text-muted-foreground max-w-md mx-auto">
This automation doesn't exist or you don't have access to it.
{error?.message ? ` (${error.message})` : null}
</p>
<Button asChild variant="outline" size="sm" className="mt-6">
<Link href={`/dashboard/${searchSpaceId}/automations`}>
<ArrowLeft className="mr-2 h-4 w-4" />
Back to automations
</Link>
</Button>
</div>
);
}

View file

@ -0,0 +1,67 @@
"use client";
import { History } from "lucide-react";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { useAutomationRuns } from "@/hooks/use-automation-runs";
import { RunRow } from "./run-row";
import { RunsLoading } from "./runs-loading";
interface AutomationRunsSectionProps {
automationId: number;
}
const LIMIT = 20;
/**
* Run history card. Shows the most recent ``LIMIT`` runs; pagination is
* intentionally deferred for the foreseeable v1 surface (one-trigger
* automations firing daily), 20 covers ~3 weeks of history which is
* enough to tell whether things are working. Real "load more" lands if
* we see usage spike past that.
*/
export function AutomationRunsSection({ automationId }: AutomationRunsSectionProps) {
const { data, isLoading, error } = useAutomationRuns(automationId, { limit: LIMIT });
const runs = data?.items ?? [];
return (
<Card className="border-border/60 bg-accent">
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-4">
<div className="space-y-1">
<CardTitle className="text-base font-semibold inline-flex items-center gap-2">
<History className="h-4 w-4 text-muted-foreground" aria-hidden />
Recent runs
</CardTitle>
<p className="text-xs text-muted-foreground">
Most recent first. Click a row to inspect step results, output and artifacts.
</p>
</div>
{!isLoading && !error && data && (
<span className="text-xs text-muted-foreground">{data.total} total</span>
)}
</CardHeader>
<CardContent>
{isLoading ? (
<RunsLoading />
) : error ? (
<p className="text-sm text-muted-foreground">
Couldn't load runs{error.message ? `: ${error.message}` : "."}
</p>
) : runs.length === 0 ? (
<div className="rounded-md border border-dashed border-border/60 bg-muted/20 px-4 py-8 text-center">
<History className="mx-auto h-8 w-8 text-muted-foreground" aria-hidden />
<p className="mt-2 text-sm font-medium text-foreground">No runs yet</p>
<p className="mt-1 text-xs text-muted-foreground">
This automation hasn't fired. Once a trigger fires (or you invoke it manually), runs
will appear here.
</p>
</div>
) : (
<div className="space-y-2">
{runs.map((run) => (
<RunRow key={run.id} run={run} automationId={automationId} />
))}
</div>
)}
</CardContent>
</Card>
);
}

View file

@ -0,0 +1,58 @@
"use client";
import { CalendarClock } from "lucide-react";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import type { Trigger } from "@/contracts/types/automation.types";
import { TriggerCard } from "./trigger-card";
interface AutomationTriggersSectionProps {
triggers: Trigger[];
automationId: number;
canUpdate: boolean;
canDelete: boolean;
}
/**
* The Triggers card. Lists each attached trigger with its own enable
* toggle and remove button. v1 attaches triggers at automation-creation
* time only; there is no in-place "add trigger" affordance here.
*/
export function AutomationTriggersSection({
triggers,
automationId,
canUpdate,
canDelete,
}: AutomationTriggersSectionProps) {
return (
<Card className="border-border/60 bg-accent">
<CardHeader className="pb-4">
<CardTitle className="text-base font-semibold">Triggers</CardTitle>
<p className="text-xs text-muted-foreground">
When this automation fires. v1 supports scheduled triggers only.
</p>
</CardHeader>
<CardContent>
{triggers.length === 0 ? (
<div className="rounded-md border border-dashed border-border/60 bg-muted/20 px-4 py-8 text-center">
<CalendarClock className="mx-auto h-8 w-8 text-muted-foreground" aria-hidden />
<p className="mt-2 text-sm font-medium text-foreground">No triggers attached</p>
<p className="mt-1 text-xs text-muted-foreground">
This automation can still be invoked, but nothing will fire it on its own.
</p>
</div>
) : (
<div className="space-y-3">
{triggers.map((trigger) => (
<TriggerCard
key={trigger.id}
trigger={trigger}
automationId={automationId}
canUpdate={canUpdate}
canDelete={canDelete}
/>
))}
</div>
)}
</CardContent>
</Card>
);
}

View file

@ -0,0 +1,80 @@
"use client";
import { useAtomValue } from "jotai";
import { useState } from "react";
import { removeTriggerMutationAtom } from "@/atoms/automations/automations-mutation.atoms";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { Spinner } from "@/components/ui/spinner";
interface DeleteTriggerDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
automationId: number;
triggerId: number;
triggerLabel: string;
}
/**
* Confirm + detach one trigger from its automation. The automation itself
* is untouched; only this trigger row is removed. The mutation atom
* invalidates the parent automation detail so the page rerenders.
*/
export function DeleteTriggerDialog({
open,
onOpenChange,
automationId,
triggerId,
triggerLabel,
}: DeleteTriggerDialogProps) {
const { mutateAsync: removeTrigger } = useAtomValue(removeTriggerMutationAtom);
const [submitting, setSubmitting] = useState(false);
async function handleConfirm() {
setSubmitting(true);
try {
await removeTrigger({ automationId, triggerId });
onOpenChange(false);
} finally {
setSubmitting(false);
}
}
return (
<AlertDialog open={open} onOpenChange={onOpenChange}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Remove this trigger?</AlertDialogTitle>
<AlertDialogDescription>
<span className="font-medium text-foreground">{triggerLabel}</span> will be detached.
The automation itself stays, but it won't fire on this trigger anymore.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel disabled={submitting}>Cancel</AlertDialogCancel>
<AlertDialogAction
onClick={handleConfirm}
disabled={submitting}
className="bg-destructive text-white hover:bg-destructive/90"
>
{submitting ? (
<span className="inline-flex items-center gap-2">
<Spinner size="xs" />
Removing
</span>
) : (
"Remove"
)}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
}

View file

@ -0,0 +1,37 @@
"use client";
import type { Execution } from "@/contracts/types/automation.types";
interface ExecutionSummaryProps {
execution: Execution;
}
/**
* Compact view of an automation's execution defaults (wall-clock cap,
* retries, backoff, concurrency, on_failure presence). Per-step overrides
* are shown inside each PlanStepCard, not here.
*/
export function ExecutionSummary({ execution }: ExecutionSummaryProps) {
return (
<dl className="grid grid-cols-2 md:grid-cols-4 gap-x-6 gap-y-2 text-xs">
<Item label="Timeout" value={`${execution.timeout_seconds}s`} />
<Item label="Max retries" value={String(execution.max_retries)} />
<Item label="Retry backoff" value={execution.retry_backoff} />
<Item label="Concurrency" value={execution.concurrency} />
{execution.on_failure.length > 0 && (
<Item
label="On failure"
value={`${execution.on_failure.length} step${execution.on_failure.length === 1 ? "" : "s"}`}
/>
)}
</dl>
);
}
function Item({ label, value }: { label: string; value: string }) {
return (
<div className="flex flex-col gap-0.5 min-w-0">
<dt className="text-muted-foreground">{label}</dt>
<dd className="text-foreground font-medium truncate">{value}</dd>
</div>
);
}

View file

@ -0,0 +1,21 @@
"use client";
import { JsonView } from "@/components/json-view";
import type { Inputs } from "@/contracts/types/automation.types";
interface InputsSchemaPreviewProps {
inputs: Inputs;
}
/**
* Read-only preview of an automation's accepted-inputs schema. Most
* automations don't define inputs (defaults are baked into the trigger's
* static_inputs), so the parent skips rendering this card when ``inputs``
* is null.
*/
export function InputsSchemaPreview({ inputs }: InputsSchemaPreviewProps) {
return (
<div className="rounded-md bg-muted/40 px-3 py-2 max-h-72 overflow-auto">
<JsonView src={inputs.schema} collapsed={2} />
</div>
);
}

View file

@ -0,0 +1,74 @@
"use client";
import { ArrowRightCircle, GitCommitHorizontal } from "lucide-react";
import { JsonView } from "@/components/json-view";
import type { PlanStep } from "@/contracts/types/automation.types";
interface PlanStepCardProps {
step: PlanStep;
index: number;
}
/**
* Read-only view of one plan step. Renders the step_id + action prominently,
* then a definition list of the per-step knobs, and finally the params as
* formatted JSON. Editable mode is out of scope here definition edits live
* on the (future) raw-JSON path.
*/
export function PlanStepCard({ step, index }: PlanStepCardProps) {
return (
<div className="rounded-md border border-border/60 overflow-hidden">
<div className="flex items-center gap-2 px-4 py-2 border-b border-border/60 bg-muted/30">
<span className="inline-flex h-6 w-6 items-center justify-center rounded-full bg-muted text-xs font-medium text-muted-foreground">
{index + 1}
</span>
<span className="text-sm font-medium text-foreground">{step.step_id}</span>
<ArrowRightCircle className="h-3.5 w-3.5 text-muted-foreground" aria-hidden />
<span className="text-xs font-mono text-muted-foreground">{step.action}</span>
</div>
<div className="px-4 py-3 space-y-3">
{(step.when ||
step.output_as ||
step.max_retries != null ||
step.timeout_seconds != null) && (
<dl className="grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5 text-xs">
{step.when && (
<DefRow label="When" value={<code className="font-mono">{step.when}</code>} />
)}
{step.output_as && (
<DefRow
label="Output as"
value={<code className="font-mono">{step.output_as}</code>}
/>
)}
{step.max_retries != null && (
<DefRow label="Max retries" value={String(step.max_retries)} />
)}
{step.timeout_seconds != null && (
<DefRow label="Timeout" value={`${step.timeout_seconds}s`} />
)}
</dl>
)}
<div>
<div className="flex items-center gap-1.5 text-xs font-medium text-muted-foreground mb-1.5">
<GitCommitHorizontal className="h-3.5 w-3.5" aria-hidden />
Params
</div>
<div className="rounded-md bg-muted/40 px-3 py-2 overflow-auto">
<JsonView src={step.params} collapsed={1} />
</div>
</div>
</div>
</div>
);
}
function DefRow({ label, value }: { label: string; value: React.ReactNode }) {
return (
<div className="flex items-baseline gap-2 min-w-0">
<dt className="text-muted-foreground shrink-0">{label}:</dt>
<dd className="text-foreground min-w-0 truncate">{value}</dd>
</div>
);
}

View file

@ -0,0 +1,117 @@
"use client";
import { AlertCircle, FileOutput, GitCommitHorizontal, Package, Settings2 } from "lucide-react";
import { JsonView } from "@/components/json-view";
import { Skeleton } from "@/components/ui/skeleton";
import { useAutomationRun } from "@/hooks/use-automation-runs";
interface RunDetailsPanelProps {
automationId: number;
runId: number;
}
/**
* Expanded view of a single run. Fetches lazily the parent only renders
* this once the row is opened, so the list view stays cheap.
*
* We surface the four most actionable sections (error first when present,
* then output, step results, artifacts, inputs). The full
* ``definition_snapshot`` is omitted because it usually mirrors the live
* definition surfacing it would dominate the panel without informing
* what the user is trying to learn ("did this work? what did it do?").
*/
export function RunDetailsPanel({ automationId, runId }: RunDetailsPanelProps) {
const { data: run, isLoading, error } = useAutomationRun(automationId, runId);
if (isLoading) {
return (
<div className="space-y-3 p-4 bg-muted/20 border-t border-border/60">
<Skeleton className="h-3 w-32" />
<Skeleton className="h-24 w-full" />
</div>
);
}
if (error || !run) {
return (
<div className="p-4 bg-muted/20 border-t border-border/60 text-xs text-muted-foreground">
Couldn't load run details{error?.message ? `: ${error.message}` : "."}
</div>
);
}
const hasError = run.error && Object.keys(run.error).length > 0;
const hasOutput = run.output && Object.keys(run.output).length > 0;
const hasInputs = Object.keys(run.inputs ?? {}).length > 0;
return (
<div className="space-y-4 p-4 bg-muted/20 border-t border-border/60">
{hasError && (
<Section icon={AlertCircle} label="Error" tone="destructive">
<JsonBlock value={run.error} />
</Section>
)}
{hasOutput && (
<Section icon={FileOutput} label="Output">
<JsonBlock value={run.output} />
</Section>
)}
<Section icon={GitCommitHorizontal} label={`Step results · ${run.step_results.length}`}>
{run.step_results.length === 0 ? (
<p className="text-xs text-muted-foreground">No steps recorded.</p>
) : (
<JsonBlock value={run.step_results} />
)}
</Section>
{run.artifacts.length > 0 && (
<Section icon={Package} label={`Artifacts · ${run.artifacts.length}`}>
<JsonBlock value={run.artifacts} />
</Section>
)}
{hasInputs && (
<Section icon={Settings2} label="Resolved inputs">
<JsonBlock value={run.inputs} />
</Section>
)}
</div>
);
}
function Section({
icon: Icon,
label,
tone = "default",
children,
}: {
icon: typeof AlertCircle;
label: string;
tone?: "default" | "destructive";
children: React.ReactNode;
}) {
return (
<div className="space-y-1.5">
<div
className={
tone === "destructive"
? "flex items-center gap-1.5 text-[11px] font-medium text-destructive uppercase tracking-wider"
: "flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider"
}
>
<Icon className="h-3 w-3" aria-hidden />
{label}
</div>
{children}
</div>
);
}
function JsonBlock({ value }: { value: unknown }) {
return (
<div className="rounded-md bg-muted/40 px-3 py-2 max-h-64 overflow-auto">
<JsonView src={value} collapsed={1} />
</div>
);
}

View file

@ -0,0 +1,75 @@
"use client";
import { ChevronDown, ChevronRight, Hand } from "lucide-react";
import { useState } from "react";
import type { RunSummary } from "@/contracts/types/automation.types";
import { formatRelativeDate } from "@/lib/format-date";
import { RunDetailsPanel } from "./run-details-panel";
import { RunStatusBadge } from "./run-status-badge";
interface RunRowProps {
run: RunSummary;
automationId: number;
}
/**
* One run row. Click to expand fetches the full run and shows the
* details panel inline. State is local to each row so multiple panels
* can be open at once (or none).
*/
export function RunRow({ run, automationId }: RunRowProps) {
const [open, setOpen] = useState(false);
const duration = computeDuration(run.started_at, run.finished_at);
const startedLabel = run.started_at
? formatRelativeDate(run.started_at)
: formatRelativeDate(run.created_at);
return (
<div className="rounded-md border border-border/60 overflow-hidden">
<button
type="button"
onClick={() => setOpen((value) => !value)}
className="flex w-full items-center justify-between gap-4 px-4 py-3 text-left hover:bg-muted/30 transition-colors"
aria-expanded={open}
>
<div className="flex items-center gap-3 min-w-0">
{open ? (
<ChevronDown className="h-4 w-4 text-muted-foreground shrink-0" aria-hidden />
) : (
<ChevronRight className="h-4 w-4 text-muted-foreground shrink-0" aria-hidden />
)}
<RunStatusBadge status={run.status} />
<span className="text-xs text-muted-foreground truncate">{startedLabel}</span>
</div>
<div className="flex items-center gap-3 shrink-0 text-xs text-muted-foreground">
{duration && <span className="font-mono">{duration}</span>}
<TriggerSource triggerId={run.trigger_id ?? null} />
</div>
</button>
{open && <RunDetailsPanel automationId={automationId} runId={run.id} />}
</div>
);
}
function TriggerSource({ triggerId }: { triggerId: number | null }) {
if (triggerId == null) {
return (
<span className="inline-flex items-center gap-1">
<Hand className="h-3 w-3" aria-hidden />
Manual
</span>
);
}
return <span>via trigger #{triggerId}</span>;
}
function computeDuration(started: string | null | undefined, finished: string | null | undefined) {
if (!started || !finished) return null;
const ms = new Date(finished).getTime() - new Date(started).getTime();
if (!Number.isFinite(ms) || ms < 0) return null;
if (ms < 1000) return `${ms}ms`;
if (ms < 60_000) return `${(ms / 1000).toFixed(1)}s`;
const minutes = Math.floor(ms / 60_000);
const seconds = Math.floor((ms % 60_000) / 1000);
return `${minutes}m ${seconds}s`;
}

View file

@ -0,0 +1,57 @@
"use client";
import { AlertCircle, CheckCircle2, Clock, Loader2, TimerOff, XCircle } from "lucide-react";
import type { RunStatus } from "@/contracts/types/automation.types";
import { cn } from "@/lib/utils";
const STATUS_STYLES: Record<
RunStatus,
{ label: string; icon: typeof CheckCircle2; classes: string; spin?: boolean }
> = {
pending: {
label: "Pending",
icon: Clock,
classes: "bg-muted text-muted-foreground border-border/60",
},
running: {
label: "Running",
icon: Loader2,
classes: "bg-blue-500/10 text-blue-600 border-blue-500/20",
spin: true,
},
succeeded: {
label: "Succeeded",
icon: CheckCircle2,
classes: "bg-emerald-500/10 text-emerald-600 border-emerald-500/20",
},
failed: {
label: "Failed",
icon: XCircle,
classes: "bg-destructive/10 text-destructive border-destructive/20",
},
cancelled: {
label: "Cancelled",
icon: AlertCircle,
classes: "bg-muted text-muted-foreground border-border/60",
},
timed_out: {
label: "Timed out",
icon: TimerOff,
classes: "bg-amber-500/10 text-amber-600 border-amber-500/20",
},
};
export function RunStatusBadge({ status, className }: { status: RunStatus; className?: string }) {
const { label, icon: Icon, classes, spin } = STATUS_STYLES[status];
return (
<span
className={cn(
"inline-flex items-center gap-1.5 rounded-md border px-2 py-0.5 text-xs font-medium",
classes,
className
)}
>
<Icon className={cn("h-3 w-3", spin && "animate-spin")} aria-hidden />
{label}
</span>
);
}

View file

@ -0,0 +1,23 @@
"use client";
import { Skeleton } from "@/components/ui/skeleton";
const ROW_KEYS = ["a", "b", "c"] as const;
export function RunsLoading() {
return (
<div className="space-y-2">
{ROW_KEYS.map((key) => (
<div
key={key}
className="flex items-center justify-between gap-4 rounded-md border border-border/60 px-4 py-3"
>
<div className="flex items-center gap-3">
<Skeleton className="h-5 w-20 rounded-md" />
<Skeleton className="h-3 w-32" />
</div>
<Skeleton className="h-3 w-16" />
</div>
))}
</div>
);
}

View file

@ -0,0 +1,274 @@
"use client";
import { useAtomValue } from "jotai";
import { AlertCircle, CalendarClock, Clock, Pencil, Save, Trash2 } from "lucide-react";
import { useState } from "react";
import { updateTriggerMutationAtom } from "@/atoms/automations/automations-mutation.atoms";
import { JsonView } from "@/components/json-view";
import { Button } from "@/components/ui/button";
import { Spinner } from "@/components/ui/spinner";
import { Switch } from "@/components/ui/switch";
import { type Trigger, triggerUpdateRequest } from "@/contracts/types/automation.types";
import { describeCron } from "@/lib/automations/describe-cron";
import { formatRelativeDate, formatRelativeFutureDate } from "@/lib/format-date";
import { DeleteTriggerDialog } from "./delete-trigger-dialog";
interface TriggerCardProps {
trigger: Trigger;
automationId: number;
canUpdate: boolean;
canDelete: boolean;
}
interface TriggerDraft {
params: Record<string, unknown>;
static_inputs: Record<string, unknown>;
}
function draftFromTrigger(trigger: Trigger): TriggerDraft {
return {
params: trigger.params,
static_inputs: trigger.static_inputs ?? {},
};
}
/**
* One trigger row in the Triggers section of the detail page. Renders:
* - type icon + human-readable schedule + timezone
* - last_fired_at / next_fire_at hints
* - static_inputs as formatted JSON (when present)
* - enable toggle + remove button + inline edit (each gated independently)
*
* Inline edit covers ``params`` and ``static_inputs`` the two fields the
* backend ``PATCH /triggers/[id]`` endpoint accepts beyond ``enabled``.
* ``enabled`` stays on the Switch so the two surfaces don't fight.
*/
export function TriggerCard({ trigger, automationId, canUpdate, canDelete }: TriggerCardProps) {
const { mutateAsync: updateTrigger, isPending: updating } =
useAtomValue(updateTriggerMutationAtom);
const [deleteOpen, setDeleteOpen] = useState(false);
const [isEditing, setIsEditing] = useState(false);
const [draft, setDraft] = useState<TriggerDraft>(() => draftFromTrigger(trigger));
const [issues, setIssues] = useState<string[]>([]);
const cron = typeof trigger.params.cron === "string" ? trigger.params.cron : undefined;
const tz = typeof trigger.params.timezone === "string" ? trigger.params.timezone : "UTC";
const human = cron ? describeCron(cron) : trigger.type;
const triggerLabel = cron ? `${human} · ${tz}` : trigger.type;
const hasStaticInputs = Object.keys(trigger.static_inputs ?? {}).length > 0;
async function handleToggle(checked: boolean) {
await updateTrigger({
automationId,
triggerId: trigger.id,
patch: { enabled: checked },
});
}
function startEdit() {
setDraft(draftFromTrigger(trigger));
setIssues([]);
setIsEditing(true);
}
function cancelEdit() {
setIsEditing(false);
setIssues([]);
}
async function saveEdit() {
setIssues([]);
const result = triggerUpdateRequest.safeParse(draft);
if (!result.success) {
setIssues(
result.error.issues.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`)
);
return;
}
try {
await updateTrigger({
automationId,
triggerId: trigger.id,
patch: result.data,
});
setIsEditing(false);
} catch (err) {
setIssues([(err as Error).message ?? "Update failed"]);
}
}
return (
<>
<div className="rounded-md border border-border/60 overflow-hidden">
<div className="flex items-center justify-between gap-4 px-4 py-3 border-b border-border/60">
<div className="flex items-center gap-3 min-w-0">
<CalendarClock className="h-4 w-4 text-muted-foreground shrink-0" aria-hidden />
<div className="min-w-0">
<div className="flex items-center gap-2 text-sm">
<span className="font-medium text-foreground">{human}</span>
<span className="text-muted-foreground">· {tz}</span>
</div>
{cron && <code className="text-xs font-mono text-muted-foreground">{cron}</code>}
</div>
</div>
<div className="flex items-center gap-2 shrink-0">
{canUpdate && (
<div className="flex items-center gap-2">
<span className="text-xs text-muted-foreground">
{trigger.enabled ? "Enabled" : "Off"}
</span>
<Switch
checked={trigger.enabled}
onCheckedChange={handleToggle}
disabled={updating || isEditing}
aria-label={trigger.enabled ? "Disable trigger" : "Enable trigger"}
/>
</div>
)}
{canUpdate && !isEditing && (
<Button
variant="ghost"
size="icon"
className="h-8 w-8 text-muted-foreground"
onClick={startEdit}
aria-label="Edit trigger"
>
<Pencil className="h-4 w-4" />
</Button>
)}
{canDelete && (
<Button
variant="ghost"
size="icon"
className="h-8 w-8 text-muted-foreground hover:text-destructive"
onClick={() => setDeleteOpen(true)}
disabled={isEditing}
aria-label="Remove trigger"
>
<Trash2 className="h-4 w-4" />
</Button>
)}
</div>
</div>
<div className="px-4 py-3 space-y-3 text-xs">
{isEditing ? (
<>
<div className="rounded-md border border-input bg-background px-3 py-2 max-h-[24rem] overflow-auto">
<JsonView
src={draft}
editable
onChange={(next) => setDraft(next as TriggerDraft)}
collapsed={false}
/>
</div>
{issues.length > 0 && (
<div className="rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2">
<div className="flex items-center gap-1.5 font-medium text-destructive mb-1">
<AlertCircle className="h-3 w-3" aria-hidden />
{issues.length === 1 ? "1 issue" : `${issues.length} issues`}
</div>
<ul className="space-y-0.5 text-destructive list-disc list-inside">
{issues.map((issue) => (
<li key={issue}>{issue}</li>
))}
</ul>
</div>
)}
<div className="flex items-center justify-end gap-2">
<Button
type="button"
variant="ghost"
size="sm"
onClick={cancelEdit}
disabled={updating}
>
Cancel
</Button>
<Button type="button" size="sm" onClick={saveEdit} disabled={updating}>
{updating ? (
<Spinner size="xs" className="mr-1.5" />
) : (
<Save className="mr-1.5 h-3.5 w-3.5" />
)}
Save
</Button>
</div>
</>
) : (
<>
{(trigger.last_fired_at || trigger.next_fire_at) && (
<dl className="grid grid-cols-[auto_minmax(0,1fr)] items-baseline gap-x-3 gap-y-1">
{trigger.next_fire_at && (
<TimeRow
label="Next fire"
iso={trigger.next_fire_at}
tense="future"
highlight={trigger.enabled}
/>
)}
{trigger.last_fired_at && (
<TimeRow label="Last fired" iso={trigger.last_fired_at} tense="past" />
)}
</dl>
)}
{hasStaticInputs && (
<div>
<div className="text-muted-foreground mb-1">Static inputs</div>
<div className="rounded-md bg-muted/40 px-3 py-2 overflow-auto">
<JsonView src={trigger.static_inputs} collapsed={1} />
</div>
</div>
)}
</>
)}
</div>
</div>
{canDelete && (
<DeleteTriggerDialog
open={deleteOpen}
onOpenChange={setDeleteOpen}
automationId={automationId}
triggerId={trigger.id}
triggerLabel={triggerLabel}
/>
)}
</>
);
}
function TimeRow({
label,
iso,
tense,
highlight = false,
}: {
label: string;
iso: string;
tense: "past" | "future";
highlight?: boolean;
}) {
const formatted = tense === "future" ? formatRelativeFutureDate(iso) : formatRelativeDate(iso);
return (
<>
<dt className="text-muted-foreground inline-flex items-center gap-1.5 whitespace-nowrap">
<Clock className="h-3 w-3" aria-hidden />
{label}
</dt>
<dd
className={
highlight
? "text-foreground font-medium min-w-0 truncate"
: "text-muted-foreground min-w-0 truncate"
}
title={new Date(iso).toLocaleString()}
>
{formatted}
</dd>
</>
);
}

View file

@ -0,0 +1,56 @@
"use client";
import { ShieldAlert } from "lucide-react";
import { useAutomation } from "@/hooks/use-automation";
import { useAutomationPermissions } from "../../hooks/use-automation-permissions";
import { AutomationDetailLoading } from "../components/automation-detail-loading";
import { AutomationNotFound } from "../components/automation-not-found";
import { AutomationEditForm } from "./components/automation-edit-form";
interface AutomationEditContentProps {
searchSpaceId: number;
automationId: number;
}
/**
* Client orchestrator for the edit route. Mirrors detail-content's branch
* structure but gates on ``canUpdate`` instead of ``canRead``: a user who
* can read but not update is bounced to the access-denied panel.
*/
export function AutomationEditContent({
searchSpaceId,
automationId,
}: AutomationEditContentProps) {
const perms = useAutomationPermissions();
const validId = Number.isInteger(automationId) && automationId > 0;
const { data: automation, isLoading, error } = useAutomation(validId ? automationId : undefined);
if (perms.loading) {
return <AutomationDetailLoading />;
}
if (!perms.canUpdate) {
return (
<div className="rounded-lg border border-border/60 bg-muted/20 px-6 py-12 text-center">
<ShieldAlert className="mx-auto h-10 w-10 text-muted-foreground" aria-hidden />
<h2 className="mt-3 text-base font-semibold text-foreground">Access denied</h2>
<p className="mt-1 text-sm text-muted-foreground max-w-md mx-auto">
You don't have permission to edit automations in this search space.
</p>
</div>
);
}
if (!validId) {
return <AutomationNotFound searchSpaceId={searchSpaceId} />;
}
if (isLoading) {
return <AutomationDetailLoading />;
}
if (error || !automation) {
return <AutomationNotFound searchSpaceId={searchSpaceId} error={error} />;
}
return <AutomationEditForm automation={automation} searchSpaceId={searchSpaceId} />;
}

View file

@ -0,0 +1,121 @@
"use client";
import { useAtomValue } from "jotai";
import { AlertCircle, ArrowLeft, Save } from "lucide-react";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { updateAutomationMutationAtom } from "@/atoms/automations/automations-mutation.atoms";
import { JsonView } from "@/components/json-view";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Spinner } from "@/components/ui/spinner";
import {
type Automation,
automationUpdateRequest,
} from "@/contracts/types/automation.types";
interface AutomationEditFormProps {
automation: Automation;
searchSpaceId: number;
}
/**
* Edit-existing-automation form. Surfaces the four mutable fields
* (name, description, status, definition) as one editable JSON tree;
* triggers stay on the detail page where they have their own management
* UI. Validates with the same Zod schema the API expects, then PATCHes
* the changed shape back.
*/
export function AutomationEditForm({ automation, searchSpaceId }: AutomationEditFormProps) {
const router = useRouter();
const { mutateAsync: updateAutomation, isPending } = useAtomValue(updateAutomationMutationAtom);
const detailHref = `/dashboard/${searchSpaceId}/automations/${automation.id}`;
const [value, setValue] = useState(() => ({
name: automation.name,
description: automation.description ?? null,
status: automation.status,
definition: automation.definition,
}));
const [issues, setIssues] = useState<string[]>([]);
async function handleSave() {
setIssues([]);
const result = automationUpdateRequest.safeParse(value);
if (!result.success) {
setIssues(
result.error.issues.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`)
);
return;
}
try {
await updateAutomation({ automationId: automation.id, patch: result.data });
router.push(detailHref);
} catch (err) {
setIssues([(err as Error).message ?? "Update failed"]);
}
}
return (
<>
<div className="space-y-3">
<Button asChild variant="ghost" size="sm" className="-ml-2 h-auto px-2 py-1">
<Link href={detailHref} className="text-xs text-muted-foreground">
<ArrowLeft className="mr-1.5 h-3.5 w-3.5" />
Back to automation
</Link>
</Button>
<div>
<h1 className="text-xl md:text-2xl font-semibold text-foreground break-words">
Edit automation
</h1>
<p className="text-sm text-muted-foreground mt-1">{automation.name}</p>
</div>
</div>
<Card className="border-border/60 bg-accent">
<CardHeader className="pb-4">
<CardTitle className="text-base font-semibold">Definition</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
<div className="rounded-md border border-input bg-background px-3 py-2 max-h-[36rem] overflow-auto">
<JsonView
src={value}
editable
onChange={(next) => setValue(next as typeof value)}
collapsed={false}
/>
</div>
{issues.length > 0 && (
<div className="rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2">
<div className="flex items-center gap-1.5 text-xs font-medium text-destructive mb-1.5">
<AlertCircle className="h-3.5 w-3.5" aria-hidden />
{issues.length === 1 ? "1 issue" : `${issues.length} issues`}
</div>
<ul className="space-y-0.5 text-xs text-destructive list-disc list-inside">
{issues.map((issue) => (
<li key={issue}>{issue}</li>
))}
</ul>
</div>
)}
<div className="flex items-center justify-end gap-2">
<Button asChild type="button" variant="ghost" size="sm">
<Link href={detailHref}>Cancel</Link>
</Button>
<Button type="button" onClick={handleSave} disabled={isPending} size="sm">
{isPending ? (
<Spinner size="xs" className="mr-2" />
) : (
<Save className="mr-2 h-4 w-4" />
)}
Save changes
</Button>
</div>
</CardContent>
</Card>
</>
);
}

View file

@ -0,0 +1,18 @@
import { AutomationEditContent } from "./automation-edit-content";
export default async function AutomationEditPage({
params,
}: {
params: Promise<{ search_space_id: string; automation_id: string }>;
}) {
const { search_space_id, automation_id } = await params;
return (
<div className="w-full space-y-6">
<AutomationEditContent
searchSpaceId={Number(search_space_id)}
automationId={Number(automation_id)}
/>
</div>
);
}

View file

@ -0,0 +1,18 @@
import { AutomationDetailContent } from "./automation-detail-content";
export default async function AutomationDetailPage({
params,
}: {
params: Promise<{ search_space_id: string; automation_id: string }>;
}) {
const { search_space_id, automation_id } = await params;
return (
<div className="w-full space-y-6">
<AutomationDetailContent
searchSpaceId={Number(search_space_id)}
automationId={Number(automation_id)}
/>
</div>
);
}

View file

@ -0,0 +1,102 @@
"use client";
import { ShieldAlert } from "lucide-react";
import { useAutomations } from "@/hooks/use-automations";
import { AutomationsEmptyState } from "./components/automations-empty-state";
import { AutomationsHeader } from "./components/automations-header";
import { AutomationsTable } from "./components/automations-table";
import { useAutomationPermissions } from "./hooks/use-automation-permissions";
interface AutomationsContentProps {
searchSpaceId: number;
}
/**
* Client orchestrator for the automations list page. Pulls the active
* search space's first page (via ``useAutomations`` ``automationsListAtom``)
* and the user's permissions, then decides between empty / loading / table.
*
* Read access is mandatory; anything else is hidden behind RBAC. The
* permissions hook is co-located in this slice so adding/removing
* surfaces is a one-file change.
*/
export function AutomationsContent({ searchSpaceId }: AutomationsContentProps) {
const { automations, total, loading, error } = useAutomations();
const perms = useAutomationPermissions();
if (perms.loading) {
// Permissions gate the entire page; defer everything until we know.
return (
<>
<AutomationsHeader searchSpaceId={searchSpaceId} total={0} loading canCreate={false} />
<AutomationsTable
automations={[]}
searchSpaceId={searchSpaceId}
loading
canUpdate={false}
canDelete={false}
/>
</>
);
}
if (!perms.canRead) {
return (
<div className="rounded-lg border border-border/60 bg-muted/20 px-6 py-12 text-center">
<ShieldAlert className="mx-auto h-10 w-10 text-muted-foreground" aria-hidden />
<h2 className="mt-3 text-base font-semibold text-foreground">Access denied</h2>
<p className="mt-1 text-sm text-muted-foreground max-w-md mx-auto">
You don't have permission to view automations in this search space.
</p>
</div>
);
}
if (error) {
return (
<>
<AutomationsHeader
searchSpaceId={searchSpaceId}
total={0}
loading={false}
canCreate={perms.canCreate}
/>
<div className="rounded-lg border border-destructive/40 bg-destructive/5 px-6 py-8 text-center">
<p className="text-sm text-destructive">Couldn't load automations. {error.message}</p>
</div>
</>
);
}
if (!loading && automations.length === 0) {
return (
<>
<AutomationsHeader
searchSpaceId={searchSpaceId}
total={0}
loading={false}
canCreate={perms.canCreate}
showCreateCta={false}
/>
<AutomationsEmptyState searchSpaceId={searchSpaceId} canCreate={perms.canCreate} />
</>
);
}
return (
<>
<AutomationsHeader
searchSpaceId={searchSpaceId}
total={total}
loading={loading}
canCreate={perms.canCreate}
/>
<AutomationsTable
automations={automations}
searchSpaceId={searchSpaceId}
loading={loading}
canUpdate={perms.canUpdate}
canDelete={perms.canDelete}
/>
</>
);
}

View file

@ -0,0 +1,98 @@
"use client";
import { useAtomValue } from "jotai";
import { MoreHorizontal, Pause, Play, Trash2 } from "lucide-react";
import { useState } from "react";
import { updateAutomationMutationAtom } from "@/atoms/automations/automations-mutation.atoms";
import { Button } from "@/components/ui/button";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import type { AutomationSummary } from "@/contracts/types/automation.types";
import { DeleteAutomationDialog } from "./delete-automation-dialog";
interface AutomationRowActionsProps {
automation: AutomationSummary;
searchSpaceId: number;
canUpdate: boolean;
canDelete: boolean;
}
/**
* Three-dot menu on each row: pause/resume (if updatable) and delete
* (if deletable). The menu itself is hidden when the user has neither
* permission so we don't render an empty trigger.
*/
export function AutomationRowActions({
automation,
searchSpaceId,
canUpdate,
canDelete,
}: AutomationRowActionsProps) {
const { mutateAsync: updateAutomation, isPending: updating } = useAtomValue(
updateAutomationMutationAtom
);
const [deleteOpen, setDeleteOpen] = useState(false);
if (!canUpdate && !canDelete) return null;
const nextStatus = automation.status === "active" ? "paused" : "active";
const pauseLabel = automation.status === "active" ? "Pause" : "Resume";
const PauseIcon = automation.status === "active" ? Pause : Play;
const canToggle = canUpdate && automation.status !== "archived";
async function handleTogglePause() {
await updateAutomation({
automationId: automation.id,
patch: { status: nextStatus },
});
}
return (
<>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
size="icon"
className="h-8 w-8"
aria-label={`Actions for ${automation.name}`}
>
<MoreHorizontal className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-40">
{canToggle && (
<DropdownMenuItem onSelect={handleTogglePause} disabled={updating}>
<PauseIcon className="mr-2 h-4 w-4" />
{pauseLabel}
</DropdownMenuItem>
)}
{canToggle && canDelete && <DropdownMenuSeparator />}
{canDelete && (
<DropdownMenuItem
onSelect={() => setDeleteOpen(true)}
className="text-destructive focus:text-destructive"
>
<Trash2 className="mr-2 h-4 w-4" />
Delete
</DropdownMenuItem>
)}
</DropdownMenuContent>
</DropdownMenu>
{canDelete && (
<DeleteAutomationDialog
open={deleteOpen}
onOpenChange={setDeleteOpen}
automationId={automation.id}
automationName={automation.name}
searchSpaceId={searchSpaceId}
/>
)}
</>
);
}

View file

@ -0,0 +1,61 @@
"use client";
import Link from "next/link";
import { TableCell, TableRow } from "@/components/ui/table";
import type { AutomationSummary } from "@/contracts/types/automation.types";
import { formatRelativeDate } from "@/lib/format-date";
import { AutomationRowActions } from "./automation-row-actions";
import { AutomationStatusBadge } from "./automation-status-badge";
interface AutomationRowProps {
automation: AutomationSummary;
searchSpaceId: number;
canUpdate: boolean;
canDelete: boolean;
}
/**
* One row in the automations table. The name links to the detail page;
* actions are gated by ``canUpdate`` / ``canDelete``. Trigger summary
* is intentionally left to the detail page list responses don't
* include triggers and we want to avoid N+1 detail fetches.
*/
export function AutomationRow({
automation,
searchSpaceId,
canUpdate,
canDelete,
}: AutomationRowProps) {
return (
<TableRow className="border-b border-border/60 hover:bg-muted/40">
<TableCell className="px-4 md:px-6 py-3 border-r border-border/60">
<div className="flex flex-col gap-0.5 min-w-0">
<Link
href={`/dashboard/${searchSpaceId}/automations/${automation.id}`}
className="text-sm font-medium text-foreground hover:underline truncate"
>
{automation.name}
</Link>
{automation.description && (
<span className="text-xs text-muted-foreground line-clamp-1">
{automation.description}
</span>
)}
</div>
</TableCell>
<TableCell className="px-4 py-3 border-r border-border/60 w-32">
<AutomationStatusBadge status={automation.status} />
</TableCell>
<TableCell className="hidden md:table-cell px-4 py-3 border-r border-border/60 w-40 text-xs text-muted-foreground">
{formatRelativeDate(automation.updated_at)}
</TableCell>
<TableCell className="px-4 md:px-6 py-3 w-16 text-right">
<AutomationRowActions
automation={automation}
searchSpaceId={searchSpaceId}
canUpdate={canUpdate}
canDelete={canDelete}
/>
</TableCell>
</TableRow>
);
}

View file

@ -0,0 +1,49 @@
"use client";
import { Archive, CircleDot, Pause } from "lucide-react";
import type { AutomationStatus } from "@/contracts/types/automation.types";
import { cn } from "@/lib/utils";
interface AutomationStatusBadgeProps {
status: AutomationStatus;
className?: string;
}
// Color + icon per status. Active = green, paused = amber, archived = muted.
const STATUS_STYLES: Record<
AutomationStatus,
{ label: string; icon: typeof CircleDot; classes: string }
> = {
active: {
label: "Active",
icon: CircleDot,
classes:
"bg-emerald-50 text-emerald-700 border border-emerald-200 dark:bg-emerald-950/40 dark:text-emerald-300 dark:border-emerald-900/50",
},
paused: {
label: "Paused",
icon: Pause,
classes:
"bg-amber-50 text-amber-700 border border-amber-200 dark:bg-amber-950/40 dark:text-amber-300 dark:border-amber-900/50",
},
archived: {
label: "Archived",
icon: Archive,
classes: "bg-muted text-muted-foreground border border-border/60",
},
};
export function AutomationStatusBadge({ status, className }: AutomationStatusBadgeProps) {
const { label, icon: Icon, classes } = STATUS_STYLES[status];
return (
<span
className={cn(
"inline-flex items-center gap-1.5 rounded-md px-2 py-0.5 text-xs font-medium",
classes,
className
)}
>
<Icon className="h-3 w-3" aria-hidden />
{label}
</span>
);
}

View file

@ -0,0 +1,52 @@
"use client";
import { CalendarClock, Pause } from "lucide-react";
import type { Trigger } from "@/contracts/types/automation.types";
import { describeCron } from "@/lib/automations/describe-cron";
interface AutomationTriggersSummaryProps {
triggers: Trigger[];
}
/**
* One-line summary of an automation's triggers for the list view.
*
* v1 only registers ``schedule`` so this stays compact:
* - 0 triggers "No triggers"
* - 1 schedule trigger "MonFri at 09:00 · UTC" + disabled badge if off
* - >1 "N triggers"
*
* The detail page renders the full per-trigger editor.
*/
export function AutomationTriggersSummary({ triggers }: AutomationTriggersSummaryProps) {
if (triggers.length === 0) {
return <span className="text-xs text-muted-foreground">No triggers</span>;
}
if (triggers.length > 1) {
return <span className="text-xs text-muted-foreground">{triggers.length} triggers</span>;
}
const [trigger] = triggers;
if (trigger.type === "schedule") {
const cron = typeof trigger.params.cron === "string" ? trigger.params.cron : undefined;
const tz = typeof trigger.params.timezone === "string" ? trigger.params.timezone : "UTC";
const human = cron ? describeCron(cron) : "Schedule";
return (
<span className="inline-flex items-center gap-1.5 text-xs">
<CalendarClock className="h-3.5 w-3.5 text-muted-foreground" aria-hidden />
<span className="text-foreground">{human}</span>
<span className="text-muted-foreground">· {tz}</span>
{!trigger.enabled && (
<span className="inline-flex items-center gap-1 rounded-md border border-border/60 px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground">
<Pause className="h-2.5 w-2.5" aria-hidden />
Off
</span>
)}
</span>
);
}
return <span className="text-xs text-muted-foreground capitalize">{trigger.type}</span>;
}

View file

@ -0,0 +1,50 @@
"use client";
import { FileJson, MessageSquarePlus, Workflow } from "lucide-react";
import Link from "next/link";
import { Button } from "@/components/ui/button";
interface AutomationsEmptyStateProps {
searchSpaceId: number;
canCreate: boolean;
}
/**
* Zero-state for the automations list. The primary CTA points to a new
* chat creation happens via the ``create_automation`` HITL tool, not a
* "new automation" form. We surface the chat path explicitly so users
* don't go hunting for an "add" button that doesn't exist.
*/
export function AutomationsEmptyState({ searchSpaceId, canCreate }: AutomationsEmptyStateProps) {
return (
<div className="rounded-lg border border-dashed border-border/60 bg-muted/20 px-6 py-12 text-center">
<div className="mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-muted text-muted-foreground">
<Workflow className="h-6 w-6" aria-hidden />
</div>
<h3 className="mt-4 text-base font-semibold text-foreground">No automations yet</h3>
<p className="mt-1 text-sm text-muted-foreground max-w-md mx-auto">
Automations let SurfSense run agent tasks on a schedule. Describe what you want in chat and
SurfSense drafts the automation for your approval.
</p>
{canCreate ? (
<div className="mt-6 flex items-center justify-center gap-2 flex-wrap">
<Button asChild>
<Link href={`/dashboard/${searchSpaceId}/new-chat`}>
<MessageSquarePlus className="mr-2 h-4 w-4" />
Create via chat
</Link>
</Button>
<Button asChild variant="outline">
<Link href={`/dashboard/${searchSpaceId}/automations/new`}>
<FileJson className="mr-2 h-4 w-4" />
Create via JSON
</Link>
</Button>
</div>
) : (
<p className="mt-6 text-xs text-muted-foreground">
You don't have permission to create automations in this search space.
</p>
)}
</div>
);
}

View file

@ -0,0 +1,59 @@
"use client";
import { FileJson, MessageSquarePlus } from "lucide-react";
import Link from "next/link";
import { Button } from "@/components/ui/button";
interface AutomationsHeaderProps {
searchSpaceId: number;
total: number;
loading: boolean;
canCreate: boolean;
/**
* Render the header's Create CTA. Defaults to true; the empty state owns
* the primary CTA on its own card, so the orchestrator turns this off
* there to avoid a duplicate button.
*/
showCreateCta?: boolean;
}
/**
* Page header: title + count + "Create via chat" CTA. Creation is intent-driven
* (the create_automation tool runs inside chat with a HITL approval card), so
* the CTA links to a new chat rather than opening a form.
*/
export function AutomationsHeader({
searchSpaceId,
total,
loading,
canCreate,
showCreateCta = true,
}: AutomationsHeaderProps) {
return (
<div className="flex items-center justify-between gap-4 flex-wrap">
<div className="flex items-baseline gap-3">
<h1 className="text-xl md:text-2xl font-semibold text-foreground">Automations</h1>
{!loading && (
<span className="text-sm text-muted-foreground">
{total} {total === 1 ? "automation" : "automations"}
</span>
)}
</div>
{canCreate && showCreateCta && (
<div className="flex items-center gap-2">
<Button asChild size="sm" variant="outline">
<Link href={`/dashboard/${searchSpaceId}/automations/new`}>
<FileJson className="mr-2 h-4 w-4" />
Create via JSON
</Link>
</Button>
<Button asChild size="sm">
<Link href={`/dashboard/${searchSpaceId}/new-chat`}>
<MessageSquarePlus className="mr-2 h-4 w-4" />
Create via chat
</Link>
</Button>
</div>
)}
</div>
);
}

View file

@ -0,0 +1,36 @@
"use client";
import { Skeleton } from "@/components/ui/skeleton";
import { TableCell, TableRow } from "@/components/ui/table";
const ROW_KEYS = ["sk-1", "sk-2", "sk-3"];
/**
* Skeleton rows for the automations table. Number of rows is fixed since
* we don't know the count ahead of time and three placeholders is enough
* to communicate "loading" without flashing too much chrome.
*/
export function AutomationsLoadingRows() {
return (
<>
{ROW_KEYS.map((key) => (
<TableRow key={key} className="border-b border-border/60 hover:bg-transparent">
<TableCell className="px-4 md:px-6 py-3 border-r border-border/60">
<div className="flex flex-col gap-1.5">
<Skeleton className="h-4 w-40" />
<Skeleton className="h-3 w-56" />
</div>
</TableCell>
<TableCell className="px-4 py-3 border-r border-border/60 w-32">
<Skeleton className="h-5 w-16 rounded-md" />
</TableCell>
<TableCell className="hidden md:table-cell px-4 py-3 border-r border-border/60 w-40">
<Skeleton className="h-3 w-20" />
</TableCell>
<TableCell className="px-4 md:px-6 py-3 w-16">
<Skeleton className="h-8 w-8 rounded-md ml-auto" />
</TableCell>
</TableRow>
))}
</>
);
}

View file

@ -0,0 +1,73 @@
"use client";
import { Activity, CalendarDays, Workflow } from "lucide-react";
import { Table, TableBody, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import type { AutomationSummary } from "@/contracts/types/automation.types";
import { AutomationRow } from "./automation-row";
import { AutomationsLoadingRows } from "./automations-loading";
interface AutomationsTableProps {
automations: AutomationSummary[];
searchSpaceId: number;
loading: boolean;
canUpdate: boolean;
canDelete: boolean;
}
/**
* Table shell + header. Rows render below loading state renders skeleton
* rows in the same shell so the layout doesn't shift on data arrival.
*/
export function AutomationsTable({
automations,
searchSpaceId,
loading,
canUpdate,
canDelete,
}: AutomationsTableProps) {
return (
<div className="rounded-lg border border-border/60 bg-accent overflow-hidden">
<Table className="table-fixed w-full">
<TableHeader>
<TableRow className="hover:bg-transparent border-b border-border/60">
<TableHead className="px-4 md:px-6 border-r border-border/60">
<span className="flex items-center gap-1.5 text-sm font-medium text-muted-foreground/70">
<Workflow size={14} className="opacity-60 text-muted-foreground" />
Name
</span>
</TableHead>
<TableHead className="border-r border-border/60 w-32">
<span className="flex items-center gap-1.5 text-sm font-medium text-muted-foreground/70">
<Activity size={14} className="opacity-60 text-muted-foreground" />
Status
</span>
</TableHead>
<TableHead className="hidden md:table-cell border-r border-border/60 w-40">
<span className="flex items-center gap-1.5 text-sm font-medium text-muted-foreground/70">
<CalendarDays size={14} className="opacity-60 text-muted-foreground" />
Updated
</span>
</TableHead>
<TableHead className="px-4 md:px-6 w-16">
<span className="sr-only">Actions</span>
</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{loading ? (
<AutomationsLoadingRows />
) : (
automations.map((automation) => (
<AutomationRow
key={automation.id}
automation={automation}
searchSpaceId={searchSpaceId}
canUpdate={canUpdate}
canDelete={canDelete}
/>
))
)}
</TableBody>
</Table>
</div>
);
}

View file

@ -0,0 +1,88 @@
"use client";
import { useAtomValue } from "jotai";
import { useState } from "react";
import { deleteAutomationMutationAtom } from "@/atoms/automations/automations-mutation.atoms";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { Spinner } from "@/components/ui/spinner";
interface DeleteAutomationDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
automationId: number;
automationName: string;
searchSpaceId: number;
/**
* Fired after a successful delete, before the dialog closes. The detail
* page uses this to navigate back to the list (the row simply vanishes
* on the list page so no callback is needed there).
*/
onDeleted?: () => void;
}
/**
* Confirm + delete one automation. FK cascade on the backend wipes attached
* triggers and runs, so we mention it explicitly. List re-fetch is handled
* by the mutation atom's onSuccess.
*/
export function DeleteAutomationDialog({
open,
onOpenChange,
automationId,
automationName,
searchSpaceId,
onDeleted,
}: DeleteAutomationDialogProps) {
const { mutateAsync: deleteAutomation } = useAtomValue(deleteAutomationMutationAtom);
const [submitting, setSubmitting] = useState(false);
async function handleConfirm() {
setSubmitting(true);
try {
await deleteAutomation({ automationId, searchSpaceId });
onDeleted?.();
onOpenChange(false);
} finally {
setSubmitting(false);
}
}
return (
<AlertDialog open={open} onOpenChange={onOpenChange}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Delete this automation?</AlertDialogTitle>
<AlertDialogDescription>
<span className="font-medium text-foreground">{automationName}</span> and all of its
triggers and run history will be removed. This cannot be undone.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel disabled={submitting}>Cancel</AlertDialogCancel>
<AlertDialogAction
onClick={handleConfirm}
disabled={submitting}
className="bg-destructive text-white hover:bg-destructive/90"
>
{submitting ? (
<span className="inline-flex items-center gap-2">
<Spinner size="xs" />
Deleting
</span>
) : (
"Delete"
)}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
}

View file

@ -0,0 +1,37 @@
"use client";
import { useAtomValue } from "jotai";
import { useMemo } from "react";
import { canPerform, myAccessAtom } from "@/atoms/members/members-query.atoms";
/**
* Centralized RBAC gates for the automations slice. Co-located with the
* route so adding/removing surfaces stays a one-file change. Backed by
* the same ``myAccessAtom`` the rest of the app uses; owners short-circuit
* to ``true`` for every action.
*
* Mirrors backend permissions in ``app.db.permissions`` (automations:*).
*/
export interface AutomationPermissions {
loading: boolean;
canCreate: boolean;
canRead: boolean;
canUpdate: boolean;
canDelete: boolean;
canExecute: boolean;
}
export function useAutomationPermissions(): AutomationPermissions {
const { data: access, isLoading } = useAtomValue(myAccessAtom);
return useMemo(
() => ({
loading: isLoading,
canCreate: canPerform(access, "automations:create"),
canRead: canPerform(access, "automations:read"),
canUpdate: canPerform(access, "automations:update"),
canDelete: canPerform(access, "automations:delete"),
canExecute: canPerform(access, "automations:execute"),
}),
[access, isLoading]
);
}

View file

@ -0,0 +1,42 @@
"use client";
import { ShieldAlert } from "lucide-react";
import { useAutomationPermissions } from "../hooks/use-automation-permissions";
import { AutomationJsonForm } from "./components/automation-json-form";
import { AutomationNewHeader } from "./components/automation-new-header";
interface AutomationNewContentProps {
searchSpaceId: number;
}
/**
* Orchestrator for the raw-JSON create route. Gates on
* ``automations:create`` so users who can't create don't even see the
* form; same panel as the detail page's access-denied state for
* consistency.
*/
export function AutomationNewContent({ searchSpaceId }: AutomationNewContentProps) {
const perms = useAutomationPermissions();
if (perms.loading) {
return <div className="h-32 rounded-md border border-border/60 bg-muted/10 animate-pulse" />;
}
if (!perms.canCreate) {
return (
<div className="rounded-lg border border-border/60 bg-muted/20 px-6 py-12 text-center">
<ShieldAlert className="mx-auto h-10 w-10 text-muted-foreground" aria-hidden />
<h2 className="mt-3 text-base font-semibold text-foreground">Access denied</h2>
<p className="mt-1 text-sm text-muted-foreground max-w-md mx-auto">
You don't have permission to create automations in this search space.
</p>
</div>
);
}
return (
<>
<AutomationNewHeader searchSpaceId={searchSpaceId} />
<AutomationJsonForm searchSpaceId={searchSpaceId} />
</>
);
}

View file

@ -0,0 +1,98 @@
"use client";
import { useAtomValue } from "jotai";
import { AlertCircle, FileJson, Save } from "lucide-react";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { createAutomationMutationAtom } from "@/atoms/automations/automations-mutation.atoms";
import { JsonView } from "@/components/json-view";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Spinner } from "@/components/ui/spinner";
import { automationCreateRequest } from "@/contracts/types/automation.types";
import { DEFAULT_AUTOMATION_TEMPLATE } from "@/lib/automations/default-template";
interface AutomationJsonFormProps {
searchSpaceId: number;
}
/**
* Raw-JSON create form. Lets power users skip the chat drafter when they
* already know the shape they want. Flow:
* edit tree inject search_space_id Zod validate POST navigate
*
* ``search_space_id`` is injected here rather than required in the edited
* tree the user shouldn't have to know their numeric id, and it keeps
* the template copy-paste-friendly across search spaces.
*/
export function AutomationJsonForm({ searchSpaceId }: AutomationJsonFormProps) {
const router = useRouter();
const { mutateAsync: createAutomation, isPending } = useAtomValue(createAutomationMutationAtom);
const [value, setValue] = useState<Record<string, unknown>>(
() => DEFAULT_AUTOMATION_TEMPLATE as Record<string, unknown>
);
const [issues, setIssues] = useState<string[]>([]);
async function handleSubmit() {
setIssues([]);
const payload = { ...value, search_space_id: searchSpaceId };
const result = automationCreateRequest.safeParse(payload);
if (!result.success) {
setIssues(
result.error.issues.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`)
);
return;
}
try {
const created = await createAutomation(result.data);
router.push(`/dashboard/${searchSpaceId}/automations/${created.id}`);
} catch (err) {
setIssues([(err as Error).message ?? "Submit failed"]);
}
}
const hasIssues = issues.length > 0;
return (
<Card className="border-border/60 bg-accent">
<CardHeader className="pb-4">
<CardTitle className="text-base font-semibold inline-flex items-center gap-2">
<FileJson className="h-4 w-4 text-muted-foreground" aria-hidden />
Definition + triggers
</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
<div className="rounded-md border border-input bg-background px-3 py-2 max-h-[32rem] overflow-auto">
<JsonView
src={value}
editable
onChange={(next) => setValue(next as Record<string, unknown>)}
collapsed={false}
/>
</div>
{hasIssues && (
<div className="rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2">
<div className="flex items-center gap-1.5 text-xs font-medium text-destructive mb-1.5">
<AlertCircle className="h-3.5 w-3.5" aria-hidden />
{issues.length === 1 ? "1 issue" : `${issues.length} issues`}
</div>
<ul className="space-y-0.5 text-xs text-destructive list-disc list-inside">
{issues.map((issue) => (
<li key={issue}>{issue}</li>
))}
</ul>
</div>
)}
<div className="flex items-center justify-end gap-2">
<Button type="button" onClick={handleSubmit} disabled={isPending} size="sm">
{isPending ? <Spinner size="xs" className="mr-2" /> : <Save className="mr-2 h-4 w-4" />}
Create automation
</Button>
</div>
</CardContent>
</Card>
);
}

View file

@ -0,0 +1,42 @@
"use client";
import { ArrowLeft, MessageSquarePlus } from "lucide-react";
import Link from "next/link";
import { Button } from "@/components/ui/button";
interface AutomationNewHeaderProps {
searchSpaceId: number;
}
export function AutomationNewHeader({ searchSpaceId }: AutomationNewHeaderProps) {
return (
<div className="space-y-3">
<Button asChild variant="ghost" size="sm" className="-ml-2 h-auto px-2 py-1">
<Link
href={`/dashboard/${searchSpaceId}/automations`}
className="text-xs text-muted-foreground"
>
<ArrowLeft className="mr-1.5 h-3.5 w-3.5" />
Back to automations
</Link>
</Button>
<div className="flex items-start justify-between gap-4 flex-wrap">
<div className="space-y-1">
<h1 className="text-xl md:text-2xl font-semibold text-foreground">
New automation · raw JSON
</h1>
<p className="text-sm text-muted-foreground max-w-2xl">
Paste an ``AutomationCreate`` payload and submit. Validated against the schema before
save. Prefer natural language? Use chat instead.
</p>
</div>
<Button asChild variant="outline" size="sm">
<Link href={`/dashboard/${searchSpaceId}/new-chat`}>
<MessageSquarePlus className="mr-2 h-4 w-4" />
Switch to chat
</Link>
</Button>
</div>
</div>
);
}

View file

@ -0,0 +1,15 @@
import { AutomationNewContent } from "./automation-new-content";
export default async function NewAutomationPage({
params,
}: {
params: Promise<{ search_space_id: string }>;
}) {
const { search_space_id } = await params;
return (
<div className="w-full space-y-6">
<AutomationNewContent searchSpaceId={Number(search_space_id)} />
</div>
);
}

View file

@ -0,0 +1,15 @@
import { AutomationsContent } from "./automations-content";
export default async function AutomationsPage({
params,
}: {
params: Promise<{ search_space_id: string }>;
}) {
const { search_space_id } = await params;
return (
<div className="w-full space-y-6">
<AutomationsContent searchSpaceId={Number(search_space_id)} />
</div>
);
}