UNPKG

@mastra/core

Version:
121 lines (116 loc) 4.14 kB
'use strict'; var chunkQPLN2BVV_cjs = require('../chunk-QPLN2BVV.cjs'); var chunkWSD4JNMB_cjs = require('../chunk-WSD4JNMB.cjs'); var chunkYNLHR2WT_cjs = require('../chunk-YNLHR2WT.cjs'); var chunkXSOONORA_cjs = require('../chunk-XSOONORA.cjs'); // src/server/request-types.ts function getRequestHeader(request, name) { if (request instanceof Request) { return request.headers.get(name); } return request.raw?.headers.get(name) ?? request.headers?.get(name) ?? request.header(name) ?? null; } function getWebRequest(request) { if (request instanceof Request) { return request; } return request.raw instanceof Request ? request.raw : void 0; } // src/server/base.ts var MastraServerBase = class extends chunkWSD4JNMB_cjs.MastraBase { #app; constructor({ app, name }) { super({ component: chunkYNLHR2WT_cjs.RegisteredLogger.SERVER, name: name ?? "Server" }); this.#app = app; } /** * Get the app instance. * * Returns the server app that was passed to the constructor. This allows users * to access the underlying server framework's app for direct operations * like calling routes via app.fetch() (Hono) or using the app for testing. * * @template T - The expected type of the app (defaults to TApp) * @returns The app instance cast to T. Callers are responsible for ensuring T matches the actual app type. * * @example * ```typescript * const app = adapter.getApp<Hono>(); * const response = await app.fetch(new Request('http://localhost/api/agents')); * ``` */ getApp() { return this.#app; } /** * Protected getter for subclasses to access the app. * This allows subclasses to use `this.app` naturally. */ get app() { return this.#app; } }; // src/server/index.ts function validateOptions(path, options) { if (options.method === void 0) { throw new chunkXSOONORA_cjs.MastraError({ id: "MASTRA_SERVER_API_INVALID_ROUTE_OPTIONS", text: `Invalid options for route "${path}", missing "method" property`, domain: chunkXSOONORA_cjs.ErrorDomain.MASTRA_SERVER, category: chunkXSOONORA_cjs.ErrorCategory.USER }); } if (options.handler === void 0 && options.createHandler === void 0) { throw new chunkXSOONORA_cjs.MastraError({ id: "MASTRA_SERVER_API_INVALID_ROUTE_OPTIONS", text: `Invalid options for route "${path}", you must define a "handler" or "createHandler" property`, domain: chunkXSOONORA_cjs.ErrorDomain.MASTRA_SERVER, category: chunkXSOONORA_cjs.ErrorCategory.USER }); } if (options.handler !== void 0 && options.createHandler !== void 0) { throw new chunkXSOONORA_cjs.MastraError({ id: "MASTRA_SERVER_API_INVALID_ROUTE_OPTIONS", text: `Invalid options for route "${path}", you can only define one of the following properties: "handler" or "createHandler"`, domain: chunkXSOONORA_cjs.ErrorDomain.MASTRA_SERVER, category: chunkXSOONORA_cjs.ErrorCategory.USER }); } } function registerApiRoute(path, options) { validateOptions(path, options); return { path, method: options.method, handler: options.handler, createHandler: options.createHandler, openapi: options.openapi, middleware: options.middleware, cors: options.cors, requiresAuth: options.requiresAuth, requiresPermission: options.requiresPermission, fga: options.fga }; } function defineAuth(config) { return config; } Object.defineProperty(exports, "CompositeAuth", { enumerable: true, get: function () { return chunkQPLN2BVV_cjs.CompositeAuth; } }); Object.defineProperty(exports, "MastraAuthProvider", { enumerable: true, get: function () { return chunkQPLN2BVV_cjs.MastraAuthProvider; } }); Object.defineProperty(exports, "SimpleAuth", { enumerable: true, get: function () { return chunkQPLN2BVV_cjs.SimpleAuth; } }); exports.MastraServerBase = MastraServerBase; exports.defineAuth = defineAuth; exports.getRequestHeader = getRequestHeader; exports.getWebRequest = getWebRequest; exports.registerApiRoute = registerApiRoute; //# sourceMappingURL=index.cjs.map //# sourceMappingURL=index.cjs.map