[data-reveal]{opacity:1!important;transform:none!important}
AntelopeJS DMS
DocumentationInterface reference

Automation interface

Register triggers, asynchronous actions and synchronous data nodes, ship procedures as code, and invoke saved procedures.

@antelopejs/interface-dms-automation is the consumer contract for backend modules that add nodes to the builder. Import from its root. The internal proxy namespace is not a supported consumer entry point.

Register a complete action

The smallest complete action is a trace marker. It records that a step ran, without logging its input or calling an external service. start() and stop() belong in the module's lifecycle. The builder then shows the registered action and its recorded output.

ts
import { RegisterActionType, UnregisterActionType } from "@antelopejs/interface-dms-automation";

const ACTION_ID = "example.trace-marker";

export function start(): void {
  RegisterActionType({
    id: ACTION_ID,
    name: "Record trace marker",
    description: "Record that this step was reached",
    icon: "i-lucide-file-text",
    inputSchema: { type: "object" },
    outputSchema: { type: "object", properties: { recorded: { type: "boolean" } } },
    async execute(_input, ctx) {
      ctx.log("info", "Trace marker reached");
      return { recorded: true };
    },
  });
}

export function stop(): void {
  UnregisterActionType(ACTION_ID);
}

Extending covers the dependency setup. The execution context and its authorization limits apply once the body does real work.

Registration and lifecycle

Contract ts
import type { ActionType, DataNodeType, TriggerType } from "@antelopejs/interface-dms-automation";

declare function RegisterTriggerType(type: TriggerType): void;
declare function RegisterActionType(type: ActionType): void;
declare function RegisterDataNodeType(type: DataNodeType): void;
declare function UnregisterTriggerType(id: string): void;
declare function UnregisterActionType(id: string): void;
declare function UnregisterDataNodeType(id: string): void;

A module registers in its start() and unregisters in stop(). Registrations belong to the calling module. A registration made before an implementation attaches waits, and the interface replays every registration when an implementation attaches or reloads. With no implementation, registering runs no node and throws no availability error. The unregister functions remove declarations, not saved procedure graphs or run history.

Removing a trigger type calls deactivate on its active handles before the unregister call returns, while the declaring module can still run code. The call does not await that cleanup. When a module stops or reloads, the core takes its registrations back and invalidates its context right after.

Each active handle keeps the trigger definition that created it. If a reload happens during an asynchronous activation, the module cleans up each handle with its own definition before it reconciles the replacement, even when the registry has already changed. A handle let go this way starts no run afterwards, even if its trigger still calls emit.

Runs started by emit belong to the automation module, whichever module calls it, so a stopping trigger module does not take its runs down with it. A step fails, and the run with it, when the module behind the step goes away during the run. The step then throws ModuleContextInvalidatedError, or its type was unregistered after the run started. A module goes away during a run only in development, because a production module never reloads.

IDs are registry keys, namespaced as <module>.<node>. A colliding ID replaces the existing definition instead of creating a second node. Every definition requires id, name, description and icon strings. JsonSchema is a JSON Schema object. The keywords the builder and the runtime read (type, title, description, properties, items, required, enum, default, minimum and maximum) are typed, and any other keyword holds a JSON value. The runtime applies each property's default under the node's configured values. Schemas stay flat, because the builder maps properties to ports. A schema describes editor inputs, not a tenant authorization policy.

JSON values

Every value a node hands the graph is JSON. That covers a trigger's payload, the output of an action or a data node, a value logged with ctx.log, and the payload that InvokeProcedure and RunProcedure pass.

JSON types ts
type JsonPrimitive = string | number | boolean | null;
type JsonValue = JsonPrimitive | JsonValue[] | JsonObject;
type JsonObject = { [key: string]: JsonValue | undefined };

An object key may hold undefined for a field left unset, as an optional property does. JSON.stringify leaves that key out, so the object still writes as JSON. A value or an array item is never undefined. A Date must become an ISO string, and a class instance a plain object, before a node hands it over. An object payload or output needs a type alias rather than an interface. TypeScript accepts an object type alias as a JsonObject, but not an interface, which declares no index signature.

TriggerType

TriggerType<TConfig = unknown, TOutput extends JsonValue = JsonValue, THandle = unknown> adds these required members:

