/** * API module exports * * Provides HTTP API for cron job management and heartbeat functionality. */ import { type Express, type Router } from 'express'; import { type Server as HttpServer } from 'node:http'; import type { ServerResponse } from 'node:http'; import type { SQLiteDatabase } from '../sqlite.js'; import { type ExecutionLogStore } from './cron-handler.js'; import { type HeartbeatTracker } from './heartbeat-handler.js'; import { CronScheduler } from '../scheduler/index.js'; import { SkillRegistry } from '../skills/skill-registry.js'; import type { SystemHealthReport } from '../observability/health-check.js'; import { type AgentRawRouterOptions } from './agent-raw-handler.js'; import { type AgentSituationRouterOptions } from './agent-situation-handler.js'; import { type AgentContextRouterOptions } from './agent-context-handler.js'; import { type AgentGraphRouterOptions } from './agent-graph-handler.js'; export * from './types.js'; export type { ExecutionLogStore } from './cron-handler.js'; export { InMemoryLogStore, ScheduleStoreAdapter } from './cron-handler.js'; export type { HeartbeatTracker } from './heartbeat-handler.js'; export { InMemoryHeartbeatTracker, DEFAULT_HEARTBEAT_PROMPT } from './heartbeat-handler.js'; export { asyncHandler, validateRequired, ApiError } from './error-handler.js'; export { createTokenRouter, initTokenUsageTable, insertTokenUsage } from './token-handler.js'; export type { TokenUsageRecord } from './token-handler.js'; /** * API server options */ export interface ApiServerOptions { /** Scheduler instance */ scheduler: CronScheduler; /** Port to listen on (default: 3847) */ port?: number; /** Log store for execution logs (default: InMemoryLogStore) */ logStore?: ExecutionLogStore; /** Heartbeat tracker (default: InMemoryHeartbeatTracker) */ heartbeatTracker?: HeartbeatTracker; /** Heartbeat execution callback */ onHeartbeat?: (prompt: string) => Promise<{ success: boolean; error?: string; }>; /** Enable automatic process killing on port conflicts (default: false) */ enableAutoKillPort?: boolean; /** Sessions database instance (for token tracking) */ db?: SQLiteDatabase; /** Memory database instance (for intelligence queries — mama-memory.db) */ memoryDb?: SQLiteDatabase; /** Transaction-capable mama-core adapter for worker situation packets */ memoryAdapter?: AgentSituationRouterOptions['memoryAdapter'] & AgentGraphRouterOptions['memoryAdapter'] & AgentContextRouterOptions['memoryAdapter']; /** Wiki directory path (for wiki API) */ wikiPath?: string; /** Skill registry instance */ skillRegistry?: SkillRegistry; /** Health score service for /api/metrics/health */ healthService?: { compute(windowMs?: number): unknown; }; /** Connection-based health check service */ healthCheckService?: { check(): Promise; }; /** RawStore for connector feed queries */ rawStore?: import('../connectors/framework/raw-store.js').RawStore; /** List of enabled connector names */ enabledConnectors?: string[]; /** AgentEventBus for notices */ eventBus?: { getRecentNotices(limit: number): Array<{ agent: string; action: string; target: string; timestamp: number; }>; }; /** Runtime envelope bootstrap metadata for authenticated status reporting */ envelope?: ApiEnvelopeMetadata; /** Runtime envelope authority for worker-scoped raw evidence reads */ envelopeAuthority?: import('../envelope/authority.js').EnvelopeAuthority; /** Test seam for raw query functions; production loads mama-core raw-query lazily */ rawQuery?: AgentRawRouterOptions['rawQuery']; /** Test seam for agent situation packet building */ situationBuilder?: AgentSituationRouterOptions['buildPacket']; /** Test seam for agent situation timestamps */ situationNow?: AgentSituationRouterOptions['now']; /** Shared context compile service for HTTP/gateway packet compilation */ contextCompileService?: AgentContextRouterOptions['contextCompileService']; } export type ApiEnvelopeMetadata = { issuance: 'off' | 'enabled' | 'required'; key_id?: string; key_version?: number; }; /** * API server instance */ export interface ApiServer { /** Express app instance */ app: Express; /** HTTP server instance */ server: HttpServer | null; /** Report slots store */ reportStore: import('./report-handler.js').ReportStore; /** SSE clients for report updates */ reportSseClients: Set; /** Start the server */ start(): Promise; /** Stop the server */ stop(): Promise; /** Get the port the server is listening on */ port: number; } /** * Create and configure the API server */ export declare function createApiServer(options: ApiServerOptions): ApiServer; /** * Create API routers without starting a server * Useful for integrating into an existing Express app */ export declare function createApiRouters(options: ApiServerOptions): { cronRouter: Router; heartbeatRouter: Router; }; //# sourceMappingURL=index.d.ts.map