Skip to content

AIDK API Reference / aidk-server

aidk-server ​

AIDK Server ​

Framework-agnostic utilities for engine backend implementations. Works with Express, NestJS, Fastify, or any Node.js server framework.

Features ​

  • Persistence Repositories - Store executions, messages, metrics
  • In-Memory Store - Development and testing storage
  • Context Utilities - Extract and manage request context
  • ID Generators - UUID and prefixed ID generation

Quick Start ​

typescript
import {
  createInMemoryRepositories,
  defaultContextExtractor,
  buildEngineContext,
} from 'aidk-server';

// Create persistence layer
const repos = createInMemoryRepositories();

// Extract context from request
const ctx = defaultContextExtractor(req.body, req.headers);

// Build engine context
const engineCtx = buildEngineContext({ ...ctx, executionId: 'exec_123' });

Classes ​

ClassDescription
InMemoryExecutionRepository-
InMemoryInteractionRepository-
InMemoryMessageBlockRepository-
InMemoryMessageRepository-
InMemoryMetricsRepository-
InMemoryToolStateRepository-

Interfaces ​

InterfaceDescription
ExecutionContextFull execution context passed to handlers. Built by middleware from request + config.
ExecutionContextConfigConfiguration for execution context middleware. Framework adapters use this to build their middleware.
ExecutionEntity-
ExecutionRepository-
InMemoryStore-
InteractionEntity-
InteractionRepository-
MessageBlockEntity-
MessageBlockRepository-
MessageEntity-
MessageRepository-
MetricsEntity-
MetricsRepository-
PersistenceRepositories-
RequestContextExtracted context from an incoming request. Framework adapters map their request shape to this.
RequestWithContextGeneric request-like object that can have context attached. Works with Express, Fastify, Koa, NestJS, etc.
StandardRequestBodyRaw request body shape (our conventions). Apps with different conventions provide their own extractor.
ToolStateEntity-
ToolStateRepository-

Type Aliases ​

Type AliasDescription
ContextExtractor-
IdGenerator-
InputTransformer-

Variables ​

VariableDescription
AIDK_CONTEXT_KEYSymbol key for storing AIDK context on request objects. Using a symbol prevents collisions with other properties.
defaultContextExtractorDefault context extractor following our conventions. Override this for apps with different field names or auth patterns.
defaultInputTransformerDefault input transformer following our conventions. Expects messages in body, transforms to Engine timeline format.
uuidV4GeneratorDefault UUID v4 generator

Functions ​

FunctionDescription
attachContextAttach AIDK context to a request object. Call this in your framework's middleware/interceptor after extracting context.
buildEngineContextBuild the withContext options for engine execution
clearStoreClear all data from a store
createContextExtractorCreate a context extractor with custom field mappings
createIdGeneratorCreate an ID generator that uses a provided function Useful for DB sequences, UUIDv7, etc.
createInMemoryRepositoriesCreate all repositories backed by an in-memory store
createInMemoryStoreCreate a new in-memory store instance
createInputTransformerCreate an input transformer with custom transformation logic
createPrefixedIdGeneratorCreate a prefixed ID generator
generateUUIDGenerate a UUID v4
getContextGet AIDK context from a request object. Returns undefined if no context has been attached.
messagesToTimelineTransform standard message format to Engine timeline. Uses loose typing to handle various frontend message formats.
requireContextGet AIDK context from a request object, throwing if not present.
resolveConfigResolved config with defaults applied

Released under the MIT License.