Skip to main content
This page documents every public type exported by the smithers-orchestrator package.

Workflow Types

SmithersWorkflow<Schema>

The top-level workflow definition object, returned by createSmithers and consumed by runWorkflow and the server.
type SmithersWorkflow<Schema> = {
  db: unknown;
  build: (ctx: SmithersCtx<Schema>) => React.ReactElement;
  opts: SmithersWorkflowOptions;
  schemaRegistry?: Map<string, SchemaRegistryEntry>;
};
FieldTypeDescription
dbunknownThe Drizzle ORM database instance (typically BunSQLiteDatabase)
build(ctx: SmithersCtx<Schema>) => ReactElementFunction that renders the workflow JSX tree given a context
optsSmithersWorkflowOptionsWorkflow-level options
schemaRegistryMap<string, SchemaRegistryEntry>Optional map of output table names to their schema entries

SmithersWorkflowOptions

Options set at the workflow definition level.
type SmithersWorkflowOptions = {
  cache?: boolean;
};
FieldTypeDefaultDescription
cachebooleanundefinedWhen true, enables caching of task outputs across runs with the same inputs

SchemaRegistryEntry

An entry in the workflow’s schema registry, mapping a table name to its Drizzle table and Zod validation schema.
type SchemaRegistryEntry = {
  table: any;
  zodSchema: import("zod").ZodObject<any>;
};
FieldTypeDescription
tableanyThe Drizzle ORM table definition
zodSchemaZodObject<any>The Zod schema used for output validation

Context Types

SmithersCtx<Schema>

The context object passed to the workflow build function. Provides access to run state, input data, and output accessors.
interface SmithersCtx<Schema> {
  runId: string;
  iteration: number;
  iterations?: Record<string, number>;
  input: Schema extends { input: infer T } ? T : never;
  outputs: OutputAccessor<Schema>;

  output<T extends keyof Schema>(
    table: Schema[T],
    key: OutputKey,
  ): InferRow<Schema[T]>;

  outputMaybe<T extends keyof Schema>(
    table: Schema[T],
    key: OutputKey,
  ): InferRow<Schema[T]> | undefined;

  latest(table: any, nodeId: string): any;

  latestArray(value: unknown, schema: import("zod").ZodType): any[];

  iterationCount(table: any, nodeId: string): number;
}
Field / MethodTypeDescription
runIdstringThe current workflow run ID
iterationnumberThe current Ralph loop iteration (0 for non-looped tasks)
iterationsRecord<string, number>Map of Ralph IDs to their current iteration count
inputInferred from SchemaThe typed input data passed to runWorkflow
outputsOutputAccessor<Schema>Callable accessor for all output rows from a table
output(table, key)InferRow<T>Get a specific output row by table and key. Throws if the output does not exist.
outputMaybe(table, key)InferRow<T> | undefinedGet a specific output row, returning undefined if not found
latest(table, nodeId)anyGet the latest output row for a nodeId (highest iteration)
latestArray(value, schema)any[]Parse/validate an array field using a Zod schema, dropping invalid items
iterationCount(table, nodeId)numberCount distinct iterations for a nodeId in a table

OutputKey

Identifies a specific task output by node ID and optional iteration.
type OutputKey = {
  nodeId: string;
  iteration?: number;
};
FieldTypeDefaultDescription
nodeIdstringThe task node ID
iterationnumber0The Ralph loop iteration

OutputAccessor<Schema>

A callable object that retrieves output rows. Can be called as a function or accessed as a property.
type OutputAccessor<Schema> = ((table: any) => any[]) & Record<string, any[]>;

InferRow<TTable>

Utility type that extracts the select row type from a Drizzle table.
type InferRow<TTable> = TTable extends { $inferSelect: infer R } ? R : never;

Run Types

RunOptions

