import type { ToolsInput } from '@mastra/core/agent'; import type { Mastra } from '@mastra/core/mastra'; import type { RequestContext } from '@mastra/core/request-context'; import type { InMemoryTaskStore } from '@mastra/server/a2a/store'; import type { ParsedRequestParams, ServerRoute } from '@mastra/server/server-adapter'; import { MastraServer as MastraServerBase } from '@mastra/server/server-adapter'; import type Koa from 'koa'; import type { Context, Middleware } from 'koa'; export { createAuthMiddleware } from './auth-middleware.js'; export type { KoaAuthMiddlewareOptions } from './auth-middleware.js'; declare module 'koa' { interface DefaultState { mastra: Mastra; requestContext: RequestContext; tools: ToolsInput; abortSignal: AbortSignal; taskStore: InMemoryTaskStore; customRouteAuthConfig?: Map; } interface Request { body?: unknown; } } export declare class MastraServer extends MastraServerBase { private readonly activeRouteDispatchers; init(): Promise; /** * Register a global error-handling middleware at the top of the middleware chain. * This acts as a safety net for errors that propagate past route handlers * (e.g., from auth middleware, context middleware, or when route handlers re-throw). * * When `server.onError` is configured, calls it and uses the response. * Otherwise provides a default JSON error response. * * Errors are emitted on the app for logging (Koa convention) but NOT re-thrown, * so this middleware is the final error boundary. Users who need custom error handling * should use `server.onError` or register their own middleware between this and the routes. */ private registerErrorMiddleware; /** * Try to handle an error using the `server.onError` hook. * Creates a minimal context shim compatible with the Hono-style onError signature. * * @returns true if the error was handled and the response was set on ctx */ private handleOnError; createContextMiddleware(): Middleware; private getRouteDispatcherGroup; private createRouteDispatcherMiddleware; private findRegisteredRoute; private handleMatchedRoute; stream(route: ServerRoute, ctx: Context, result: { fullStream: ReadableStream; }): Promise; getParams(route: ServerRoute, ctx: Context): Promise; /** * Parse multipart/form-data using @fastify/busboy. * Converts file uploads to Buffers and parses JSON field values. * * @param ctx - The Koa context object * @param maxFileSize - Optional maximum file size in bytes */ private parseMultipartFormData; sendResponse(route: ServerRoute, ctx: Context, result: unknown, prefix?: string): Promise; registerRoute(app: Koa, route: ServerRoute, { prefix: prefixParam }?: { prefix?: string; }): Promise; /** * Convert Express-style path to regex for matching */ private pathToRegex; /** * Extract parameter names from path */ private extractParamNames; registerCustomApiRoutes(): Promise; registerContextMiddleware(): void; registerAuthMiddleware(): void; registerHttpLoggingMiddleware(): void; } //# sourceMappingURL=index.d.ts.map