Beta 0.2.0-beta.2, not yet for critical processes. See the roadmap
PNeX logo
Documentation of the version in development, not released yet. See the stable release (0.1.0)

Functions

Versioned JavaScript and Starlark functions with live validation

When a flow node is not enough, PNeX exposes a functions registry: per-organization user functions in JavaScript (QuickJS sandbox) or Starlark, with append-only versioning and live validation. It lives under Automation › Functions.

Lifecycle

  1. Create a function and pick its language.
  2. Edit with live validation — the platform spawns the real runtime binary to check syntax and run a test payload before you save.
  3. Version: every save appends a version; deployed flows pin an exact version, inlined at deploy time.
  4. Test run executes the code in the editor (no save needed) with input values or an incoming message, and shows the console, the duration and the output of each port.

A function used by a deployed flow cannot be deleted.

New function dialog with Starlark/JavaScript and templates

Starlark editor with the @input/@output ports panel

Inputs and outputs: @input / @output directives

A function's signature lives in its code, as comments versioned with it (// or # prefix in both languages):

// @input temperature number "Measured temperature"
// @input mode string="auto"
// @output heating number
function handle(inputs, msg) {
  return { heating: inputs.temperature < 19 ? 1 : 0 };
}

The editor's Inputs / Outputs panel reads and rewrites these directives (Add an input, Add an output, name, type, default). The code defines handle(inputs, msg) (def handle(inputs, msg): in Starlark).

In a flow, the Function node shows one input anchor per @input (one wire per input) and one output port per @output:

  • Per-wire routing: a bare payload wired to the temperature anchor arrives in inputs.temperature — deploying tags each wire with the input name (msg.topic). A JSON Split can therefore feed the anchors directly (topic = key). Without a dedicated wire, the input is read from payload.<name>, then falls back to its default.
  • Return: an object whose keys are the @output names emits each key on its port (missing key or null = muted port). Without @output, the returned value replaces the payload on port 0; null drops the message.

Sandboxing

JavaScript runs in a QuickJS sandbox with an interrupt handler as the single reliable bound on runaway code. Starlark offers a deterministic, Python-flavoured alternative. Functions have no access to the organization's secrets. The function replaces the incoming message payload with its return value — it does not merge into it. A new version does not change deployed flows: select it in the node, then redeploy.

Live test run with per-port outputs

AI-assisted authoring

The integrated AI assistant can draft, validate, test and fix functions on request (see AI Assistant), and the editor offers quick-fixes for common validation errors.

On this page