Options passed to runWorkflow to configure execution.
type RunOptions = {
  runId?: string;
  input: Record<string, unknown>;
  maxConcurrency?: number;
  onProgress?: (e: SmithersEvent) => void;
  signal?: AbortSignal;
  resume?: boolean;
  workflowPath?: string;
  rootDir?: string;
  logDir?: string | null;
  allowNetwork?: boolean;
  maxOutputBytes?: number;
  toolTimeoutMs?: number;
};
FieldTypeDefaultDescription
runIdstringAuto-generatedCustom run identifier
inputRecord<string, unknown>Input data for the workflow (required). In the manual API it should match the input table schema; in the schema-driven API it is stored as a JSON payload.
maxConcurrencynumberundefinedMaximum number of tasks to execute in parallel
onProgress(e: SmithersEvent) => voidundefinedCallback invoked for every lifecycle event
signalAbortSignalundefinedSignal to cancel the run
resumebooleanfalseResume from the last checkpoint instead of starting fresh
workflowPathstringundefinedPath to the workflow file (used for tool context)
rootDirstringundefinedSandbox root directory for tools
logDirstring | nullundefinedDirectory for event log files (stream.ndjson)
allowNetworkbooleanfalseAllow network access in the bash tool
maxOutputBytesnumber200000Maximum output bytes for tool calls
toolTimeoutMsnumber60000Timeout for tool executions in milliseconds

RunResult

The result returned when a workflow run completes.
type RunResult = {
  runId: string;
  status: "finished" | "failed" | "cancelled" | "waiting-approval";
  output?: unknown;
  error?: unknown;
};
FieldTypeDescription
runIdstringThe run identifier
statusstringTerminal status of the run
outputunknownFinal output data (if finished successfully)
errorunknownError details (if failed)

RunStatus

The possible states of a workflow run.
type RunStatus =
  | "running"
  | "waiting-approval"
  | "finished"
  | "failed"
  | "cancelled";
ValueDescription
"running"The workflow is actively executing tasks
"waiting-approval"A task with needsApproval is waiting for human approval or denial
"finished"All tasks completed successfully
"failed"A task failed and was not recoverable
"cancelled"The run was cancelled via AbortSignal or the cancel API

Task Types

TaskDescriptor

The internal representation of a task extracted from the JSX tree. This is what the engine schedules and executes.
type TaskDescriptor = {
  nodeId: string;
  ordinal: number;
  iteration: number;
  ralphId?: string;

  outputTable: Table | null;
  outputTableName: string;
  outputSchema?: import("zod").ZodObject<any>;

  parallelGroupId?: string;
  parallelMaxConcurrency?: number;

  needsApproval: boolean;
  skipIf: boolean;
  retries: number;
  timeoutMs: number | null;
  continueOnFail: boolean;

  agent?: AgentLike;
  prompt?: string;
  staticPayload?: unknown;

  label?: string;
  meta?: Record<string, unknown>;
};
FieldTypeDescription
nodeIdstringUnique identifier for this task (from the id prop)
ordinalnumberPosition in the execution order (depth-first traversal)
iterationnumberCurrent Ralph loop iteration
ralphIdstringID of the parent Ralph loop (if any)
outputTableTable | nullDrizzle table for persisting the output
outputTableNamestringName of the output table
outputSchemaZodObject<any>Optional Zod schema for validating agent output
parallelGroupIdstringID of the parent <Parallel> group (if any)
parallelMaxConcurrencynumberMax concurrency limit from the parent <Parallel>
needsApprovalbooleanWhether the task requires human approval before execution
skipIfbooleanWhether this task should be skipped
retriesnumberNumber of retry attempts on failure
timeoutMsnumber | nullTask-level timeout in milliseconds
continueOnFailbooleanWhether to continue the workflow if this task fails
agentAgentLikeThe AI agent assigned to execute this task
promptstringThe prompt text for the agent (from task children)
staticPayloadunknownPre-computed payload (for non-agent tasks)
labelstringHuman-readable label for display
metaRecord<string, unknown>Arbitrary metadata attached to the task

AgentLike

Type alias for any object that implements the AI SDK Agent interface.
type AgentLike = Agent<any, any, any>;

Graph Types

GraphSnapshot

A snapshot of the workflow graph at a specific render frame.
type GraphSnapshot = {
  runId: string;
  frameNo: number;
  xml: XmlNode | null;
  tasks: TaskDescriptor[];
};
FieldTypeDescription
runIdstringThe run identifier
frameNonumberThe render frame number (monotonically increasing)
xmlXmlNode | nullThe rendered XML tree representation
tasksTaskDescriptor[]Ordered list of tasks extracted from the tree

