SDK Reference · v0.5.0

The aidran package, end to end.

The published aidran npm package is a CLI plus a typed schema surface — not a hosted API client. It bundles the aidran binary, re-exports @aidran/contracts (Zod event & DTO schemas), and re-exports @aidran/db (Drizzle ORM schemas for the corpus tables). Everything below is verifiable against the public scaffold.

Published packages · 4

1 · The aidran binary

Bare aidran in a TTY launches the interactive wizard; with a subcommand it runs that step directly. In a non-TTY context (CI, piped) the wizard is skipped and help is printed so logs never hang.

aidran

Interactive setup wizard (when run in a TTY). Prompts for DATABASE_URL, generates AIDRAN_API_KEY, writes config, runs migrate + verify.

DATABASE_URL (prefilled if set)
aidran init

Scaffold .env.example and drizzle.config.ts in the current directory. Drizzle config points at the bundled @aidran/db schema.

aidran migrate

Apply the bundled @aidran/db migrations to the database at $DATABASE_URL. Idempotent — re-running is safe once schema is current.

DATABASE_URL
aidran verify

Confirm $DATABASE_URL is reachable and required tables exist. Exits non-zero on a missing or mis-shaped schema.

DATABASE_URL
aidran help

Print usage. Also runs implicitly when invoked non-interactively (e.g. piped or in CI) so logs never hang.

2 · Import patterns

Three ways to bring the surface in. Namespace gives you collision-free access via contracts.* and db.*. Subpaths narrow the import. Scoped packages skip the meta-package entirely.

// One install. Namespaced for collision-free access.
import { contracts, db } from 'aidran';
 
const event = contracts.RecordIngestedSchema.parse(payload);
const records = db.records;
aidranBoth namespaces — `import { contracts, db } from "aidran"`
aidran/contractsDirect re-export of @aidran/contracts (all named exports)
aidran/dbDirect re-export of @aidran/db (schemas + Database type)
aidran/db/migrations-pathThe `migrationsFolder` constant — feed to drizzle-kit or drizzle-orm migrator

3 · contracts — types & schemas

Everything under @aidran/contracts is re-exported. Zod schemas suffixed *Schema parse runtime payloads; inferred TS types share the base name.

01aidran/contracts (events.ts)

Events

Past-tense facts emitted between services. Used as Render Workflow task payloads. Every event has a *Schema (Zod) and an inferred *TS type.

  • RecordIngestedSchema · RecordIngested
  • EntitiesExtractedSchema · EntitiesExtracted
  • EmbeddingReadySchema · EmbeddingReady
  • TopicAssignedSchema · TopicAssigned
02aidran/contracts (api.ts)

API DTOs

