The JavaScript Processor is a core component of the EigenLayer-AVS Task Engine that enables custom JavaScript code execution within task workflows.
The JavaScript Processor is a core component of the EigenLayer-AVS Task Engine that enables custom JavaScript code execution within task workflows. This processor allows operators to execute arbitrary JavaScript logic as part of task execution, providing powerful capabilities for data transformation, validation, filtering, and custom business logic.
For information about other processors such as REST API calls or contract interactions, see REST API Processor and Contract Interaction Processors. For information about flow control and branching, see Branch and Flow Control.
The JavaScript Processor is implemented as part of the task engine's Virtual Machine (VM) system, specifically handling nodes of type CustomCodeNode with JavaScript as the language.
Sources:
The JavaScript Processor leverages the Goja library, a pure Go implementation of ECMAScript 5.1, to provide JavaScript execution capabilities without external dependencies. This approach ensures that JavaScript code can be executed reliably within the Go environment.
The JSProcessor struct contains:
CommonProcessor reference for accessing VM context and variablesSources:
During initialization, the processor:
macros.GetEnvs() methodSources:
The execution workflow for a JavaScript node:
Sources:
The processor executes provided JavaScript code by wrapping it in a self-executing function:
This approach isolates the execution context while capturing the returned value.
Sources:
JavaScript code can perform various data transformations:
Tests show examples of:
return 3>2)a.filter((i) => i >= 2))Sources:
JavaScript code has access to:
apContext.configVarsSources:
The processor captures the JavaScript return value and:
Sources:
In addition to the main JavaScript Processor, the system includes a specialized Filter Processor that uses JavaScript expressions for filtering arrays.
Sources:
The Filter Processor:
Unlike the general JavaScript Processor, the Filter Processor is specifically designed for array filtering operations, providing a more focused API.
Sources:
This returns a boolean value (true).
This returns [2, 3].
This returns [{name: 'bob', age: 15}].
This demonstrates accessing configuration variables or secrets.
Sources:
When using JavaScript object results in template strings in subsequent steps, objects are rendered as [object Object] rather than as JSON strings. This is important to consider when designing workflows that pass complex objects between steps.
Sources:
The JavaScript runtime is initialized with:
macros.GetEnvs()apContext objectSources:
The processor provides comprehensive error handling:
Sources:
When using the JavaScript Processor:
[object Object] in template strings| Aspect | Details |
|---|---|
| JavaScript Engine | Goja (Pure Go ECMAScript 5.1 implementation) |
| ECMAScript Support | ES5.1 + partial ES6 |
| Variable Access | All previous steps' outputs available as variables |
| Return Value Types | Any JSON-serializable value |
| Error Handling | Comprehensive with detailed logs |
| Configuration Access | Via apContext.configVars object |
The JavaScript Processor provides a powerful mechanism for custom logic within EigenLayer-AVS tasks, enabling complex transformations and business rules to be expressed directly within the task workflow.
Feature this wiki to auto refresh weekly