XmlNode

A node in the internal XML tree representation. Either an element or text node.
type XmlNode = XmlElement | XmlText;

XmlElement

An element node in the XML tree.
type XmlElement = {
  kind: "element";
  tag: string;
  props: Record<string, string>;
  children: XmlNode[];
};
FieldTypeDescription
kind"element"Discriminant tag
tagstringElement tag name (e.g., "Workflow", "Task", "Parallel")
propsRecord<string, string>Element attributes
childrenXmlNode[]Child nodes

XmlText

A text node in the XML tree.
type XmlText = {
  kind: "text";
  text: string;
};
FieldTypeDescription
kind"text"Discriminant tag
textstringText content

Event Types

SmithersEvent

A discriminated union of all lifecycle events emitted during workflow execution. Every event includes runId and timestampMs fields.
type SmithersEvent =
  | RunStarted
  | RunStatusChanged
  | RunFinished
  | RunFailed
  | RunCancelled
  | FrameCommitted
  | NodePending
  | NodeStarted
  | NodeFinished
  | NodeFailed
  | NodeCancelled
  | NodeSkipped
  | NodeRetrying
  | NodeWaitingApproval
  | ApprovalRequested
  | ApprovalGranted
  | ApprovalDenied
  | ToolCallStarted
  | ToolCallFinished
  | NodeOutput
  | RevertStarted
  | RevertFinished;

Run Events

Event TypeFieldsDescription
RunStartedrunId, timestampMsWorkflow execution has begun
RunStatusChangedrunId, status: RunStatus, timestampMsRun status transition
RunFinishedrunId, timestampMsAll tasks completed successfully
RunFailedrunId, error: unknown, timestampMsWorkflow failed with an error
RunCancelledrunId, timestampMsWorkflow was cancelled

Frame Events

Event TypeFieldsDescription
FrameCommittedrunId, frameNo: number, xmlHash: string, timestampMsA render frame was persisted to the database

Node Events

Event TypeFieldsDescription
NodePendingrunId, nodeId, iteration, timestampMsTask is queued for execution
NodeStartedrunId, nodeId, iteration, attempt, timestampMsTask execution began
NodeFinishedrunId, nodeId, iteration, attempt, timestampMsTask completed successfully
NodeFailedrunId, nodeId, iteration, attempt, error: unknown, timestampMsTask failed with an error
NodeCancelledrunId, nodeId, iteration, attempt?, reason?, timestampMsTask was cancelled
NodeSkippedrunId, nodeId, iteration, timestampMsTask was skipped (due to skipIf)
NodeRetryingrunId, nodeId, iteration, attempt, timestampMsTask is being retried after a failure

Approval Events

Event TypeFieldsDescription
NodeWaitingApprovalrunId, nodeId, iteration, timestampMsTask is waiting for human approval
ApprovalRequestedrunId, nodeId, iteration, timestampMsApproval was formally requested
ApprovalGrantedrunId, nodeId, iteration, timestampMsHuman approved the task
ApprovalDeniedrunId, nodeId, iteration, timestampMsHuman denied the task

Tool Events

Event TypeFieldsDescription
ToolCallStartedrunId, nodeId, iteration, attempt, toolName, seq, timestampMsAn agent tool call began
ToolCallFinishedrunId, nodeId, iteration, attempt, toolName, seq, status: "success" | "error", timestampMsAn agent tool call completed

Output Events

Event TypeFieldsDescription
NodeOutputrunId, nodeId, iteration, attempt, text, stream: "stdout" | "stderr", timestampMsAgent produced output text

Revert Events

Event TypeFieldsDescription
RevertStartedrunId, nodeId, iteration, attempt, jjPointer, timestampMsA version control revert operation started
RevertFinishedrunId, nodeId, iteration, attempt, jjPointer, success, error?, timestampMsA version control revert operation completed

Component Props

WorkflowProps

Props for the <Workflow> component.
type WorkflowProps = {
  name: string;
  cache?: boolean;
  children?: React.ReactNode;
};
PropTypeRequiredDescription
namestringYesWorkflow name used in logging and the database
cachebooleanNoEnable output caching for this workflow
childrenReactNodeNoChild components (tasks, sequences, parallels, etc.)

