Data Selectors & Transformations
Relevant source files
The following files were used as context for generating this wiki page:
- packages/web/src/lib/agent/skills/content/data-handling.md
- packages/web/src/lib/agent/skills/content/superglue-concepts.md
- packages/web/src/lib/agent/registries/tool-registry.ts
- packages/web/src/lib/agent/skills/content/http-apis.md
- packages/core/systems/system-manager.ts
- packages/core/documentation/documentation-search.ts
Data Selectors and Transformations govern how information flows, mutates, and loops within superglue workflows. They ensure deterministic data handling between disparate APIs, databases, and file servers by utilizing JavaScript-based logic executed in isolated sandboxes.
Core Transformation Points
The superglue execution pipeline applies logic at three distinct stages to manage data flow.
| Point | Timing | Primary Purpose |
|---|---|---|
| Data Selector | Before step execution | Controls step input and determines single vs. loop execution mode. |
| Transform Step | During step execution | Reshapes data between request steps using transformCode. |
| Output Transform | After all steps complete | Defines the final structure of the tool's response. |
Sources: packages/web/src/lib/agent/skills/content/data-handling.md:120-126, packages/web/src/lib/agent/skills/content/superglue-concepts.md:25-30
Variable Resolution Strategy
The <<expression>> syntax injects dynamic values into configuration fields such as URLs, headers, and request bodies. The system resolves these expressions using a specific hierarchy.
Resolution Hierarchy
- Direct Lookup: The system checks if the expression matches a top-level key in the merged variable object.
- Arrow Function Execution: If the lookup fails, the system executes the expression as an asynchronous JavaScript arrow function within a Deno sandbox.
- Failure: If neither method succeeds, the system throws an error listing available keys.
Sources: packages/web/src/lib/agent/skills/content/data-handling.md:3-36
Variable Sources
All available data resides in a single sourceData object, which includes:
- Original tool payload inputs.
- Previous step results (keyed by
stepId). - System credentials (namespaced as
systemId_credKey). - System base URLs (namespaced as
systemId_url). - Context variables like
sg_auth_email. - Loop-specific variables such as
currentItemand pagination metadata (page,offset,cursor).
Sources: packages/web/src/lib/agent/skills/content/data-handling.md:38-51, packages/web/src/lib/agent/skills/content/http-apis.md:104-114
This diagram shows the logic flow for resolving variable expressions within tool configurations.
Data Selectors and Looping
Every step contains a dataSelector that acts as a gatekeeper for execution. The return type of the selector determines whether a step executes once or iterates over a collection.
Single Execution (Object)
If the selector returns an Object, the step executes exactly once. The returned object becomes the currentItem for that step.
Sources: packages/web/src/lib/agent/skills/content/data-handling.md:66-70
Loop Execution (Array)
If the selector returns an Array, the step executes once for every element in the array. Each element sequentially becomes the currentItem. If the array is empty, the system skips the step.
Sources: packages/web/src/lib/agent/skills/content/data-handling.md:80-86
Result Envelopes
The system wraps every step result in a consistent envelope.
- Object Results:
sourceData.stepId = { currentItem, data, success } - Array Results:
sourceData.stepId = [{ currentItem, data, success }, ...] - Paginated Results: Merged into a single object envelope even if multiple pages were fetched.
Sources: packages/web/src/lib/agent/skills/content/data-handling.md:92-118, packages/web/src/lib/agent/skills/content/http-apis.md:144-150
JavaScript Execution Sandbox
All JavaScript logic in selectors and transforms runs in an isolated Deno subprocess to ensure security and determinism.
Constraints and Limits
- Memory: 8192 MB limit.
- Timeout: 10 minutes for transforms/selectors; 3 seconds for pagination stop conditions.
- Permissions: No filesystem access (
--deny-read/write) and no subprocess spawning (--deny-run). - Network: HTTP requests are allowed via
--allow-net.
Sources: packages/web/src/lib/agent/skills/content/data-handling.md:144-152, packages/web/src/lib/agent/skills/content/superglue-concepts.md:52-54
Serialization Safety
Because code is MessagePack-serialized and evaluated, certain patterns cause failures:
- Regex Literals: Use
new RegExp("pattern")instead of/pattern/. - Newlines: Code strings must remain single-line; use semicolons for statement separation.
- Backslashes: Avoid heavy backslash usage in strings.
Sources: packages/web/src/lib/agent/skills/content/data-handling.md:154-164
Output Transformations
The outputTransform shapes the final response of a tool. It runs after all individual steps have completed and has access to the cumulative sourceData.
This diagram illustrates the progression from initial payload through sequential steps to the final output transformation.
Sources: packages/web/src/lib/agent/skills/content/data-handling.md:135-142, packages/web/src/lib/agent/registries/tool-registry.ts:133-145
Practical Examples
URL and Credential Resolution
Using <<systemId_url>> allows tools to remain environment-agnostic, switching base URLs automatically between development and production systems.
{
"url": "<<salesforce_url>>/services/data/v58.0/sobjects/Account",
"headers": { "Authorization": "Bearer <<salesforce_access_token>>" }
}
Sources: packages/web/src/lib/agent/skills/content/data-handling.md:59-64, packages/web/src/lib/agent/skills/content/http-apis.md:17-30
Pagination Stop Conditions
Stop conditions prevent infinite loops by checking response data or fetch metadata.
(response, pageInfo) => !response.data.meta.next_cursor || pageInfo.totalFetched >= 1000
Sources: packages/web/src/lib/agent/skills/content/http-apis.md:120-135
Complex Data Selection
Data selectors can filter or transform upstream results before passing them to the current step.
(sourceData) => sourceData.getUsers.data.filter(u => u.isActive).map(u => ({ id: u.id }))
Sources: packages/web/src/lib/agent/skills/content/data-handling.md:81-83, packages/web/src/lib/agent/registries/tool-registry.ts:120-131
Data Selectors and Transformations provide the necessary flexibility to handle complex API interactions while maintaining the deterministic execution required for reliable integration workflows.