kodexa/go-scripting-runtime — making them fast to deploy and ideal for:
- Document metadata enrichment
- Conditional routing and classification
- Lightweight data transformations
- Calling external APIs via service bridges
- LLM-assisted processing
Module Definition
Create amodule.yml with scriptLanguage: "javascript" and inline your script in the script field:
- slug: Unique identifier within your organization
- orgSlug: Your Kodexa organization slug
- moduleRuntimeRef: Must be
kodexa/go-scripting-runtimefor JavaScript modules - scriptLanguage: Must be
javascript(orjs) - script: Your inline JavaScript code
Script Structure
Scripts run in a Goja JavaScript runtime (ES5+ compatible). The script is automatically wrapped in an IIFE (Immediately Invoked Function Expression), so you can usereturn at the top level to produce an output value:
Available APIs
Parameters
Aparameters global object is available containing:
- Any module options configured for the execution (from
inferenceOptionsor step config) - The execution_id for the current execution
- The pipeline_context with execution context metadata
Logging
Two logging APIs are available:Module Dependencies
JavaScript modules can load other JavaScript modules as dependencies using themoduleSidecars field in module.yml. Dependencies are fetched and executed in order before your main script runs, making their functions and variables available in global scope.
script. Sidecar scripts run in global scope (not wrapped in an IIFE), so any functions or variables they declare are available to subsequent sidecars and your main script.
A maximum of 10 module pre-loads are allowed per execution. Exceeding this limit will cause a startup error.
Document API (when used in script steps)
When your JavaScript module is used as a script step in a plan workflow, the full document API is available — includingloadDocument(), node traversal, tagging, data object creation, and more. See the Script Steps guide for complete documentation.
Service Bridges (when used in script steps)
Script steps can call external APIs through project-scoped service bridges usingserviceBridge.list() and serviceBridge.call(). See the Script Steps guide for details.
LLM Invocation (when used in script steps)
Script steps can invoke the platform’s LLM service usingllm.invoke() and llm.invokeWithPromptRef(). See the Script Steps guide for details.
Limits
| Limit | Value |
|---|---|
| Script timeout | 60 seconds |
| Max module pre-loads | 10 |
Deployment
Deploy with the KDX CLI:- Create or update the module metadata in the platform
- Store the inline script in the module metadata
- Make the module available for use in assistants, pipelines, and as a sidecar dependency
Example: Document Classifier
Here is a complete example of a JavaScript module that classifies documents based on metadata:module.yml
Example: Reusable Utility Module
This module is designed to be used as a sidecar dependency. It defines utility functions in global scope that other modules can call:module.yml
Using Your Module
Once deployed, your JavaScript module can be:- Added to an Assistant in your project through Studio
- Referenced as a sidecar by other JavaScript modules
- Used in scheduled jobs and pipelines
Troubleshooting
Script syntax errors
- JavaScript modules use ES5+ syntax. Features like
let,const, arrow functions, and template literals are supported, but some ES2015+ features may not be available. - Check that your script does not contain syntax errors by testing locally with Node.js.
Module sidecar not found
- Verify the sidecar module exists and has been deployed with
kdx get module my-org/sidecar-slug - Ensure the sidecar module has a
scriptfield in its metadata - Check that the sidecar reference uses the correct
orgSlug/moduleSlugformat
Script timeout
- The default timeout is 60 seconds. Long-running scripts will be interrupted.
- Optimize loops and avoid blocking operations.
- Consider breaking complex logic into multiple steps.
Deployment failures
- Verify KDX CLI is configured:
kdx config --list - Check the
orgSlugin module.yml matches your organization - Ensure module.yml is valid YAML (watch for indentation in the
scriptblock) - Run
kdx applyfrom the directory containing module.yml
