Input Data Mapping
Input data mapping allows explicit mapping of values for the inputs of the next step. These values can come from a number of sources:
- The outputs of a previous step
- The runtime context
- A constant value
- The initial input of the workflow
Map
In this example the output
from step1
is transformed to match the inputSchema
required for the step2
. The value from step1
is available using the inputData
parameter of the .map
function.
const step1 = createStep({...});
const step2 = createStep({...});
export const testWorkflow = createWorkflow({
id: "test-workflow",
description: 'Test workflow',
inputSchema: z.object({
input: z.number()
}),
outputSchema: z.object({
output: z.string()
})
})
.then(step1)
.map(({ inputData }) => {
const { value } = inputData;
return {
output: `${value}`
};
})
.then(step2)
.commit();
inputData
Use inputData
to access the full output of the previous step:
.map(({ inputData }) => {
const { value} = inputData;
...
})
getStepResult
Use getStepResult
to access the full output of a specific step by referencing the step’s instance:
.then(step1)
.map(({ getStepResult }) => {
console.log(getStepResult(step1));
...
})
getInitData
Use getInitData
to access the initial input data provided to the workflow:
.then(step1)
.map(({ getInitData }) => {
console.log(getInitData());
...
})
Renaming Outputs
Step Outputs
You can rename step outputs using the object syntax in .map()
. In the example below, the value
output from step1
is renamed to details
:
.then(step)
.map({
details: {
step: step,
path: "value"
}
})
Workflow Outputs
You can rename workflow outputs by using referential composition. This involves passing the workflow instance as the initData
.
export const testWorkflow = createWorkflow({
id: "test-workflow",
description: 'Test workflow',
inputSchema: z.object({
input: z.string()
}),
outputSchema: z.object({
output: z.string()
})
});
testWorkflow
.then(cityCoordinatesStep)
.map({
details: {
initData: testWorkflow,
path: "value"
}
})