Trigger members ts
import type { JsonSchema, JsonValue } from "@antelopejs/interface-dms-automation";

interface TriggerMembers<TConfig, TOutput extends JsonValue, THandle> {
  configSchema: JsonSchema;
  outputSchema: JsonSchema;
  cluster: "singleton" | "replicated";
  activate(config: TConfig, emit: (payload: TOutput) => void): Promise<THandle>;
  deactivate(handle: THandle): Promise<void>;
}

activate installs the trigger and returns a handle that deactivate must clean up. THandle types it, so deactivate receives what activate resolved with. The automation module treats the handle as opaque. emit starts a run with a JSON payload, which the run stores and its trace shows. It returns void, not a completion promise. deactivate must release the timers, listeners and routes the trigger holds.

activate and deactivate each get 10 seconds. A failed or timed-out activation is an arming failure, not a registration return value, and the next reconcile retries it. A failed deactivation keeps the handle for a later retry.

A trigger that keeps a timer types its handle, so deactivate reads it without a cast:

ts
import { RegisterTriggerType } from "@antelopejs/interface-dms-automation";
import type { TriggerType } from "@antelopejs/interface-dms-automation";

interface PollHandle {
  timer: ReturnType<typeof setInterval>;
}

const pollTrigger: TriggerType<{ everyMs: number }, { at: number }, PollHandle> = {
  id: "example.poll",
  name: "Poll",
  description: "Fires on an interval",
  icon: "i-lucide-timer",
  configSchema: { type: "object" },
  outputSchema: { type: "object", properties: { at: { type: "number" } } },
  cluster: "singleton",
  async activate(config, emit) {
    return { timer: setInterval(() => emit({ at: Date.now() }), config.everyMs) };
  },
  async deactivate(handle) {
    clearInterval(handle.timer);
  },
};

RegisterTriggerType(pollTrigger);

cluster has no default. singleton activates only on the elected leader, for schedules or feeds that must not fire on every instance. replicated activates on every instance, for inputs such as webhooks that a load balancer routes to one instance. The distinction has no effect in single-instance mode. It does not make an action's side effects exactly-once, so an action visible outside the run must tolerate retries. Cluster configuration covers the modes.

ActionType and ExecutionCtx

ActionType<TInput = unknown, TOutput extends JsonObject | void = JsonObject | void> adds inputSchema, outputSchema, the optional sideEffects and dryRun (see test runs), and execute(input: TInput, ctx: ExecutionCtx): Promise<TOutput>. Actions are asynchronous and may do I/O. Resolving with a JSON object makes its fields available to downstream ports. Resolving with nothing leaves the step without output. A run fails the step whose action resolves with anything else, an array included, with action type "<id>" must resolve with an object or nothing. A throw fails the step. A step whose action type is disabled in the library fails with action type "<id>" is disabled in the library.

ExecutionCtx contains procedureId, runId and nodeId strings, an optional dryRun boolean (see test runs), and log(level: LogLevel, message: string, value?: JsonValue): void. LogLevel is "info" | "warn" | "error". The runtime tags each entry with the node and records it in the run trace, so a secret logged there is stored. The context has no tenantId and no authenticated user. An action validates and authorizes its tenant-scoped operations itself.

Procedures belong to the platform, not to a tenant, and many triggers, such as a schedule or a webhook, have no tenant at all. The context therefore cannot carry one. An action that works on tenant data takes the tenant as an input, as the DMS's own actions do. It declares a tenantId string in inputSchema, which a procedure wires from the tenantId output of a DMS event trigger or types in. When the input is empty, the action falls back to DEFAULT_TENANT_ID from @antelopejs/interface-dms.

Test runs: sideEffects, dryRun and ctx.dryRun

The builder's Test run tries a draft. Two optional ActionType members tell it what the action does outside the run.

Dry-run members ts
import type { ExecutionCtx } from "@antelopejs/interface-dms-automation";

