import type { ToolsInput } from '@mastra/core/agent'; import type { Mastra } from '@mastra/core/mastra'; import type { InMemoryTaskStore } from '@mastra/server/a2a/store'; import type { DynamicModule, MiddlewareConsumer, NestModule, Type } from '@nestjs/common'; /** * Options for MastraModule configuration. */ export interface MastraModuleOptions { /** The Mastra instance to register */ mastra: Mastra; /** Route prefix (default: '/api') */ prefix?: string; /** Request body size limits */ bodyLimitOptions?: { /** Max body size in bytes (default: 10MB) */ maxSize?: number; /** Max per-file size in bytes (default: 50MB) */ maxFileSize?: number; /** Temp directory for file uploads */ tempDir?: string; /** Allowed MIME types for file uploads */ allowedMimeTypes?: string[]; }; /** * Rate limiting options. * Rate limiting is ON by default - set enabled: false to disable. */ rateLimitOptions?: { /** Enable/disable rate limiting (default: true) */ enabled?: boolean; /** Default requests per window (default: 100) */ defaultLimit?: number; /** Window size in ms (default: 60000 = 1 minute) */ windowMs?: number; /** Stricter limit for /generate endpoints (default: 10) */ generateLimit?: number; }; /** Graceful shutdown options */ shutdownOptions?: { /** Max wait time for in-flight requests in ms (default: 30000) */ timeoutMs?: number; /** Send shutdown event to SSE clients (default: true) */ notifyClients?: boolean; }; /** Observability options */ tracingOptions?: { /** Enable tracing (default: auto-detect @opentelemetry/api) */ enabled?: boolean; /** Service name for spans */ serviceName?: string; }; /** Context parsing options */ contextOptions?: { /** Fail on parse errors (default: false) */ strict?: boolean; /** Log parse warnings (default: true) */ logWarnings?: boolean; }; /** Additional tools to register */ tools?: ToolsInput; /** Task store for async operations */ taskStore?: InMemoryTaskStore; /** Mastra-internal authentication configuration. Disabled by default. * Most NestJS apps have their own global auth guards -- Mastra defers to those. * Enable this only if you want Mastra's built-in token auth. */ auth?: { /** Enable Mastra's internal auth (default: false) */ enabled?: boolean; /** Allow `?apiKey=` query auth for backward compatibility (default: false) */ allowQueryApiKey?: boolean; }; /** Per-route auth configuration */ customRouteAuthConfig?: Map; /** Streaming configuration */ streamOptions?: { /** Redact sensitive data from streams (default: true) */ redact?: boolean; /** Send SSE heartbeats every N ms (default: disabled). Set <= 0 to disable. */ heartbeatMs?: number; }; /** MCP transport options */ mcpOptions?: { /** Run in serverless mode */ serverless?: boolean; /** Custom session ID generator */ sessionIdGenerator?: () => string; }; } /** * Options for async module configuration. */ export interface MastraModuleAsyncOptions { /** Modules to import for dependency injection */ imports?: any[]; /** Factory function to create module options */ useFactory?: (...args: any[]) => Promise | MastraModuleOptions; /** Dependencies to inject into the factory function */ inject?: any[]; /** Use an existing provider */ useExisting?: Type; /** Use a class to create options */ useClass?: Type; } /** * Interface for async options factory. */ export interface MastraModuleOptionsFactory { createMastraOptions(): Promise | MastraModuleOptions; } /** * NestJS module for integrating Mastra into your application. * * @example * Basic registration: * ```typescript * @Module({ * imports: [ * MastraModule.register({ * mastra: new Mastra({ agents: { ... } }), * prefix: '/api', * }), * ], * }) * export class AppModule {} * ``` * * @example * With rate limiting disabled: * ```typescript * MastraModule.register({ * mastra, * rateLimitOptions: { enabled: false }, * }) * ``` * * @example * Async registration: * ```typescript * MastraModule.registerAsync({ * imports: [ConfigModule], * useFactory: (config: ConfigService) => ({ * mastra: new Mastra({ ... }), * prefix: config.get('MASTRA_PREFIX', '/api'), * }), * inject: [ConfigService], * }) * ``` */ export declare class MastraModule implements NestModule { /** * Register Mastra with the NestJS application. * * @param options - Configuration options including the Mastra instance * @returns Dynamic module configuration */ static register(options: MastraModuleOptions): DynamicModule; /** * Register Mastra asynchronously for when configuration depends on other services. * * @param options - Async configuration options * @returns Dynamic module configuration */ static registerAsync(options: MastraModuleAsyncOptions): DynamicModule; /** * Configure middleware for the module. * Order matters: body limit must run BEFORE JSON parsing. * * Middleware is scoped to MastraController to avoid affecting other routes * in the user's NestJS application. */ configure(consumer: MiddlewareConsumer): void; } //# sourceMappingURL=mastra.module.d.ts.map