mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 22:34:56 +00:00
Restructure workflow/ for multi-language plugin support:
- Rename src/ to core/ (engine code: DAG executor, registry, types)
- Create executor/{cpp,python,ts}/ for language-specific runtimes
- Consolidate plugins to plugins/{ts,python}/ by language then category
Add 80+ Python plugins from AutoMetabuilder in 14 categories:
- control: bot control, switch logic, state management
- convert: type conversions (json, boolean, dict, list, number, string)
- core: AI requests, context management, tool calls
- dict: dictionary operations (get, set, keys, values, merge)
- list: list operations (concat, find, sort, slice, filter)
- logic: boolean logic (and, or, xor, equals, comparisons)
- math: arithmetic operations (add, subtract, multiply, power, etc.)
- string: string manipulation (concat, split, replace, format)
- notifications: Slack, Discord integrations
- test: assertion helpers and test suite runner
- tools: file operations, git, docker, testing utilities
- utils: filtering, mapping, reducing, condition branching
- var: variable store operations (get, set, delete, exists)
- web: Flask server, environment variables, JSON handling
Add language executor runtimes:
- TypeScript: direct import execution (default, fast startup)
- Python: child process with JSON stdin/stdout communication
- C++: placeholder for native FFI bindings (Phase 3)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
309 lines
6.1 KiB
Markdown
309 lines
6.1 KiB
Markdown
# Set Variable Node Plugin
|
|
|
|
Set workflow variables for use in subsequent nodes.
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
npm install @metabuilder/workflow-plugin-set-variable
|
|
```
|
|
|
|
## Usage
|
|
|
|
```json
|
|
{
|
|
"id": "set-vars",
|
|
"type": "operation",
|
|
"nodeType": "set-variable",
|
|
"parameters": {
|
|
"variables": {
|
|
"userId": "{{ $json.id }}",
|
|
"userEmail": "{{ $json.email }}",
|
|
"processDate": "{{ new Date().toISOString() }}"
|
|
},
|
|
"mode": "merge"
|
|
}
|
|
}
|
|
```
|
|
|
|
## Operations
|
|
|
|
### Set Simple Variables
|
|
Store string and number values:
|
|
|
|
```json
|
|
{
|
|
"variables": {
|
|
"count": 0,
|
|
"name": "John Doe",
|
|
"active": true
|
|
}
|
|
}
|
|
```
|
|
|
|
### Set Variables from Input Data
|
|
Reference input data with template expressions:
|
|
|
|
```json
|
|
{
|
|
"variables": {
|
|
"userId": "{{ $json.id }}",
|
|
"userName": "{{ $json.name }}",
|
|
"userStatus": "{{ $json.status }}"
|
|
}
|
|
}
|
|
```
|
|
|
|
### Set Computed Variables
|
|
Use expressions to compute values:
|
|
|
|
```json
|
|
{
|
|
"variables": {
|
|
"fullName": "{{ $json.firstName + ' ' + $json.lastName }}",
|
|
"isActive": "{{ $json.status === 'active' }}",
|
|
"count": "{{ $json.items.length }}"
|
|
}
|
|
}
|
|
```
|
|
|
|
### Set Complex Variables
|
|
Store objects and arrays:
|
|
|
|
```json
|
|
{
|
|
"variables": {
|
|
"userData": {
|
|
"id": "{{ $json.id }}",
|
|
"name": "{{ $json.name }}",
|
|
"email": "{{ $json.email }}"
|
|
},
|
|
"tags": ["{{ $json.tag1 }}", "{{ $json.tag2 }}"]
|
|
}
|
|
}
|
|
```
|
|
|
|
### Merge vs Replace Mode
|
|
Merge adds to existing variables (default):
|
|
|
|
```json
|
|
{
|
|
"variables": { "newVar": "value" },
|
|
"mode": "merge"
|
|
}
|
|
```
|
|
|
|
Replace clears all previous variables:
|
|
|
|
```json
|
|
{
|
|
"variables": { "var1": "value" },
|
|
"mode": "replace"
|
|
}
|
|
```
|
|
|
|
## Parameters
|
|
|
|
- `variables` (required): Object with variable definitions
|
|
- Keys must be valid variable names (alphanumeric + underscore)
|
|
- Values can be strings, numbers, booleans, objects, or arrays
|
|
- Supports template expressions in strings
|
|
- Recursively interpolates nested objects
|
|
- `mode` (optional): How to handle existing variables
|
|
- `merge` (default): Add new variables to existing set
|
|
- `replace`: Clear existing variables first
|
|
- `append`: Append to existing array variables
|
|
|
|
## Variable Names
|
|
|
|
Valid variable names:
|
|
- Must start with letter (a-z, A-Z) or underscore (_)
|
|
- Can contain letters, numbers (0-9), and underscores
|
|
- Are case-sensitive
|
|
- Examples: `userId`, `_private`, `tempData123`
|
|
|
|
Invalid variable names:
|
|
- `123var` (starts with number)
|
|
- `user-id` (contains hyphen)
|
|
- `user.id` (contains dot)
|
|
- `user@id` (contains special char)
|
|
|
|
## Template Expressions
|
|
|
|
Variable values support template interpolation:
|
|
|
|
- `{{ $json.fieldName }}` - Access input field
|
|
- `{{ $json.field1 + $json.field2 }}` - Concatenate/add
|
|
- `{{ $json.price * 1.1 }}` - Calculate
|
|
- `{{ $json.items.length }}` - Array length
|
|
- `{{ $json.active ? 'yes' : 'no' }}` - Conditionals
|
|
- `{{ new Date().toISOString() }}` - Current timestamp
|
|
- `{{ $env.API_KEY }}` - Environment variables
|
|
- `{{ $context.tenantId }}` - Context values
|
|
|
|
## Reserved Names
|
|
|
|
These names conflict with built-in variables and should be avoided:
|
|
- `context`
|
|
- `state`
|
|
- `json`
|
|
- `env`
|
|
- `utils`
|
|
- `$json`
|
|
- `$context`
|
|
- `$state`
|
|
- `$env`
|
|
|
|
Using reserved names will trigger a validation warning.
|
|
|
|
## Features
|
|
|
|
- Template expression interpolation in variable values
|
|
- Nested object and array support
|
|
- Multiple variable setting in single node
|
|
- Mode selection (merge/replace/append)
|
|
- Variable name validation
|
|
- Reserved name detection
|
|
- Type preservation (strings, numbers, booleans, objects)
|
|
- Recursive object interpolation
|
|
|
|
## Examples
|
|
|
|
### Set User Information
|
|
|
|
```json
|
|
{
|
|
"id": "set-user-vars",
|
|
"nodeType": "set-variable",
|
|
"parameters": {
|
|
"variables": {
|
|
"userId": "{{ $json.id }}",
|
|
"userName": "{{ $json.name }}",
|
|
"userEmail": "{{ $json.email }}",
|
|
"isAdmin": "{{ $json.role === 'admin' }}"
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
### Set Computed Values
|
|
|
|
```json
|
|
{
|
|
"id": "set-computed",
|
|
"nodeType": "set-variable",
|
|
"parameters": {
|
|
"variables": {
|
|
"total": "{{ $json.subtotal + $json.tax }}",
|
|
"discount": "{{ $json.total * 0.1 }}",
|
|
"finalPrice": "{{ ($json.subtotal + $json.tax) - ($json.total * 0.1) }}",
|
|
"timestamp": "{{ new Date().toISOString() }}"
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
### Set Conditional Variables
|
|
|
|
```json
|
|
{
|
|
"id": "set-conditional",
|
|
"nodeType": "set-variable",
|
|
"parameters": {
|
|
"variables": {
|
|
"status": "{{ $json.amount > 1000 ? 'high' : 'normal' }}",
|
|
"requiresApproval": "{{ $json.amount > 5000 }}",
|
|
"priority": "{{ $json.urgent ? 1 : 3 }}"
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
### Set Complex Data Structure
|
|
|
|
```json
|
|
{
|
|
"id": "set-complex",
|
|
"nodeType": "set-variable",
|
|
"parameters": {
|
|
"variables": {
|
|
"order": {
|
|
"id": "{{ $json.id }}",
|
|
"customer": {
|
|
"name": "{{ $json.customerName }}",
|
|
"email": "{{ $json.customerEmail }}"
|
|
},
|
|
"items": "{{ $json.items }}",
|
|
"totals": {
|
|
"subtotal": "{{ $json.subtotal }}",
|
|
"tax": "{{ $json.tax }}",
|
|
"total": "{{ $json.total }}"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
### Replace All Variables
|
|
|
|
```json
|
|
{
|
|
"id": "reset-variables",
|
|
"nodeType": "set-variable",
|
|
"parameters": {
|
|
"variables": {
|
|
"step": 1,
|
|
"status": "processing"
|
|
},
|
|
"mode": "replace"
|
|
}
|
|
}
|
|
```
|
|
|
|
### Build from Previous Variable
|
|
|
|
```json
|
|
{
|
|
"id": "build-from-var",
|
|
"nodeType": "set-variable",
|
|
"parameters": {
|
|
"variables": {
|
|
"processedUserId": "{{ $context.variables.userId }}_processed",
|
|
"incrementedCount": "{{ parseInt($context.variables.count) + 1 }}"
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
## Accessing Variables in Subsequent Nodes
|
|
|
|
Once set, variables are available in other nodes:
|
|
|
|
```json
|
|
{
|
|
"id": "next-node",
|
|
"nodeType": "http-request",
|
|
"parameters": {
|
|
"url": "{{ $context.variables.apiUrl }}",
|
|
"method": "POST",
|
|
"body": {
|
|
"userId": "{{ $context.variables.userId }}",
|
|
"email": "{{ $context.variables.userEmail }}"
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
## Variable Scope
|
|
|
|
Variables are scoped to workflow execution:
|
|
- Available to all subsequent nodes in same execution
|
|
- Not persisted across executions
|
|
- Can be overwritten by later Set Variable nodes
|
|
- Lost when workflow completes
|
|
|
|
## License
|
|
|
|
MIT
|