Request and response shapes for the public /v1/* HTTP API. Zod-validated at the route boundary; TS-typed on the way out.

  • HealthResponse
  • StoryListQuerySchema · StoryListQuery · StorySummary
  • StoryDetailResponse · StoryReferenceSummary
  • RecordListQuerySchema · RecordSummary
  • SignalListQuerySchema · SignalSummary
03aidran/contracts (enums.ts)

Enums

Canonical enum value lists, kept byte-aligned with the Postgres enums in @aidran/db. Imported by events, DTOs, and webhooks.

  • SOURCE_KINDS · SourceKindSchema · SourceKind
  • STORY_TYPES · StoryTypeSchema · StoryType
  • SIGNAL_SEVERITIES · SignalSeveritySchema
  • ARC_STATUSES · ArcStatusSchema · ComputedArcStatusSchema
  • CONTENT_TYPES · CONTENT_VARIANT_TYPES · CITATION_TYPES
04aidran/contracts (webhooks.ts)

Webhooks

Outbound webhook envelopes for hosted-AIDRAN integrations. Discriminated union over event_type so a single handler can switch over WebhookEvent.

  • StoryPublishedEventSchema
  • SignalDetectedEventSchema
  • EntityMentionedEventSchema
  • ArcUpdatedEventSchema
  • SavedSearchMatchEventSchema
  • WebhookEventSchema · WEBHOOK_EVENT_TYPES
05aidran/contracts (tiers.ts)

Tier policies

Subscription tier definitions and per-tier limit tables. The same constants enforced by the Delivery gateway in front of the API.

  • TIERS · Tier
  • TIER_LIMITS · TierLimits
  • WORKSPACE_ROLES · WORKSPACE_KINDS
06aidran/contracts (errors.ts)

Errors

Canonical error code constants. Match the response.code field returned by the Delivery API on 4xx / 5xx.

  • ERROR_UNAUTHORIZED · ERROR_FORBIDDEN
  • ERROR_RATE_LIMITED · ERROR_QUOTA_EXCEEDED
  • ERROR_TIER_LIMIT_EXCEEDED · ERROR_EXPORT_THROTTLED
  • ERROR_WORKSPACE_ROLE_REQUIRED · ERROR_WORKSPACE_SEAT_EXCEEDED
07aidran/contracts (ids.ts)

Branded IDs

Branded string / number ID types so RecordId, StoryId, EntityId, etc. cannot be accidentally swapped. Constructor functions cast safely at trusted boundaries.

  • RecordId · StoryId · EntityId
  • TopicId · SignalId · SourceId

4 · db — Drizzle ORM

Tables grouped by service-boundary ownership. AIDRAN's discipline: services do not import from one another; they read shared schemas from @aidran/db and write only to their owned tables.

  • A

    Records

    Ingestion team writes
    aidran/db (schema/records.ts)
    • · sources — source adapters and ingest cursors
    • · records — every ingested document, link, post, paper
    • · sourceKindEnum · recordCategoryEnum · contentTypeEnum
  • B

    Analysis

    Analysis team writes
    aidran/db (schema/analysis.ts)
    • · entities · entityMentions
    • · topics · topicAssignments
    • · embeddings · analysisCursors
  • C

    Signals

    Signal team writes
    aidran/db (schema/signals.ts)
    • · signals — novelty / velocity / divergence detections
    • · signalEvidence — joined records that justified each signal
    • · signalSeverityEnum · evidenceTargetEnum
  • D

    Editorial

    Editorial team writes
    aidran/db (schema/editorial.ts)
    • · stories · storyCitations · storyReferences
    • · storyContentVariants · storyRelated
    • · storyArcs · storyArcMembership
    • · seoMetadata
    • · storyTypeEnum · arcStatusEnum · citationTypeEnum
  • E

    Search-sync

    Search-sync team writes
    aidran/db (schema/search-sync.ts)
    • · searchSyncCheckpoints — per-target index sync watermarks

5 · Common workflows

Three load-bearing patterns. Validate an inbound event at the boundary; query the corpus through Drizzle; apply migrations programmatically when the CLI isn't in your runtime.

Validate an inbound event
import { RecordIngestedSchema } from 'aidran/contracts';
 
// Validate at the boundary — anything that survives parse() is typed.
const event = RecordIngestedSchema.parse(payload);
 
// event: { recordId, kind, contentType, externalId, capturedAt }
// - kind narrowed to a SourceKind union
// - capturedAt typed as an ISO datetime string
Query the corpus
import { drizzle } from 'drizzle-orm/node-postgres';
import { Pool } from 'pg';
import * as schema from 'aidran/db';
import { type Database } from 'aidran/db';
 
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const db: Database = drizzle(pool, { schema });
 
// Pull the 50 most recent records, typed end to end.
const rows = await db
.select()
.from(schema.records)
.orderBy(schema.records.capturedAt)
.limit(50);
Apply migrations from your own runtime
import { drizzle } from 'drizzle-orm/node-postgres';
import { migrate } from 'drizzle-orm/node-postgres/migrator';
import { Pool } from 'pg';
import { migrationsFolder } from 'aidran/db/migrations-path';
 
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
await migrate(drizzle(pool), { migrationsFolder });

Prefer the CLI (aidran migrate) for one-shot setup; use this pattern when you need to migrate from inside an existing service or test harness.

Source of truth

Every command, export, and subpath listed here is verifiable in github.com/AIDRAN/aidran under packages/aidran, packages/contracts, and packages/db.

Open repo ↗