Function: when()
when<
TInput,TOutput>(config):Processable<TInput,TInput|TOutput>
Defined in: packages/core/src/pipeline/branches.ts:85
Create a conditional branching step for pipelines. Evaluates a condition and executes onPass or onFail branch accordingly.
The condition can be:
- String: Natural language condition (auto-creates conditional with GPT-4)
- Function: Returns boolean or Promise
- Processable<TInput, boolean>: Returns boolean result
Type Parameters
TInput
TInput
Input type for condition and branches
TOutput
TOutput
Output type from both branches
Parameters
config
WhenConfig<TInput, TOutput>
Configuration object with condition, onPass, and optional onFail
Returns
Processable<TInput, TInput | TOutput>
Processable that branches on the condition
Example
// With function condition
const myPipeline = pipeline(
validatePost,
when({
condition: (post) => post.wordCount > 1000,
onPass: publishImmediately,
onFail: scheduleForReview
})
);
// With string condition (uses AI)
const myPipeline = pipeline(
analyzeContent,
when({
condition: 'this content is high quality and ready to publish',
onPass: publishPost,
onFail: flagForReview
})
);
// With conditional
const isHighQuality = conditional({
goal: 'Determine if content meets quality standards'
});
const myPipeline = pipeline(
processContent,
when({
condition: isHighQuality,
onPass: approve,
onFail: reject
})
);
// onFail is optional - input passes through if condition fails
const myPipeline = pipeline(
loadData,
when({
condition: needsEnrichment,
onPass: enrichData
// No onFail - data passes through unchanged
}),
saveData
);