Skip to main content
A Smithers workflow is built from a single factory call. You hand it Zod schemas; it owns the storage layer and hands back a typed set of JSX components plus the smithers() wrapper that produces a runnable SmithersWorkflow. createSmithers is synchronous and SQLite-only. The other factories exist for the cases it cannot serve: Postgres/PGlite backends, environment-resolved backends, store migration, and non-JSX (external) build functions.
import {
  createSmithers,
  createSmithersPostgres,
  openSmithersBackend,
  migrateSmithersStore,
  createExternalSmithers,
} from "smithers-orchestrator";
smithers, Workflow, Task, useCtx, outputs, tables, and db are returned by the factory, not imported. The component set is documented in the Components reference; this page covers the factories themselves.

createSmithers

Schema-driven workflow API over a local SQLite database. The schemas you pass become both the output tables and the typed outputs accessor. This is the default entry point for almost every workflow.
function createSmithers<Schemas extends Record<string, ZodObject>>(
  schemas: Schemas,
  opts?: CreateSmithersOptions,
): CreateSmithersApi<Schemas>;
schemas
Record<string, ZodObject>
required
A map of output name to Zod object schema. Each key becomes a property on outputs and a backing table. Use the reserved input key to type the workflow’s run input.
opts
CreateSmithersOptions
Optional metadata and storage configuration.
CreateSmithersApi
object
The typed authoring surface.
const { Workflow, Task, smithers, outputs } = createSmithers({
  input: z.object({ topic: z.string() }),
  research: z.object({ findings: z.string() }),
});

export default smithers((ctx) => (
  <Workflow name="research">
    <Task id="research" output={outputs.research} agent={myAgent}>
      {`Research ${ctx.input.topic}`}
    </Task>
  </Workflow>
));
Source create.js · CreateSmithersApi.ts · Tests create-unit.test.js · See also Get started, JSX overview

createSmithersPostgres

PostgreSQL or PGlite equivalent of createSmithers. Asynchronous because it opens a connection, and it returns an extra close(). Reach for it when a run must outlive a single process or be shared across hosts.
function createSmithersPostgres<Schemas extends Record<string, ZodObject>>(
  schemas: Schemas,
  opts?: CreateSmithersPostgresOptions,
): Promise<CreateSmithersApi<Schemas> & { close: () => Promise<void> }>;
schemas
Record<string, ZodObject>
required
Same as createSmithers.
opts
CreateSmithersPostgresOptions
Extends CreateSmithersOptions with the backend connection. A discriminated union on provider.
Promise<CreateSmithersApi & { close }>
object
The same API as createSmithers, plus close() to release the connection pool. Call it when the process is done with the backend.
const api = await createSmithersPostgres(schemas, {
  provider: "postgres",
  connectionString: process.env.DATABASE_URL,
});
Source create.js · See also Control-plane deployment, migrateSmithersStore

openSmithersBackend

Resolve the backend from the environment instead of hard-coding it. Reads smithers.config / env vars and returns whichever of SQLite, PGlite, or Postgres they select. Use it in shared CLIs and servers that should honor a deployment’s configured store.
function openSmithersBackend<Schemas extends Record<string, ZodObject>>(
  schemas?: Schemas,
  opts?: OpenSmithersBackendOptions,
): Promise<CreateSmithersApi<Schemas> & { close?: () => Promise<void> }>;
schemas
Record<string, ZodObject>
Optional output schemas. Omit to open the backend without registering tables.
opts
OpenSmithersBackendOptions
Extends CreateSmithersOptions.
Promise<CreateSmithersApi & { close? }>
object
The authoring API for the resolved backend. close() is present when the backend holds a connection (PGlite/Postgres).
Source openSmithersBackend.js · Tests openSmithersBackend.test.js · See also Package configuration

migrateSmithersStore

Copy an existing SQLite store into PGlite or Postgres, table by table, and write a migration marker. Use it once when graduating a project from the local SQLite default to a shared backend.
function migrateSmithersStore(
  opts?: MigrateSmithersStoreOptions,
): Promise<SmithersMigrationResult>;
opts
MigrateSmithersStoreOptions
Promise<SmithersMigrationResult>
object
Source migrateSmithersStore.js · Tests migrateSmithersStore.test.js

createExternalSmithers

Build a SmithersWorkflow from a plain build function instead of JSX. The build function returns a HostNodeJson tree that maps 1:1 to what the JSX renderer produces, so a workflow can be authored in any language that can emit that JSON.
function createExternalSmithers<S extends Record<string, ZodObject>>(
  config: ExternalSmithersConfig<S>,
): SmithersWorkflow<S> & { tables: Record<string, any>; cleanup: () => void };
config
ExternalSmithersConfig<S>
required
SmithersWorkflow & { tables, cleanup }
object
A runnable workflow plus its backing tables and a cleanup() to release the database.
Source external/index.js · Tests create-unit.test.js · See also SerializedCtx, HostNodeJson
Once you have a SmithersWorkflow, run it with the Runtime API or the CLI. For the full type surface, see the Types reference.