TaskProps<Row>

Props for the <Task> component.
type TaskProps<Row> = {
  key?: string;
  id: string;
  output: Table | string;
  outputSchema?: import("zod").ZodObject<any>;
  agent?: AgentLike;
  skipIf?: boolean;
  needsApproval?: boolean;
  timeoutMs?: number;
  retries?: number;
  continueOnFail?: boolean;
  label?: string;
  meta?: Record<string, unknown>;
  children: string | Row | React.ReactNode;
};
PropTypeRequiredDescription
idstringYesUnique task identifier within the workflow
outputTable | stringYesDrizzle table or table name for persisting results
outputSchemaZodObject<any>NoZod schema for validating agent output
agentAgentLikeNoAI agent to execute the task
skipIfbooleanNoSkip this task when true
needsApprovalbooleanNoPause for human approval before execution
timeoutMsnumberNoTask-level timeout in milliseconds
retriesnumberNoNumber of retry attempts on failure (default: 0)
continueOnFailbooleanNoContinue the workflow even if this task fails
labelstringNoHuman-readable label
metaRecord<string, unknown>NoArbitrary metadata
childrenstring | Row | ReactNodeYesPrompt text, static payload, or nested elements

SequenceProps

Props for the <Sequence> component. Tasks inside a sequence execute in order.
type SequenceProps = {
  skipIf?: boolean;
  children?: React.ReactNode;
};
PropTypeRequiredDescription
skipIfbooleanNoSkip the entire sequence when true
childrenReactNodeNoChild tasks or components

ParallelProps

Props for the <Parallel> component. Tasks inside a parallel group execute concurrently.
type ParallelProps = {
  maxConcurrency?: number;
  skipIf?: boolean;
  children?: React.ReactNode;
};
PropTypeRequiredDescription
maxConcurrencynumberNoMaximum number of concurrent tasks in this group
skipIfbooleanNoSkip the entire parallel group when true
childrenReactNodeNoChild tasks or components

BranchProps

Props for the <Branch> component. Conditionally renders one of two branches.
type BranchProps = {
  if: boolean;
  then: React.ReactElement;
  else?: React.ReactElement;
  skipIf?: boolean;
};
PropTypeRequiredDescription
ifbooleanYesCondition to evaluate
thenReactElementYesElement to render when condition is true
elseReactElementNoElement to render when condition is false
skipIfbooleanNoSkip the branch entirely when true

RalphProps

Props for the <Ralph> component. Loops its children until a condition is met.
type RalphProps = {
  id?: string;
  until: boolean;
  maxIterations?: number;
  onMaxReached?: "fail" | "return-last";
  skipIf?: boolean;
  children?: React.ReactNode;
};
PropTypeRequiredDescription
idstringNoUnique identifier for the Ralph loop (auto-generated if omitted)
untilbooleanYesExit condition. When true, the loop stops.
maxIterationsnumberNoMaximum number of loop iterations
onMaxReached"fail" | "return-last"NoBehavior when maxIterations is exceeded: fail the run or return the last successful output
skipIfbooleanNoSkip the loop entirely when true
childrenReactNodeNoChild tasks executed each iteration

Error Types

SmithersError

Standard error shape returned by the HTTP server.
type SmithersError = {
  code: string;
  message: string;
  details?: Record<string, unknown>;
};
FieldTypeDescription
codestringMachine-readable error code (e.g., "INVALID_REQUEST", "UNAUTHORIZED")
messagestringHuman-readable error description
detailsRecord<string, unknown>Optional additional error context

Server Types

ServerOptions

Options for startServer. See the HTTP Server page for full details.
type ServerOptions = {
  port?: number;
  db?: BunSQLiteDatabase<any>;
  authToken?: string;
  maxBodyBytes?: number;
  rootDir?: string;
  allowNetwork?: boolean;
};

Tool Context Types

ToolContext

Internal context provided to tools via AsyncLocalStorage. Not typically used directly.
type ToolContext = {
  db: SmithersDb;
  runId: string;
  nodeId: string;
  iteration: number;
  attempt: number;
  rootDir: string;
  allowNetwork: boolean;
  maxOutputBytes: number;
  timeoutMs: number;
  seq: number;
};