Define locally
Author typed workflow, agent, and entity-type definitions with define* factories.
Use the define* factories in @lunnoa/client to describe connections, catalogue actions, workflows, agents, and entity types as pure typed config. Nothing is deployed or executed until you call Start runs or the CLI. These examples assume you import from @lunnoa/client. Discover catalogue ids with npx @lunnoa/client tools list / tools get, and model ids with npx @lunnoa/client ai-connections list --json, before writing defineAction or defineAgent.
defineAgent and defineWorkflow also accept a parsed JSON definition file, including $schema and instructions: { file }. Those files live in lunnoa/ and round-trip with the UI through pull and push (codeSource: "synced"). A TypeScript definition deployed with agents deploy or workflows deploy sets codeSource to generated and stays locked in the UI. codeSource replaces managedByCode on agents and workflows. See Sync with the UI.
Factories
| Factory | Role |
|---|---|
defineConnection({ id? }) | Ref to an app Connection UUID |
defineAiConnection({ id? }) | Ref to an AiProviderConnection UUID |
defineAction({ id, connection?, … }) | Catalogue action binding |
defineTrigger({ id, input?, inputs?, connection? }) | Catalogue trigger. Omit on the workflow for Manually Run with no fields |
defineWorkflow({ slug, steps, trigger? }) | Workflow, workspace-scoped slug. Steps take an optional key, and the last step may branch with paths. A loaded steps or graph JSON file is accepted too |
ref.trigger(field, …path) / ref.step(key, …path) | Pass a trigger field or an earlier step's output into a step setting |
defineAgent({ slug, model, instructions, … }) | Agent definition, workspace-scoped slug. A loaded JSON file is accepted, including instructions: { file } |
defineEntityType({ slug, attributeSchema, … }) | Entity type schema, workspace-scoped slug |
Omit connection when that app has one usable connection, or a workspace default. If several app connections match and none is the default, the call returns 400 and lists the candidates. The platform never picks the oldest connection. Pass defineAiConnection({ id }) for the AI connection. Omitting aiConnection does not assign one.
defineEntityType defaults to allowUnknownAttributes: false (strict instance writes). Use the reserved attribute key extensions on records for flexible bags. See Entities.
import {
defineAction,
defineAgent,
defineConnection,
defineEntityType,
defineWorkflow,
} from '@lunnoa/client';
const gmail = defineConnection({ id: process.env.GMAIL_CONNECTION_ID });
export const invoice = defineEntityType({
slug: 'invoice',
name: 'Invoice',
namePlural: 'Invoices',
icon: 'fileText',
color: '#3B82F6',
attributeSchema: {
version: '1.0',
sections: [
{
id: 'basic',
name: 'Basic',
order: 0,
collapsible: false,
defaultExpanded: true,
fields: [
{
id: 'amount',
name: 'amount',
label: 'Amount',
type: 'currency',
order: 0,
required: true,
visibility: 'always',
config: {},
},
],
},
],
},
});
export const syncOrders = defineWorkflow({
slug: 'sync-orders',
name: 'Sync orders',
steps: [
{
use: defineAction({
id: 'http_action_send-request',
input: { method: 'GET', url: 'https://api.example.com/orders' },
}),
},
{
use: defineAction({
id: 'gmail_action_send-email',
connection: gmail,
input: { to: 'ops@example.com', subject: 'Orders synced' },
}),
},
],
});
export const triage = defineAgent({
slug: 'support-triage',
model: 'deepseek-ai/DeepSeek-V4-Pro',
instructions: 'Triage inbound support mail. Be concise.',
tools: [
defineAction({ id: 'http_action_send-request' }),
syncOrders,
],
});Trigger
Omit trigger and deploy writes a Manually Run trigger with no input fields.
defineTrigger binds one catalogue trigger. Discover the id with npx @lunnoa/client apps get <appId> --json. The JSON includes triggers[].triggerId, inputFields, and a defineTrigger sketch. Do not invent trigger ids.
| Trigger | What to set |
|---|---|
Manually Run (flow-control_trigger_manual) | inputs: the form the caller fills in. Stored as customInputConfig. workflows.execute sends those keys. |
| Listen for Webhook | input: { method: 'POST' } (PUT and GET are the other methods) |
| Recurring Schedule | input from the catalogue (start and rrule). A schedule that cannot compute its next run fails the deploy. |
| Any other catalogue trigger | id, optional connection, and input from that trigger's inputConfig |
runs.start runs the steps only. It does not create a trigger.
import { defineAction, defineTrigger, defineWorkflow } from '@lunnoa/client';
export const syncOrders = defineWorkflow({
slug: 'sync-orders',
trigger: defineTrigger({
id: 'flow-control_trigger_manual',
inputs: [
{ id: 'invoiceId', label: 'Invoice', inputType: 'text', required: true },
],
}),
steps: [
{
use: defineAction({ id: 'http_action_send-request' }),
},
],
});
export const onWebhook = defineWorkflow({
slug: 'on-webhook',
trigger: defineTrigger({
id: 'flow-control_trigger_listen-for-webhook',
input: { method: 'POST' },
}),
steps: [
{
use: defineAction({ id: 'http_action_send-request' }),
},
],
});Passing data between steps
A step setting can take its value from the trigger or from an earlier step. Use ref from @lunnoa/client:
| Helper | Value it passes |
|---|---|
ref.trigger('caseId') | A trigger output field. On Manually Run, one of the inputs ids. On a webhook, the request shape, for example ref.trigger('body', 'caseId'). |
ref.step('load', 'rows', 0, 'status') | An earlier step's output. Give that step key: 'load'. Array indexes are numbers. |
A ref is a plain string. Use it as a whole value, inside a template string, or inside nested settings. On deploy the server swaps each ref for the real node id. In the builder, a reference in a top-level text field or list shows as a mapped field from that earlier node. In nested settings, the builder shows the reference text instead.
To find a step's output path, run the step once with actions.run or runs.startAndWait, then read that step's output in the execution.
import { defineAction, defineTrigger, defineWorkflow, ref } from '@lunnoa/client';
export const summariseCase = defineWorkflow({
slug: 'summarise-case',
trigger: defineTrigger({
id: 'flow-control_trigger_manual',
inputs: [{ id: 'caseId', label: 'Case', required: true }],
}),
steps: [
{
key: 'order',
use: defineAction({
id: 'http_action_send-request',
input: {
method: 'GET',
url: `https://api.example.com/cases/${ref.trigger('caseId')}`,
},
}),
},
{
use: defineAction({
id: 'http_action_send-request',
input: {
method: 'GET',
url: `https://api.example.com/owners/${ref.step('order', 'response', 'ownerId')}`,
},
}),
},
],
});defineWorkflow throws, and deploy returns 400, when a reference:
- names a key that no step has;
- points at its own step or a later one;
- uses a Manually Run field missing from
inputs.
Duplicate step keys and the reserved key trigger fail the same way.
runs.start resolves ref.step too. It has no trigger, so ref.trigger fails there.
Stable node ids
Each workflow node has an id, which references and run history use. A keyed step keeps the same node id on every deploy of the same slug. The trigger keeps its id while its type and settings stay the same. Steps without a key get a new id on each deploy. Give every step that another step reads from a key.
Branches
Add paths to the last step of a list to branch. Steps after the branch go inside each path. Paths do not merge back together. If steps are shared after a branch, repeat them in each path or build that part in the builder.
paths works on three Flow Control actions:
| Action | Paths |
|---|---|
| Request Approval | At most two. The first runs when approved and the second when rejected. Label them Approved and Rejected. |
| Conditional Paths | Each path has an optional when. Every path whose when matches runs. A path without when always runs. |
| Manually Decide Path | A person picks one path at runtime. No when. |
const approval = defineAction({ id: 'flow-control_action_request-approval', input: { /* from tools get */ } });
const route = defineAction({ id: 'flow-control_action_conditional-paths' });
export default defineWorkflow({
slug: 'suggestion-review',
steps: [
{ key: 'load', use: loadSuggestion },
{
key: 'review',
use: approval,
paths: [
{ label: 'Approved', steps: [{ key: 'apply', use: applySuggestion }] },
{
label: 'Rejected',
steps: [{ use: notifyAuthor, input: { text: ref.step('review', 'comment') } }],
},
],
},
],
});
// Conditional Paths
{
key: 'size',
use: route,
paths: [
{
label: 'Large',
when: [[{ field: ref.step('load', 'amount'), condition: 'is_greater_than', value: '1000' }]],
steps: [{ use: escalate }],
},
{
label: 'Small',
when: [[{ field: ref.step('load', 'amount'), condition: 'is_less_than_or_equal_to', value: '1000' }]],
steps: [{ use: autoApprove }],
},
],
}In when, the outer list holds groups and the inner list holds conditions. Groups are OR-ed, and conditions in a group are AND-ed. Each condition has:
field: exactly oneref.triggerorref.step.condition: one ofPATH_CONDITIONS, the same list the builder offers. It covers text (equals,contains,starts_with,matches_regex), presence (exists,is_empty), booleans (is_true,is_truthy), numbers (is_greater_than,is_less_than_or_equal_to) and dates (comes_before,is_in_the_past), plus their negations.value: text to compare with. Omit it for conditions that need none, such asis_emptyoris_true.
Steps on a path can ref.step the branching step and earlier steps on the same path, but not steps on another path. The builder shows the paths with their labels and conditions. runs.start rejects paths, so deploy the workflow and execute it instead.
What is deferred
The TypeScript steps shape cannot merge paths back together. pull writes those workflows as graph JSON, and push keeps the join. See Sync with the UI.
Also deferred on the TypeScript defineAgent: MCP, A2A, skills, memory, drive, shares, canvas, and profile image. A JSON file in lunnoa/agents/ can set those. See The agent file. Also deferred: NEEDS_INPUT, creating connections from code, and ephemeral agents without a row. Agents have no trigger. Put that on a workflow.
Related
- Start runs
- CLI
- Sync with the UI
- Entities
- Run actions (single catalogue step)
- Toolkit Actions (
createAction)