Skip to content

API Reference

All public exports from minions-sdk. The library is framework-agnostic, storage-agnostic, and has zero runtime dependencies.

import {
// Types
type FieldType, type FieldValidation, type FieldDefinition,
type RelationType, type MinionStatus, type MinionPriority,
type Minion, type MinionType, type Relation,
type CreateMinionInput, type UpdateMinionInput, type CreateRelationInput,
type ExecutionResult, type Executable,
type ValidationError, type ValidationResult,
// Validation
validateField, validateFields,
// Schemas
noteType, linkType, fileType, contactType,
agentType, teamType, thoughtType, promptTemplateType, testCaseType, taskType,
builtinTypes,
// Registry
TypeRegistry,
// Relations
RelationGraph,
// Lifecycle
createMinion, updateMinion, softDelete, hardDelete, restoreMinion,
// Evolution
migrateMinion,
// Utilities
generateId, now, SPEC_VERSION,
} from 'minions-sdk';

Validate a single field value against its FieldDefinition.

function validateField(value: unknown, field: FieldDefinition): ValidationError[]

Returns a list of ValidationError objects. Empty list means valid.

Rules:

  • If required is true and the value is undefined | null | "", validation fails immediately.
  • If the value is absent and not required, no further checks are performed.
  • Otherwise, type-specific validation is applied (see Field Types).

Validate all fields of a minion against a MinionType schema.

function validateFields(
fields: Record<string, unknown>,
schema: FieldDefinition[]
): ValidationResult

Returns { valid: boolean, errors: ValidationError[] } (TS) or a ValidationResult object (Python).


Pre-defined MinionType objects for all built-in types:

TypeScriptPythonSlugLayer
noteTypenote_typenote
linkTypelink_typelink
fileTypefile_typefile
contactTypecontact_typecontact
agentTypeagent_typeagentDefinition
teamTypeteam_typeteamOrganization
thoughtTypethought_typethoughtMemory
promptTemplateTypeprompt_template_typeprompt-templateInterface
testCaseTypetest_case_typetest-caseEvaluation
taskTypetask_typetaskExecution

Array/list containing all 10 built-in types.


An in-memory registry for MinionType objects. Pre-loaded with all built-in types by default.

const registry = new TypeRegistry(loadBuiltins?: boolean);
registry.register(type: MinionType): void; // throws on duplicate
registry.getById(id: string): MinionType | undefined;
registry.getBySlug(slug: string): MinionType | undefined;
registry.list(): MinionType[];
registry.has(id: string): boolean;
registry.remove(id: string): boolean;

In-memory relation graph manager. Provides utilities to add, remove, query, and traverse typed relations between minions.

const graph = new RelationGraph();
graph.add(input: CreateRelationInput): Relation;
graph.remove(id: string): boolean;
graph.removeByMinionId(minionId: string): number;
graph.get(id: string): Relation | undefined;
graph.list(): Relation[];
graph.getFromSource(sourceId: string, type?: RelationType): Relation[];
graph.getToTarget(targetId: string, type?: RelationType): Relation[];
graph.getChildren(parentId: string): string[];
graph.getParents(childId: string): string[];
graph.getTree(rootId: string): string[]; // depth-first, handles cycles
graph.getNetwork(minionId: string): string[];

// Create — generates id, timestamps, validates, applies defaults
const { minion, validation } = createMinion(input, type);
// Update — merges fields, re-validates, strips undefined
const { minion: updated } = updateMinion(minion, input, type);
// Soft delete — sets deletedAt/deletedBy
const deleted = softDelete(minion, 'user-123');
// Hard delete — removes all relations from the graph
hardDelete(minion, graph);
// Restore — clears deletedAt/deletedBy
const restored = restoreMinion(deleted);

Note: hardDelete / hard_delete handles relation cleanup only (this is intentional — Minions is storage-agnostic). After calling it, you must also remove the minion object from your storage layer (array, database, etc.).


Migrates a minion when its type schema changes:

ChangeBehavior
Field removedValue moves to _legacy
Field type changed (incompatible)Value moves to _legacy
Field addedGets default value or remains absent
updatedAtAlways updated

ConceptTypeScriptPython
Field namescamelCasesnake_case
Return style{ minion, validation }(minion, validation) tuple
Relation input keyssourceId, targetIdsource_id, target_id
Method namesgetBySlug()get_by_slug()
Cross-SDK JSONNative objectminion.to_dict() → camelCase
Error on duplicateThrows ErrorRaises ValueError

Returns a new UUID v4 string.

Returns the current time as an ISO 8601 string.

Current specification version ("0.1.0").


TypeDescription
MinionA structured object instance
MinionTypeSchema/definition of a kind of minion
RelationTyped directional link between two minions
TypeDescription
CreateMinionInputInput for createMinion / create_minion
UpdateMinionInputInput for updateMinion / update_minion (all fields optional)
CreateRelationInputInput for RelationGraph.add
TypeValues
FieldTypestring, number, boolean, date, select, multi-select, url, email, textarea, tags, json, array
RelationTypeparent_of, depends_on, implements, relates_to, inspired_by, triggers, references, blocks, alternative_to, part_of, follows, integration_link
MinionStatusactive, todo, in_progress, completed, cancelled
MinionPrioritylow, medium, high, urgent
TypeDescription
ExecutableInterface / Protocol with execute(input) → ExecutionResult
ExecutionResult{ output, status, startedAt, completedAt, error?, metadata? }
TypeDescription
ValidationError{ field: string, message: string, value?: unknown }
ValidationResult{ valid: boolean, errors: ValidationError[] }
FieldValidation{ minLength?, maxLength?, min?, max?, pattern? }
FieldDefinition{ name, type, label?, description?, required?, defaultValue?, options?, validation? }