Skip to content
OpenNodeFlow.DocsOpen beta ↗
Agent guide ↗
Docs/Build workflows

Author custom code nodes

Define sockets, configuration and an async code body with explicit outputs, routing and effect boundaries.

23 Oct 2026 · 3 min read
Markdown ↗

Create a Node asset when no existing library operation has the required behavior. Define its socket contract and configuration before writing code. A small reusable pure transformation is easier to validate than one body combining discovery, mutation, retry and cleanup.

Function-body contract#

TypeScript/JavaScript code is an async function body, not a full module. The wrapper supplies inputs, config and context. Declare number input value and number output result, then use:

ts
const multiplier = config.multiplier ?? 2;
if (typeof multiplier !== 'number') throw new Error('Invalid multiplier');
return { result: inputs.value * multiplier };

Return a non-null object keyed by socket IDs. A display label does not change those keys. An omitted return becomes an empty object; an array, primitive or null top-level return is rejected. JSON serialization removes undefined fields and cannot transport values such as BigInt. Required outputs are checked after serialization.

TypeScript is transpiled, but publication does not provide full semantic TypeScript type checking. Runtime input/output/configuration schemas supply the actual data checks. Static module import/export syntax is not the code-body contract, and no per-asset package-install UI is provided.

Configuration and context#

Describe configuration using configSchema. Defaults initialise new instances; validation does not inject defaults into arbitrary API-created configurations. Connected input values override instance literals, which override definition defaults. A missing connected value does not fall back.

context.input is the whole workflow payload. IDs identify the real run, workflow, workspace and graph node. context.secrets.get(name) obtains a configured secret internally; never return or log it. context.connections.get() reads the selected profile in trusted execution. Await variables and storage helpers.

context.state stages node-local checkpoint changes until successful output/route validation. Storage and variable writes commit immediately instead. The distinction determines whether a later failure leaves a persistent change.

Routes and failures#

Declare control outputs and call context.emit('routeId') to choose one. With no explicit route, a declared next route is selected automatically; returning a next property alone does not select it. {__skip:true} intentionally skips the node path. Emitting an empty array still permits the default next route.

Throw for failure. A wired control output whose ID is error enables the normal handled-error route after attempts are exhausted. Data outputs are empty on that path; downstream handlers should read context.errors rather than also requiring a failed data output.

Reserved instance options include $timeoutMs (100–300,000), $retries (0–5 extra attempts) and $retryDelayMs (0–30,000). Retrying reruns the whole body and can duplicate network/file effects. Use stable business idempotency keys and reconcile uncertain results.

Test and publish#

Use synthetic valid and invalid inputs. Library Test executes real code with the host's trusted permissions, configured network and secrets; it does not run a downstream graph or engine retries. Publish an immutable version, insert it, validate and save the parent. Existing instances retain their pins. For Python/PowerShell contracts, read runtimes and workers.

Source provenance

Reviewed against maintained source and topic documentation on 23 October 2026. This is a source snapshot; installed versions and provider access may differ.

  • docs/AUTHORING.md
  • docs/RUNTIMES-AND-WORKERS.md
  • docs/EXAMPLES.md
Type to search the documentation.
↑ ↓ to navigate · Enter to openAgent map ↗