Step API Reference
This reference documents the core APIs for defining, executing, and managing steps in ZoopFlow.
Step Definition
defineStep<TInput, TOutput>(definition: StepDefinition<TInput, TOutput>)
Creates a new step definition with specified input and output types.
import { defineStep } from '@zoopflow/core';
const stringTransformer = defineStep({
id: 'examples.string.transform',
version: '1.0.0',
description: 'Transforms a string based on the specified operation',
inputSchema: { /* JSON Schema for input validation */ },
outputSchema: { /* JSON Schema for output validation */ },
execute: async (input, context) => {
// Step implementation
return output;
}
});Parameters
| Name | Type | Description |
|---|---|---|
definition | StepDefinition<TInput, TOutput> | The step definition configuration |
Returns
Returns a Step<TInput, TOutput> instance that can be registered and executed.
StepDefinition<TInput, TOutput>
Interface for defining a step.
interface StepDefinition<TInput, TOutput> {
// Required properties
id: string;
version: string;
description?: string;
displayName?: string;
inputSchema: JSONSchema7;
outputSchema: JSONSchema7;
execute: (input: TInput, context: StepContext) => Promise<TOutput>;
// Optional properties
retryConfig?: RetryConfig;
timeoutSeconds?: number;
tags?: string[];
metadata?: Record<string, unknown>;
}Properties
| Name | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Unique identifier for the step in the format domain.resource.action |
version | string | Yes | Semantic version of the step |
description | string | No | Human-readable description of what the step does |
displayName | string | No | Friendly name for display in UIs |
inputSchema | JSONSchema7 | Yes | JSON Schema for validating step input |
outputSchema | JSONSchema7 | Yes | JSON Schema for validating step output |
execute | Function | Yes | The implementation function for the step |
retryConfig | RetryConfig | No | Configuration for retry behavior |
timeoutSeconds | number | No | Timeout for step execution in seconds |
tags | string[] | No | Tags for categorization and filtering |
metadata | Record<string, unknown> | No | Additional metadata for the step |
Step Context
The StepContext provides utilities, services, and state management for step execution.
StepContext Interface
interface StepContext {
// Execution metadata
info: ExecutionInfo;
stepMetadata: StepMetadata;
readonly executionMetadata: StepExecutionMetadata;
readonly history: StepHistoryEntry[];
// State management
getState<T>(key: string): Promise<T | undefined>;
setState<T>(key: string, value: T): Promise<void>;
getStateObject(): Promise<Record<string, unknown>>;
updateState(stateUpdates: Record<string, unknown>): Promise<void>;
// Checkpointing and recovery
createCheckpoint(metadata?: Record<string, unknown>): Promise<string>;
restoreFromCheckpoint(checkpointId: string): Promise<void>;
getCheckpointInfo(checkpointId: string): Promise<CheckpointInfo | undefined>;
getAllCheckpoints(): Promise<CheckpointInfo[]>;
// Logging and history
log(message: string, metadata?: Record<string, unknown>): void;
addHistoryEntry(type: 'custom', details: Record<string, unknown>): void;
// Lifecycle management
complete(details?: Record<string, unknown>): Promise<void>;
fail(reason: string, details?: Record<string, unknown>): Promise<void>;
// Service access
getService<T>(name: string, options?: Record<string, unknown>): T;
}ExecutionInfo
Information about the current execution context.
interface ExecutionInfo {
stepId: string;
flowId: string;
executionId: string;
attemptNumber: number;
}StepExecutionMetadata
Metadata about the step execution.
interface StepExecutionMetadata {
executionId: string;
status: StepExecutionStatus;
startedAt: Date;
completedAt?: Date;
succeeded?: boolean;
failureReason?: string;
attemptNumber: number;
[key: string]: unknown;
}StepExecutionStatus
Possible status values for step execution.
type StepExecutionStatus =
| 'pending'
| 'executing'
| 'completed'
| 'failed'
| 'skipped';StepHistoryEntry
History entry for tracking step execution events.
interface StepHistoryEntry {
timestamp: Date;
type: 'started' | 'checkpoint' | 'completed' | 'failed' | 'state_change' | 'custom';
details?: Record<string, unknown>;
}CheckpointInfo
Information about a step execution checkpoint.
interface CheckpointInfo {
id: string;
createdAt: Date;
state: Record<string, unknown>;
metadata?: Record<string, unknown>;
}Step Execution
executeStep<TInput, TOutput>(step: Step<TInput, TOutput>, input: TInput, options?: ExecuteStepOptions)
Executes a step with the given input and options.
import { executeStep } from '@zoopflow/core';
const result = await executeStep(stringTransformer, {
text: 'Hello, World!',
operation: 'uppercase'
});Parameters
| Name | Type | Required | Description |
|---|---|---|---|
step | Step<TInput, TOutput> | Yes | The step to execute |
input | TInput | Yes | Input data for the step |
options | ExecuteStepOptions | No | Options for execution |
Returns
Returns a Promise<TOutput> with the result of the step execution.
ExecuteStepOptions
Options for step execution.
interface ExecuteStepOptions {
context?: StepContext;
validateInput?: boolean;
validateOutput?: boolean;
retryConfig?: RetryConfig;
timeoutSeconds?: number;
}Step Registry
registerStep<TInput, TOutput>(step: Step<TInput, TOutput>)
Registers a step with the step registry.
import { registerStep } from '@zoopflow/core';
registerStep(stringTransformer);Parameters
| Name | Type | Description |
|---|---|---|
step | Step<TInput, TOutput> | The step to register |
getStep(id: string, version?: string)
Gets a registered step by ID and optionally version.
import { getStep } from '@zoopflow/core';
const step = getStep('examples.string.transform');
// or with version
const specificVersion = getStep('examples.string.transform', '1.0.0');Parameters
| Name | Type | Required | Description |
|---|---|---|---|
id | string | Yes | The ID of the step to retrieve |
version | string | No | The version of the step (defaults to latest) |
Returns
Returns the Step instance if found, otherwise undefined.
listSteps(options?: ListStepsOptions)
Lists registered steps based on optional filter criteria.
import { listSteps } from '@zoopflow/core';
// List all steps
const allSteps = listSteps();
// List steps with specific tag
const dataSteps = listSteps({ tags: ['data-processing'] });Parameters
| Name | Type | Required | Description |
|---|---|---|---|
options | ListStepsOptions | No | Filter options |
Returns
Returns an array of StepMetadata objects.
ListStepsOptions
Options for listing steps.
interface ListStepsOptions {
domain?: string;
tags?: string[];
includeDeprecated?: boolean;
}Retry Configuration
RetryConfig
Configuration for step retry behavior.
interface RetryConfig {
maxAttempts: number;
backoffCoefficient?: number;
initialIntervalSeconds?: number;
maxIntervalSeconds?: number;
retryableErrors?: string[];
}Properties
| Name | Type | Required | Description |
|---|---|---|---|
maxAttempts | number | Yes | Maximum number of retry attempts |
backoffCoefficient | number | No | Multiplier for retry interval (default: 2.0) |
initialIntervalSeconds | number | No | Initial retry interval in seconds (default: 1) |
maxIntervalSeconds | number | No | Maximum retry interval in seconds (default: 60) |
retryableErrors | string[] | No | List of error types that should trigger retry |