interface ActionDryRunMembers<TInput, TOutput> {
  sideEffects?: boolean;
  dryRun?(input: TInput, ctx: ExecutionCtx): Promise<TOutput>;
}
DeclarationIn a test run
sideEffects: false (reads or computes only)execute runs as is, no confirmation asked.
dryRun (sends, writes, calls a service)dryRun runs instead of execute, and the trace logs Simulated (test run): no effect. It must have no effect and resolve to a plausible output, shaped as outputSchema, so the steps after it still run.
Neither (sideEffects defaults to true)execute runs for real. Before the test starts, the builder lists the step and asks the user to confirm. The API refuses the test until then.

sideEffects: false wins over dryRun. Such an action runs execute in a test. ExecutionCtx.dryRun is true for every step of a test run, inside dryRun and in actions that have none, so the code an action calls can tell a test from a real run. An implementation without dry-run support leaves it out, which reads as false, and calls execute in a test. Run now, triggers, InvokeProcedure and RunProcedure always call execute.

ts
import { RegisterActionType } from "@antelopejs/interface-dms-automation";

RegisterActionType({
  id: "example.notify",
  name: "Notify the team",
  description: "Post a message to the team channel",
  icon: "i-lucide-bell",
  inputSchema: { type: "object", properties: { text: { type: "string" } } },
  outputSchema: { type: "object", properties: { delivered: { type: "boolean" } } },
  async dryRun(_input, ctx) {
    ctx.log("info", "Test run: message not posted");
    return { delivered: true };
  },
  async execute(_input, ctx) {
    ctx.log("info", "Message posted");
    return { delivered: true };
  },
});

DataNodeType

DataNodeType<TInput = unknown, TOutput extends JsonObject = JsonObject> adds category: string, inputSchema, outputSchema, optional configSchema, and synchronous evaluate(input: TInput): TOutput, a JSON object whose fields are the node's output ports. Evaluation is pure. Asynchronous work and side effects belong in an action. An evaluation error fails the step that reads the node, and so does a result that is not an object or is an array, with data node type "<id>" must evaluate to an object.

When present, configSchema replaces the inspector's editable fields, not the data-input ports, which still come from inputSchema. The runtime merges the configured values into the evaluation input. Data nodes receive no execution context.

List types and invoke procedures

Contract ts
import type {
  ActionType,
  DataNodeType,
  JsonValue,
  ProcedureRunOutcome,
  RunProcedureOptions,
  TriggerType,
} from "@antelopejs/interface-dms-automation";

declare function ListTriggerTypes(): Promise<TriggerType[]>;
declare function ListActionTypes(): Promise<ActionType[]>;
declare function ListDataNodeTypes(): Promise<DataNodeType[]>;
declare function InvokeProcedure(id: string, payload?: JsonValue): Promise<string>;
declare function RunProcedure(id: string, options?: RunProcedureOptions): Promise<ProcedureRunOutcome>;

All five calls are asynchronous. Listing returns the definitions registered now. With no implementation loaded, a call waits until one attaches. By default, each function holds at most 1,000 waiting calls, and the next call rejects with ProviderQueueFullError. A waiting call rejects with ModuleContextInvalidatedError when its calling module has stopped by the time an implementation attaches.

InvokeProcedure runs the saved graph from its first manual trigger and resolves to the stored run ID after execution and recording. It rejects with 404 for an unknown procedure, and with 400 for an unparseable stored graph or a graph without a manual trigger. A failed run still returns a run ID, so the ID is not a success flag. A storage failure can reject after actions have run. The call has no rollback and no idempotency key.

RunProcedure starts any saved procedure now, whatever its triggers (a schedule, a webhook, a manual trigger or one a module registers), the way Run now does in the builder. It waits until the automation module has started.

OptionTypeDescription
payloadJsonValueWhat the trigger hands the graph. Left out, the payload of the newest stored run that kept one, test runs excluded, among the procedure's last 50 runs. With triggerNodeId, only runs of that trigger count. With no such run, {}. An explicit payload makes the run reproducible.
triggerNodeIdstringThe trigger node to start from. By default the manual trigger, else the graph's first trigger.

It resolves once the run is stored, to a ProcedureRunOutcome of { runId, status, errorMessage? }, where status is "ok" or "failed". It rejects as the HTTP run-now route does. An unknown procedure or trigger node gives 404. An unparseable stored graph, or a graph with blocking issues such as no trigger or a step missing its settings, gives 400, and the rejection lists the issues. Like Run now, it runs a paused procedure too, because pausing stops its triggers, not explicit runs. The run is stored as an ordinary run and counts in the health figures.

