API Reference

Quick reference for SMRT framework APIs. See documentation for detailed usage.

Core Classes

SmrtObject Base class for persistent entities with AI methods (is, do)
SmrtCollection Collection manager for querying, CRUD, and batch operations
ObjectRegistry Runtime registry for class/field metadata (globalThis singleton)
DispatchBus Inter-agent asynchronous messaging with persistent subscriptions
GlobalInterceptors Plugin system for beforeList/Get/Save/Delete hooks
SchemaComparer Compares current vs. desired database schema
ManifestManager Reads, writes, and generates build-time manifests

Decorators

@smrt() Register a class with the framework for code generation
@field() Configure field constraints (required, unique, nullable, transient)
@meta() Mark field for STI meta storage in _meta_data JSONB
@foreignKey() Many-to-one relationship (same-package only)
@oneToMany() One-to-many relationship (transient, no DB column)
@manyToMany() Many-to-many via junction table (transient, no DB column)

AI Methods (SmrtObject)

is(criteria) Evaluate criteria against object, returns boolean
do(instructions) Perform action based on instructions, returns string

Object Methods (SmrtObject)

save() Upsert with STI validation, interceptors, auto-embeddings
delete() Delete object from database
initialize() Load field initializers, apply options, load from DB
loadRelated(field) Lazy-load a foreignKey relationship (cached)
loadRelatedMany(field) Lazy-load a oneToMany relationship
getSlug() Auto-generate slug from name/title/label/id
transformJSON(data) Override point for custom JSON serialization

Collection Methods (SmrtCollection)

create(options) Static factory to create collection instance
get(id|slug|filter) Retrieve single object by ID, slug, or filter
list(options) Query with where, orderBy, limit, offset, include
count(options) Count objects matching criteria
listByIds(ids) Batch fetch multiple objects in a single query
query(sql, params) Execute raw SQL query
getOrUpsert(match, defaults) Get existing or create new object

WHERE Operators

String operators in the field key. Arrays auto-detect as IN.

= (default) { status: 'active' }
>, <, >=, <= { 'price >': 100 }
!= { 'status !=': 'archived' }
in { 'category in': ['A', 'B'] } or auto-detected from arrays
not in { 'status not in': ['archived', 'deleted'] }
like { 'name like': '%widget%' }
contains { 'tags contains': 'featured' } (JSON)

DispatchBus Methods

emit(type, payload, meta) Emit an event to the dispatch queue
subscribe(options) Create persistent subscription (survives restarts)
on(pattern, handler) In-memory handler (immediate, fire-and-forget)
process(subscriber, handler) Process pending dispatches for subscriber
retry(options) Reset failed dispatches for retry
cleanup(options) Delete old completed/failed dispatches
list(filters) Query dispatches with status/source/type filters

Agent Exports

Agent Base agent class with lifecycle, dispatch, interests
AgentConfig DB-persisted agent configuration model
AgentSchedule Cron-based schedule model (_smrt_agent_schedules)
TenantAgent Agent-to-tenant junction with hierarchy resolution
AgentUIRegistry Singleton registry for agent admin panels (from /ui)

CLI Commands

smrt introspect Discover SMRT objects in project
smrt db:status Show pending schema changes
smrt db:migrate Apply migrations
smrt db:diff --generate Generate migration from changes
smrt db:rollback Rollback migrations
smrt docs:claude Generate .claude/smrt-framework.md
smrt generate:mcp Generate MCP server
smrt config:export Export agent config for SSG
smrt dispatch:* Dispatch management (list/process/retry/cleanup)

Internal Tables

_smrt_migrations Framework schema version tracking
_smrt_schema_migrations User schema migration tracking
_smrt_registry Object metadata persistence
_smrt_contexts Remembered context and learned patterns
_smrt_embeddings Vector embeddings for semantic search
_smrt_dispatch Inter-agent dispatch queue
_smrt_dispatch_subscriptions Persistent dispatch subscriptions
_smrt_signals Signal history audit log
_smrt_agent_schedules Cron-based agent schedule definitions

TypeDoc Reference

Full API documentation is generated from source with TypeDoc.

View on GitHub →