DEE Docs
API Reference

Engine

Core Engine API reference.

Engine

The main entry point for the Deterministic Execution Engine.

Constructor

const engine = new Engine(config: EngineConfig);
interface EngineConfig {
  database: string;               // PostgreSQL connection string
  redis: string;                  // Redis connection string
  scheduler?: {
    tickInterval?: number;        // ms between ticks (default: 1000)
    maxRunsPerTick?: number;      // max runs per tick (default: 500)
    partitionKey?: string;        // for multi-instance deployments
  };
  channels?: {
    email?: EmailChannelConfig;
    voice?: VoiceChannelConfig;
  };
  audit?: {
    retention?: { days: number }; // log retention (default: indefinite)
    archiveTo?: string;           // S3 URI for archived logs
  };
}

engine.execute(plan, params)

Starts a new execution run for a contact.

const run = await engine.execute(plan: ExecutionPlan, params: {
  contact: Contact;
  variables?: Record<string, unknown>;
  startAt?: number;  // tick to start at (default: current tick)
}): Promise<ExecutionRun>;

engine.getRun(runId)

Retrieves the current state of an execution run.

const run = await engine.getRun(runId: string): Promise<ExecutionRun>;

engine.pauseRun(runId)

Pauses an active run. The run can be resumed later.

await engine.pauseRun(runId: string): Promise<void>;

engine.resumeRun(runId)

Resumes a paused run.

await engine.resumeRun(runId: string): Promise<void>;

engine.cancelRun(runId, reason)

Cancels a run permanently. Cannot be undone.

await engine.cancelRun(runId: string, reason: string): Promise<void>;

engine.replay(runId, options)

Replays a completed run to verify determinism.

const result = await engine.replay(runId: string, options?: {
  dryRun?: boolean;  // default: true
}): Promise<ReplayResult>;
interface ReplayResult {
  identical: boolean;
  steps: Array<{
    id: string;
    originalResult: StepResult;
    replayedResult: StepResult;
    identical: boolean;
  }>;
  diffs: Array<{
    step: string;
    field: string;
    expected: unknown;
    actual: unknown;
  }>;
}

engine.getTimeline(runId)

Returns an ordered timeline of all events in a run.

const timeline = await engine.getTimeline(runId: string): Promise<TimelineEntry[]>;

engine.ingestEvent(event)

Feeds an external event (email open, reply, call outcome) into the engine.

await engine.ingestEvent(event: {
  type: string;          // 'email.opened', 'email.replied', etc.
  contactId: string;
  runId?: string;        // optional: associate with specific run
  stepId?: string;       // optional: associate with specific step
  data: Record<string, unknown>;
  occurredAt: Date;
}): Promise<void>;

On this page