expr

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package expr evaluates JS boolean/value expressions (n8n's "{{ $json.x }}" convention, already used by seshat-backend's inbox event filter) for dataflow nodes that need per-item logic (filter/if/set/switch) — unlike event_filter.go's one-VM-per-call approach (fine for a single check per inbound message), a dataflow node may evaluate the same expression against many items in one run, so this pool reuses goja runtimes and caches compiled bytecode across evaluations.

Index

Constants

View Source
const DefaultTimeout = 2 * time.Second

DefaultTimeout bounds a single evaluation — an expression authored by an LLM (the Inbox Agent) is untrusted input in the same sense event_filter.go already treats it: it must fail loudly rather than hang the graph.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool evaluates expressions against a bounded set of reused goja runtimes, caching compiled bytecode by source string. A goja.Runtime cannot run two scripts concurrently, so runtimes are checked out/in like a connection pool; Compile is the expensive, reusable part (bytecode has no per-run state), so it's cached independently of runtime checkout.

func NewPool

func NewPool(maxRuntimes int) *Pool

NewPool creates a pool that keeps up to maxRuntimes JavaScript runtimes ready to evaluate expressions (8 when it is 0 or less) and caches the compiled programs.

func (*Pool) Eval

func (p *Pool) Eval(ctx context.Context, source string, bindings map[string]any) (any, error)

Eval evaluates source with bindings set as global variables (e.g. bindings["$json"] = the current Item) and returns the raw goja value's exported Go form.

func (*Pool) EvalBool

func (p *Pool) EvalBool(ctx context.Context, source string, bindings map[string]any) (bool, error)

EvalBool evaluates source and requires a boolean result — the shape filter/if nodes need, matching event_filter.go's own "must be a boolean, no silent coercion" rule.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL