"use client"; /** * Automations editor — ACTIONS section (ordered 1..50). * Per-action knobs (retries 1..8, timeoutMs 1000..300000) + per-type config. * Field sets follow the real strict ActionConfigSchemas (see lib.ts * actionConfigPayload for the documented mapping of the task's illustrative * field list onto the actual API schema). */ import { ArrowDown, ArrowUp, Plus, Trash2 } from "lucide-react"; import { inputCls } from "@/components/settings/settings-shell"; import { ACTION_LABELS, ACTION_RETRY_DEFAULT, ACTION_RETRY_MAX, ACTION_RETRY_MIN, ACTION_TIMEOUT_DEFAULT_MS, ACTION_TIMEOUT_MAX_MS, ACTION_TIMEOUT_MIN_MS, AI_TASKS, AUTOMATION_ACTION_TYPES, AUTOMATION_MAX_ACTIONS, NOTIFICATION_TYPES, type ActionDraft, type AutomationActionType } from "./lib"; interface ActionEditorProps { actions: ActionDraft[]; onChange: (actions: ActionDraft[]) => void; } const secToMs = (s: number) => Math.round(s * 1000); const msToSec = (ms: number) => Math.round(ms / 1000); export function ActionEditor({ actions, onChange }: ActionEditorProps) { const update = (i: number, patch: Partial) => { const next = [...actions]; next[i] = { ...next[i]!, ...patch }; onChange(next); }; const setCfg = (i: number, key: string, value: string) => { const a = actions[i]!; update(i, { config: { ...a.config, [key]: value } }); }; const move = (i: number, dir: -1 | 1) => { const j = i + dir; if (j < 0 || j >= actions.length) return; const next = [...actions]; const tmp = next[i]!; next[i] = next[j]!; next[j] = tmp; onChange(next); }; const remove = (i: number) => onChange(actions.filter((_a, idx) => idx !== i)); const add = () => { if (actions.length >= AUTOMATION_MAX_ACTIONS) return; onChange([ ...actions, { type: "RUN_AI_ACTION", config: {}, retries: ACTION_RETRY_DEFAULT, timeoutMs: ACTION_TIMEOUT_DEFAULT_MS } ]); }; return (
{actions.length === 0 && (

No actions yet. An automation needs at least one action to run.

)} {actions.map((a, i) => (
{i + 1}.
{a.type === "UPDATE_RECORD" && ( <> setCfg(i, "recordId", v)} /> setCfg(i, "propertyName", v)} /> setCfg(i, "value", v)} /> )} {a.type === "CHANGE_STATUS" && ( <> setCfg(i, "recordId", v)} /> setCfg(i, "propertyId", v)} /> setCfg(i, "value", v)} /> )} {a.type === "ASSIGN_USER" && ( <> setCfg(i, "recordId", v)} /> setCfg(i, "propertyId", v)} /> setCfg(i, "userId", v)} /> )} {a.type === "CREATE_NOTIFICATION" && ( <> )} {a.type === "CREATE_PAGE" && ( <> setCfg(i, "title", v)} /> setCfg(i, "parentPageId", v)} /> )} {a.type === "SEND_WEBHOOK" && ( <>