RunProcedure is a trusted, platform-level backend API, not a tenant-scoped HTTP route. The caller restricts which procedures run and what payloads they receive. Arbitrary procedure IDs from untrusted users must not reach it.

Declare procedures from code

Contract ts
import type { DeclaredProcedure, ProcedureDeclaration } from "@antelopejs/interface-dms-automation";

declare function DeclareProcedure(declaration: ProcedureDeclaration): Promise<DeclaredProcedure>;

DeclareProcedure creates a procedure a module ships as code, such as the procedures a project template or a demo provides, keyed by declaration.id. The procedure is written once. When a procedure already has that ID, the call leaves it as it is.

FieldTypeDescription
idstringStable key the caller chooses, namespaced <module>.<procedure>. Letters, digits, ., _ and -, starting with a letter or a digit, at most 120 characters. It becomes the procedure's ID, so InvokeProcedure(id), RunProcedure(id) and the builder (/modules/automation/builder?selected=<id>) take it as is.
namestring1 to 200 characters once trimmed. Another procedure with the same name adds a warning to issues.
descriptionstringOptional, at most 2000 characters.
graphProcedureGraphThe graph, in the shape Export JSON writes under graph, with nodes, triggerEdges and dataEdges. Each node's config is a JsonObject, and its optional label is the step's name. The graph comes from a builder export or is written by hand.
enabledbooleanRequired. After storage, the module reconciles eligible triggers locally and notifies peers in Redis mode. Singleton triggers run only on the leader, and replicated triggers run on each instance.

The module validates the declaration as Import JSON validates a file. An enabled declaration is also validated as enabling the procedure in the builder is. A missing setting, a missing trigger, an unknown template, or a webhook route that another enabled procedure answers on rejects the call, and nothing is stored. The rejection is an Error whose message reads [dms-automation] DeclareProcedure("<id>") refused: followed by each problem, separated by ; . A disabled declaration is stored as a draft with its graph problems. A trigger, action or data node type that is not registered yet never blocks, because modules start in parallel. Its trigger arms as soon as the type registers.

Stored procedurestatusEffect
None with this ID"created"Stored, version 1, and its triggers reconciled.
One with this ID"kept"Left as it is, whatever the declaration says.

From its creation on, the procedure belongs to its users. An edit, a pause or a deletion stays, and a changed declaration is not applied. The next call creates a deleted procedure again, so pausing is the way to keep a declared procedure out of the way. The result also carries enabled, the stored procedure's state, which can differ from the declaration for a kept one. It carries issues too, the graph's problems that did not block it.

enabled: true does not guarantee a healthy trigger or a completed run. A trigger that fails to activate shows as an arming error in the dashboard, and the procedure as Failing. issues describes the submitted graph, not those runtime failures. The call waits for local reconciliation, not for every peer to acknowledge it. Retry-safe storage does not make the actions a trigger fires exactly-once.

The call waits until the automation module has started, so it is safe from a module's start() or a Hook.DATABASE_INITIALIZED handler. With no implementation loaded, it waits until one attaches. Do not await it in construct(), which runs before any module starts.

ts
import { DeclareProcedure, type ProcedureGraph } from "@antelopejs/interface-dms-automation";

const graph: ProcedureGraph = {
  nodes: [
    {
      id: "weekday-morning",
      kind: "trigger",
      typeId: "schedule.cron",
      config: { cron: "0 9 * * 1-5" },
      position: { x: 80, y: 160 },
    },
    {
      id: "note",
      kind: "action",
      typeId: "log.message",
      config: { message: "Follow up the open quotes" },
      position: { x: 360, y: 160 },
    },
  ],
  triggerEdges: [{ id: "edge-1", from: { node: "weekday-morning" }, to: { node: "note" } }],
  dataEdges: [],
};

export async function start(): Promise<void> {
  const declared = await DeclareProcedure({
    id: "example.quote-follow-up",
    name: "Follow up open quotes",
    description: "Every weekday morning, list the quotes waiting for an answer",
    graph,
    enabled: true,
  });
  if (declared.status === "kept") {
    console.info(`${declared.id} already exists: left as it is`);
  }
}