@mastra/core
Version:
128 lines • 5.68 kB
TypeScript
import type { ValidatableStepFlowEntry, WorkflowValidationInput } from '../dynamic/validate/types.js';
import type { Predicate } from '../predicate/index.js';
import type { WorkflowScheduleConfig } from '../scheduler/types.js';
import type { SerializedSingleStepEntry, SerializedStepOptions } from '../types.js';
export type WorkflowBuilderJsonValue = string | number | boolean | null | WorkflowBuilderJsonValue[] | {
[key: string]: WorkflowBuilderJsonValue;
};
export type WorkflowBuilderJsonObject = {
[key: string]: WorkflowBuilderJsonValue;
};
export type WorkflowBuilderStepOptions = SerializedStepOptions;
/**
* Authoring leaf entries are the canonical serialized leaf union minus
* code-only `step` descriptors (a persisted definition cannot reference a
* live Step object). Derived, not duplicated: when the serialized union
* changes, these change with it.
*/
export type WorkflowBuilderSingleStepEntry = Exclude<SerializedSingleStepEntry, {
type: 'step';
}>;
export type WorkflowBuilderAgentEntry = Extract<WorkflowBuilderSingleStepEntry, {
type: 'agent';
}>;
export type WorkflowBuilderToolEntry = Extract<WorkflowBuilderSingleStepEntry, {
type: 'tool';
}>;
export type WorkflowBuilderClassifierEntry = Extract<WorkflowBuilderSingleStepEntry, {
type: 'classifier';
}>;
export type WorkflowBuilderMappingEntry = Extract<WorkflowBuilderSingleStepEntry, {
type: 'mapping';
}>;
export type WorkflowBuilderWorkflowEntry = Extract<WorkflowBuilderSingleStepEntry, {
type: 'workflow';
}>;
export type WorkflowBuilderExecutableInnerEntry = Exclude<WorkflowBuilderSingleStepEntry, {
type: 'mapping';
}>;
/**
* Container entries are hand-written *narrowings* of the serialized union:
* declarative predicates are required (closure conditions can't be authored),
* fluent-only debug labels (`serializedConditions`/`serializedCondition`) are
* absent, and `sleepUntil.date` is the wire's ISO string rather than a Date.
* The static assertions at the bottom of this file prove each narrowing stays
* inside the canonical union — drift is a compile error.
*/
/**
* Optional identity/display fields shared by every control-flow entry.
* Mirrors `StepFlowEntryOptions` on the canonical union.
*/
interface WorkflowBuilderEntryDisplayFields {
description?: string;
metadata?: Record<string, any>;
}
export interface WorkflowBuilderParallelEntry extends WorkflowBuilderEntryDisplayFields {
type: 'parallel';
id?: string;
steps: WorkflowBuilderExecutableInnerEntry[];
}
export interface WorkflowBuilderForeachEntry extends WorkflowBuilderEntryDisplayFields {
type: 'foreach';
id?: string;
step: WorkflowBuilderExecutableInnerEntry;
opts?: {
concurrency: number;
};
}
export interface WorkflowBuilderSleepEntry extends WorkflowBuilderEntryDisplayFields {
type: 'sleep';
id: string;
duration: number;
}
export interface WorkflowBuilderSleepUntilEntry extends WorkflowBuilderEntryDisplayFields {
type: 'sleepUntil';
id: string;
date: string;
}
export interface WorkflowBuilderConditionalEntry extends WorkflowBuilderEntryDisplayFields {
type: 'conditional';
id?: string;
steps: WorkflowBuilderExecutableInnerEntry[];
predicates: Predicate[];
}
export interface WorkflowBuilderLoopEntry extends WorkflowBuilderEntryDisplayFields {
type: 'loop';
id?: string;
step: WorkflowBuilderExecutableInnerEntry;
loopType: 'dowhile' | 'dountil';
predicate: Predicate;
}
export type WorkflowBuilderGraphEntry = WorkflowBuilderSingleStepEntry | WorkflowBuilderParallelEntry | WorkflowBuilderForeachEntry | WorkflowBuilderSleepEntry | WorkflowBuilderSleepUntilEntry | WorkflowBuilderConditionalEntry | WorkflowBuilderLoopEntry;
export interface WorkflowBuilderDefinition {
id: string;
description?: string;
metadata?: Record<string, unknown>;
inputSchema: WorkflowBuilderJsonObject;
outputSchema: WorkflowBuilderJsonObject;
stateSchema?: WorkflowBuilderJsonObject;
requestContextSchema?: WorkflowBuilderJsonObject;
graph: WorkflowBuilderGraphEntry[];
/**
* Optional declarative schedule config(s). JSON-safe by construction
* (literal inputData/initialState/requestContext only), so it persists with
* the definition and is re-declared on rehydration.
*/
schedule?: WorkflowScheduleConfig | WorkflowScheduleConfig[];
}
type Extends<A, B> = [A] extends [B] ? true : false;
type Expect<T extends true> = T;
/**
* Compile-time drift guards: the authoring universe must remain a subset of
* the canonical serialized/wire union the validation core operates on. If a
* serialized variant gains a required field (or an authoring type drifts),
* these tuple members stop typechecking and the build fails.
*/
export type WorkflowBuilderTypeAssertions = [
Expect<Extends<WorkflowBuilderGraphEntry, ValidatableStepFlowEntry>>,
Expect<Extends<WorkflowBuilderDefinition, WorkflowValidationInput>>
];
export declare const WORKFLOW_BUILDER_SUPPORTED_STEP_TYPES: readonly ['agent', 'tool', 'classifier', 'mapping', 'workflow', 'parallel', 'foreach', 'sleep', 'sleepUntil', 'conditional', 'loop'];
export type WorkflowBuilderSupportedStepType = (typeof WORKFLOW_BUILDER_SUPPORTED_STEP_TYPES)[number];
export { WORKFLOW_BUILDER_AUTHORING_CONSTRAINTS, WORKFLOW_BUILDER_AUTHORING_PLAYBOOK } from './authoring-playbook.js';
export declare function normalizeWorkflowBuilderDefinition(input: unknown): WorkflowBuilderDefinition;
export * from './preflight.js';
export * from './inspection.js';
export * from './authoring-schema.js';
export * from './agent.js';
//# sourceMappingURL=index.d.ts.map