"use client"; import "@xyflow/react/dist/style.css"; import { Background, Controls, Handle, Position, ReactFlow, type Node, type NodeProps, } from "@xyflow/react"; import { ArrowDownIcon, ArrowUpIcon, ClockIcon, PlusIcon, ShieldCheckIcon, Trash2Icon, WrenchIcon, ZapIcon, } from "lucide-react"; import { useMemo, useState } from "react"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; import { useI18n } from "@/lib/i18n"; import { cn } from "@/lib/utils"; import { addStep, blankStep, deleteStep, moveStep, toFlow, TRIGGER_NODE_ID, updateStep, type StepKind, type StepNodeData, type TriggerNodeData, } from "./dsl"; import type { CatalogTool, Condition, Step, WorkflowDefinition } from "./types"; type TriggerFlowNode = Node; type StepFlowNode = Node; function TriggerNode({ data }: NodeProps) { return (
{data.trigger.type}

{data.label}

); } const KIND_ICON = { tool: WrenchIcon, wait: ClockIcon, approval: ShieldCheckIcon } as const; function StepNode({ data, selected }: NodeProps) { const { m } = useI18n(); const Icon = KIND_ICON[data.kind]; const s = data.step; return (
{s.id} · {m.workflows.kinds[data.kind]} {s.requires_approval && ( {m.workflows.needsSignoff} )}
{data.kind === "tool" &&

{s.tool || "—"}

} {data.kind === "wait" &&

{s.wait?.seconds}s

} {data.kind === "approval" &&

{s.approval?.summary}

} {s.for_each &&

for_each {s.for_each}

} {data.conditions.map((c, i) => (

if {c}

))}
); } const NODE_TYPES = { trigger: TriggerNode, step: StepNode }; /** JSON textarea that applies its value only when it parses. */ function JsonField({ id, label, value, onValid, testId, }: { id: string; label: string; value: unknown; onValid: (v: unknown) => void; testId?: string; }) { const { t } = useI18n(); const [text, setText] = useState(() => JSON.stringify(value ?? null, null, 2)); const [err, setErr] = useState(null); return (