@mastra/next 0.2.10-alpha.0 → 0.2.10-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @mastra/next
2
2
 
3
+ ## 0.2.10-alpha.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`a211d09`](https://github.com/mastra-ai/mastra/commit/a211d09185dc65a746534914cf38b67f21ee9bac), [`4cbd63c`](https://github.com/mastra-ai/mastra/commit/4cbd63cfa7fd1ce8be4199ed01a20c709794fee1), [`05db566`](https://github.com/mastra-ai/mastra/commit/05db566fcbdcbf33d0bffca0c72ec30129e2e3ca), [`8124754`](https://github.com/mastra-ai/mastra/commit/8124754ae89fbc69f8136d1df4a91904d0f84c4e)]:
8
+ - @mastra/core@1.54.0-alpha.2
9
+ - @mastra/server@1.54.0-alpha.2
10
+ - @mastra/hono@1.5.11-alpha.2
11
+
12
+ ## 0.2.10-alpha.1
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies [[`ce93a3c`](https://github.com/mastra-ai/mastra/commit/ce93a3c114ea1cbfbd576f3db41d7c26c9844f5b), [`5718a22`](https://github.com/mastra-ai/mastra/commit/5718a229281dcfd36bcd1f42a242e3717e510a33), [`5807d3a`](https://github.com/mastra-ai/mastra/commit/5807d3ae1d259b8b7d6df7e5bf2b485c694af9c8), [`57661af`](https://github.com/mastra-ai/mastra/commit/57661afeca52ff9af4e72675ede2134fa503d5a5), [`57661af`](https://github.com/mastra-ai/mastra/commit/57661afeca52ff9af4e72675ede2134fa503d5a5), [`57661af`](https://github.com/mastra-ai/mastra/commit/57661afeca52ff9af4e72675ede2134fa503d5a5), [`5718a22`](https://github.com/mastra-ai/mastra/commit/5718a229281dcfd36bcd1f42a242e3717e510a33), [`57661af`](https://github.com/mastra-ai/mastra/commit/57661afeca52ff9af4e72675ede2134fa503d5a5), [`d1b7e3a`](https://github.com/mastra-ai/mastra/commit/d1b7e3a978a309a5653eeaa490d2d6c7c53bd093), [`c093146`](https://github.com/mastra-ai/mastra/commit/c0931466404d3c521308ea119cb165bb7e695155)]:
17
+ - @mastra/core@1.54.0-alpha.1
18
+ - @mastra/hono@1.5.11-alpha.1
19
+ - @mastra/server@1.54.0-alpha.1
20
+
3
21
  ## 0.2.10-alpha.0
4
22
 
5
23
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -1,67 +1,73 @@
1
- 'use strict';
2
-
3
- var hono$1 = require('@mastra/hono');
4
- var store = require('@mastra/server/a2a/store');
5
- var hono = require('hono');
6
- var vercel = require('hono/vercel');
7
-
8
- // src/index.ts
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _mastra_hono = require("@mastra/hono");
3
+ let _mastra_server_a2a_store = require("@mastra/server/a2a/store");
4
+ let hono = require("hono");
5
+ let hono_vercel = require("hono/vercel");
6
+ //#region src/index.ts
7
+ /**
8
+ * Creates Next.js App Router route handlers for a Mastra instance.
9
+ *
10
+ * Mount this in a catch-all route file such as:
11
+ * `app/api/[...mastra]/route.ts`
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * // app/api/[...mastra]/route.ts
16
+ * import { createNextRouteHandler } from '@mastra/next';
17
+ * import { mastra } from '../../../mastra';
18
+ *
19
+ * export const { GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD } = createNextRouteHandler({
20
+ * mastra,
21
+ * });
22
+ * ```
23
+ */
9
24
  function createNextRouteHandler(options) {
10
- const { mastra, tools = {}, prefix = "/api" } = options;
11
- let appPromise;
12
- function getApp() {
13
- if (!appPromise) {
14
- appPromise = initApp(mastra, tools, prefix);
15
- }
16
- return appPromise;
17
- }
18
- const handler = async (req) => {
19
- const app = await getApp();
20
- const honoHandler = vercel.handle(app);
21
- return honoHandler(req);
22
- };
23
- return {
24
- GET: handler,
25
- POST: handler,
26
- PUT: handler,
27
- DELETE: handler,
28
- PATCH: handler,
29
- OPTIONS: handler,
30
- HEAD: handler
31
- };
25
+ const { mastra, tools = {}, prefix = "/api" } = options;
26
+ let appPromise;
27
+ function getApp() {
28
+ if (!appPromise) appPromise = initApp(mastra, tools, prefix);
29
+ return appPromise;
30
+ }
31
+ const handler = async (req) => {
32
+ return (0, hono_vercel.handle)(await getApp())(req);
33
+ };
34
+ return {
35
+ GET: handler,
36
+ POST: handler,
37
+ PUT: handler,
38
+ DELETE: handler,
39
+ PATCH: handler,
40
+ OPTIONS: handler,
41
+ HEAD: handler
42
+ };
32
43
  }
33
44
  async function initApp(mastra, tools, prefix) {
34
- const app = new hono.Hono();
35
- const serverConfig = mastra.getServer();
36
- const apiRoutes = serverConfig?.apiRoutes;
37
- const customRouteAuthConfig = /* @__PURE__ */ new Map();
38
- if (apiRoutes) {
39
- for (const route of apiRoutes) {
40
- const requiresAuth = route.requiresAuth !== false;
41
- const routeKey = `${route.method}:${route.path}`;
42
- customRouteAuthConfig.set(routeKey, requiresAuth);
43
- }
44
- }
45
- const taskStore = new store.InMemoryTaskStore();
46
- const bodySizeLimit = serverConfig?.bodySizeLimit ?? 4.5 * 1024 * 1024;
47
- const honoServerAdapter = new hono$1.MastraServer({
48
- app,
49
- mastra,
50
- tools,
51
- taskStore,
52
- bodyLimitOptions: {
53
- maxSize: bodySizeLimit,
54
- onError: (_err) => ({ error: "Request body too large" })
55
- },
56
- customRouteAuthConfig,
57
- customApiRoutes: apiRoutes,
58
- prefix,
59
- mcpOptions: serverConfig?.mcpOptions
60
- });
61
- await honoServerAdapter.init();
62
- return app;
45
+ const app = new hono.Hono();
46
+ const serverConfig = mastra.getServer();
47
+ const apiRoutes = serverConfig?.apiRoutes;
48
+ const customRouteAuthConfig = /* @__PURE__ */ new Map();
49
+ if (apiRoutes) for (const route of apiRoutes) {
50
+ const requiresAuth = route.requiresAuth !== false;
51
+ const routeKey = `${route.method}:${route.path}`;
52
+ customRouteAuthConfig.set(routeKey, requiresAuth);
53
+ }
54
+ await new _mastra_hono.MastraServer({
55
+ app,
56
+ mastra,
57
+ tools,
58
+ taskStore: new _mastra_server_a2a_store.InMemoryTaskStore(),
59
+ bodyLimitOptions: {
60
+ maxSize: serverConfig?.bodySizeLimit ?? 4.5 * 1024 * 1024,
61
+ onError: (_err) => ({ error: "Request body too large" })
62
+ },
63
+ customRouteAuthConfig,
64
+ customApiRoutes: apiRoutes,
65
+ prefix,
66
+ mcpOptions: serverConfig?.mcpOptions
67
+ }).init();
68
+ return app;
63
69
  }
64
-
70
+ //#endregion
65
71
  exports.createNextRouteHandler = createNextRouteHandler;
66
- //# sourceMappingURL=index.cjs.map
72
+
67
73
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["handle","Hono","InMemoryTaskStore","MastraServer"],"mappings":";;;;;;;;AA6DO,SAAS,uBAAuB,OAAA,EAAqD;AAC1F,EAAA,MAAM,EAAE,MAAA,EAAQ,KAAA,GAAQ,EAAC,EAAG,MAAA,GAAS,QAAO,GAAI,OAAA;AAGhD,EAAA,IAAI,UAAA;AAEJ,EAAA,SAAS,MAAA,GAAwB;AAC/B,IAAA,IAAI,CAAC,UAAA,EAAY;AACf,MAAA,UAAA,GAAa,OAAA,CAAQ,MAAA,EAAQ,KAAA,EAAO,MAAM,CAAA;AAAA,IAC5C;AACA,IAAA,OAAO,UAAA;AAAA,EACT;AAGA,EAAA,MAAM,OAAA,GAA4B,OAAM,GAAA,KAAO;AAC7C,IAAA,MAAM,GAAA,GAAM,MAAM,MAAA,EAAO;AACzB,IAAA,MAAM,WAAA,GAAcA,cAAO,GAAG,CAAA;AAC9B,IAAA,OAAO,YAAY,GAAG,CAAA;AAAA,EACxB,CAAA;AAEA,EAAA,OAAO;AAAA,IACL,GAAA,EAAK,OAAA;AAAA,IACL,IAAA,EAAM,OAAA;AAAA,IACN,GAAA,EAAK,OAAA;AAAA,IACL,MAAA,EAAQ,OAAA;AAAA,IACR,KAAA,EAAO,OAAA;AAAA,IACP,OAAA,EAAS,OAAA;AAAA,IACT,IAAA,EAAM;AAAA,GACR;AACF;AAEA,eAAe,OAAA,CAAQ,MAAA,EAAgB,KAAA,EAAmB,MAAA,EAA+B;AACvF,EAAA,MAAM,GAAA,GAAM,IAAIC,SAAA,EAAK;AAErB,EAAA,MAAM,YAAA,GAAe,OAAO,SAAA,EAAU;AACtC,EAAA,MAAM,YAAoC,YAAA,EAAc,SAAA;AAGxD,EAAA,MAAM,qBAAA,uBAA4B,GAAA,EAAqB;AACvD,EAAA,IAAI,SAAA,EAAW;AACb,IAAA,KAAA,MAAW,SAAS,SAAA,EAAW;AAC7B,MAAA,MAAM,YAAA,GAAe,MAAM,YAAA,KAAiB,KAAA;AAC5C,MAAA,MAAM,WAAW,CAAA,EAAG,KAAA,CAAM,MAAM,CAAA,CAAA,EAAI,MAAM,IAAI,CAAA,CAAA;AAC9C,MAAA,qBAAA,CAAsB,GAAA,CAAI,UAAU,YAAY,CAAA;AAAA,IAClD;AAAA,EACF;AAEA,EAAA,MAAM,SAAA,GAAY,IAAIC,uBAAA,EAAkB;AAExC,EAAA,MAAM,aAAA,GAAgB,YAAA,EAAc,aAAA,IAAiB,GAAA,GAAM,IAAA,GAAO,IAAA;AAGlE,EAAA,MAAM,iBAAA,GAAoB,IAAIC,mBAAA,CAAa;AAAA,IACzC,GAAA;AAAA,IACA,MAAA;AAAA,IACA,KAAA;AAAA,IACA,SAAA;AAAA,IACA,gBAAA,EAAkB;AAAA,MAChB,OAAA,EAAS,aAAA;AAAA,MACT,OAAA,EAAS,CAAC,IAAA,MAAmB,EAAE,OAAO,wBAAA,EAAyB;AAAA,KACjE;AAAA,IACA,qBAAA;AAAA,IACA,eAAA,EAAiB,SAAA;AAAA,IACjB,MAAA;AAAA,IACA,YAAY,YAAA,EAAc;AAAA,GAC3B,CAAA;AAGD,EAAA,MAAM,kBAAkB,IAAA,EAAK;AAE7B,EAAA,OAAO,GAAA;AACT","file":"index.cjs","sourcesContent":["import type { ToolsInput } from '@mastra/core/agent';\nimport type { Mastra } from '@mastra/core/mastra';\nimport type { ApiRoute } from '@mastra/core/server';\nimport { MastraServer } from '@mastra/hono';\nimport type { HonoApp } from '@mastra/hono';\nimport { InMemoryTaskStore } from '@mastra/server/a2a/store';\nimport { Hono } from 'hono';\nimport { handle } from 'hono/vercel';\n\nexport interface NextRouteHandlerOptions {\n /**\n * The Mastra instance to serve.\n */\n mastra: Mastra;\n\n /**\n * Tools to register with the server.\n * @default {}\n */\n tools?: ToolsInput;\n\n /**\n * API route prefix. Should match the path where the catch-all route is mounted.\n * For example, if you mount at `app/api/[...mastra]/route.ts`, set this to `/api`.\n * @default '/api'\n */\n prefix?: string;\n}\n\n/**\n * A Next.js route handler function compatible with App Router.\n */\nexport type NextRouteHandler = (req: Request) => Response | Promise<Response>;\n\nexport interface NextRouteHandlers {\n GET: NextRouteHandler;\n POST: NextRouteHandler;\n PUT: NextRouteHandler;\n DELETE: NextRouteHandler;\n PATCH: NextRouteHandler;\n OPTIONS: NextRouteHandler;\n HEAD: NextRouteHandler;\n}\n\n/**\n * Creates Next.js App Router route handlers for a Mastra instance.\n *\n * Mount this in a catch-all route file such as:\n * `app/api/[...mastra]/route.ts`\n *\n * @example\n * ```ts\n * // app/api/[...mastra]/route.ts\n * import { createNextRouteHandler } from '@mastra/next';\n * import { mastra } from '../../../mastra';\n *\n * export const { GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD } = createNextRouteHandler({\n * mastra,\n * });\n * ```\n */\nexport function createNextRouteHandler(options: NextRouteHandlerOptions): NextRouteHandlers {\n const { mastra, tools = {}, prefix = '/api' } = options;\n\n // Lazily initialize the Hono app so the module-level export works synchronously\n let appPromise: Promise<Hono> | undefined;\n\n function getApp(): Promise<Hono> {\n if (!appPromise) {\n appPromise = initApp(mastra, tools, prefix);\n }\n return appPromise;\n }\n\n // Build a handler for each HTTP method\n const handler: NextRouteHandler = async req => {\n const app = await getApp();\n const honoHandler = handle(app);\n return honoHandler(req);\n };\n\n return {\n GET: handler,\n POST: handler,\n PUT: handler,\n DELETE: handler,\n PATCH: handler,\n OPTIONS: handler,\n HEAD: handler,\n };\n}\n\nasync function initApp(mastra: Mastra, tools: ToolsInput, prefix: string): Promise<Hono> {\n const app = new Hono();\n\n const serverConfig = mastra.getServer();\n const apiRoutes: ApiRoute[] | undefined = serverConfig?.apiRoutes;\n\n // Store custom route auth configurations\n const customRouteAuthConfig = new Map<string, boolean>();\n if (apiRoutes) {\n for (const route of apiRoutes) {\n const requiresAuth = route.requiresAuth !== false;\n const routeKey = `${route.method}:${route.path}`;\n customRouteAuthConfig.set(routeKey, requiresAuth);\n }\n }\n\n const taskStore = new InMemoryTaskStore();\n\n const bodySizeLimit = serverConfig?.bodySizeLimit ?? 4.5 * 1024 * 1024;\n\n // Create the MastraServer adapter\n const honoServerAdapter = new MastraServer({\n app: app as unknown as HonoApp,\n mastra,\n tools,\n taskStore,\n bodyLimitOptions: {\n maxSize: bodySizeLimit,\n onError: (_err: unknown) => ({ error: 'Request body too large' }),\n },\n customRouteAuthConfig,\n customApiRoutes: apiRoutes,\n prefix,\n mcpOptions: serverConfig?.mcpOptions,\n });\n\n // Initialize: registers context middleware, auth, routes, etc.\n await honoServerAdapter.init();\n\n return app;\n}\n"]}
1
+ {"version":3,"file":"index.cjs","names":["Hono","MastraServer","InMemoryTaskStore"],"sources":["../src/index.ts"],"sourcesContent":["import type { ToolsInput } from '@mastra/core/agent';\nimport type { Mastra } from '@mastra/core/mastra';\nimport type { ApiRoute } from '@mastra/core/server';\nimport { MastraServer } from '@mastra/hono';\nimport type { HonoApp } from '@mastra/hono';\nimport { InMemoryTaskStore } from '@mastra/server/a2a/store';\nimport { Hono } from 'hono';\nimport { handle } from 'hono/vercel';\n\nexport interface NextRouteHandlerOptions {\n /**\n * The Mastra instance to serve.\n */\n mastra: Mastra;\n\n /**\n * Tools to register with the server.\n * @default {}\n */\n tools?: ToolsInput;\n\n /**\n * API route prefix. Should match the path where the catch-all route is mounted.\n * For example, if you mount at `app/api/[...mastra]/route.ts`, set this to `/api`.\n * @default '/api'\n */\n prefix?: string;\n}\n\n/**\n * A Next.js route handler function compatible with App Router.\n */\nexport type NextRouteHandler = (req: Request) => Response | Promise<Response>;\n\nexport interface NextRouteHandlers {\n GET: NextRouteHandler;\n POST: NextRouteHandler;\n PUT: NextRouteHandler;\n DELETE: NextRouteHandler;\n PATCH: NextRouteHandler;\n OPTIONS: NextRouteHandler;\n HEAD: NextRouteHandler;\n}\n\n/**\n * Creates Next.js App Router route handlers for a Mastra instance.\n *\n * Mount this in a catch-all route file such as:\n * `app/api/[...mastra]/route.ts`\n *\n * @example\n * ```ts\n * // app/api/[...mastra]/route.ts\n * import { createNextRouteHandler } from '@mastra/next';\n * import { mastra } from '../../../mastra';\n *\n * export const { GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD } = createNextRouteHandler({\n * mastra,\n * });\n * ```\n */\nexport function createNextRouteHandler(options: NextRouteHandlerOptions): NextRouteHandlers {\n const { mastra, tools = {}, prefix = '/api' } = options;\n\n // Lazily initialize the Hono app so the module-level export works synchronously\n let appPromise: Promise<Hono> | undefined;\n\n function getApp(): Promise<Hono> {\n if (!appPromise) {\n appPromise = initApp(mastra, tools, prefix);\n }\n return appPromise;\n }\n\n // Build a handler for each HTTP method\n const handler: NextRouteHandler = async req => {\n const app = await getApp();\n const honoHandler = handle(app);\n return honoHandler(req);\n };\n\n return {\n GET: handler,\n POST: handler,\n PUT: handler,\n DELETE: handler,\n PATCH: handler,\n OPTIONS: handler,\n HEAD: handler,\n };\n}\n\nasync function initApp(mastra: Mastra, tools: ToolsInput, prefix: string): Promise<Hono> {\n const app = new Hono();\n\n const serverConfig = mastra.getServer();\n const apiRoutes: ApiRoute[] | undefined = serverConfig?.apiRoutes;\n\n // Store custom route auth configurations\n const customRouteAuthConfig = new Map<string, boolean>();\n if (apiRoutes) {\n for (const route of apiRoutes) {\n const requiresAuth = route.requiresAuth !== false;\n const routeKey = `${route.method}:${route.path}`;\n customRouteAuthConfig.set(routeKey, requiresAuth);\n }\n }\n\n const taskStore = new InMemoryTaskStore();\n\n const bodySizeLimit = serverConfig?.bodySizeLimit ?? 4.5 * 1024 * 1024;\n\n // Create the MastraServer adapter\n const honoServerAdapter = new MastraServer({\n app: app as unknown as HonoApp,\n mastra,\n tools,\n taskStore,\n bodyLimitOptions: {\n maxSize: bodySizeLimit,\n onError: (_err: unknown) => ({ error: 'Request body too large' }),\n },\n customRouteAuthConfig,\n customApiRoutes: apiRoutes,\n prefix,\n mcpOptions: serverConfig?.mcpOptions,\n });\n\n // Initialize: registers context middleware, auth, routes, etc.\n await honoServerAdapter.init();\n\n return app;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA6DA,SAAgB,uBAAuB,SAAqD;CAC1F,MAAM,EAAE,QAAQ,QAAQ,CAAC,GAAG,SAAS,WAAW;CAGhD,IAAI;CAEJ,SAAS,SAAwB;EAC/B,IAAI,CAAC,YACH,aAAa,QAAQ,QAAQ,OAAO,MAAM;EAE5C,OAAO;CACT;CAGA,MAAM,UAA4B,OAAM,QAAO;EAG7C,QAAA,GAAA,YAAA,OAAA,CAD2B,MADT,OAAO,CAER,CAAC,CAAC,GAAG;CACxB;CAEA,OAAO;EACL,KAAK;EACL,MAAM;EACN,KAAK;EACL,QAAQ;EACR,OAAO;EACP,SAAS;EACT,MAAM;CACR;AACF;AAEA,eAAe,QAAQ,QAAgB,OAAmB,QAA+B;CACvF,MAAM,MAAM,IAAIA,KAAAA,KAAK;CAErB,MAAM,eAAe,OAAO,UAAU;CACtC,MAAM,YAAoC,cAAc;CAGxD,MAAM,wCAAwB,IAAI,IAAqB;CACvD,IAAI,WACF,KAAK,MAAM,SAAS,WAAW;EAC7B,MAAM,eAAe,MAAM,iBAAiB;EAC5C,MAAM,WAAW,GAAG,MAAM,OAAO,GAAG,MAAM;EAC1C,sBAAsB,IAAI,UAAU,YAAY;CAClD;CAwBF,MAAM,IAhBwBC,aAAAA,aAAa;EACpC;EACL;EACA;EACA,WAAA,IAToBC,yBAAAA,kBASZ;EACR,kBAAkB;GAChB,SATkB,cAAc,iBAAiB,MAAM,OAAO;GAU9D,UAAU,UAAmB,EAAE,OAAO,yBAAyB;EACjE;EACA;EACA,iBAAiB;EACjB;EACA,YAAY,cAAc;CAC5B,CAGsB,CAAC,CAAC,KAAK;CAE7B,OAAO;AACT"}
package/dist/index.js CHANGED
@@ -1,65 +1,72 @@
1
- import { MastraServer } from '@mastra/hono';
2
- import { InMemoryTaskStore } from '@mastra/server/a2a/store';
3
- import { Hono } from 'hono';
4
- import { handle } from 'hono/vercel';
5
-
6
- // src/index.ts
1
+ import { MastraServer } from "@mastra/hono";
2
+ import { InMemoryTaskStore } from "@mastra/server/a2a/store";
3
+ import { Hono } from "hono";
4
+ import { handle } from "hono/vercel";
5
+ //#region src/index.ts
6
+ /**
7
+ * Creates Next.js App Router route handlers for a Mastra instance.
8
+ *
9
+ * Mount this in a catch-all route file such as:
10
+ * `app/api/[...mastra]/route.ts`
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * // app/api/[...mastra]/route.ts
15
+ * import { createNextRouteHandler } from '@mastra/next';
16
+ * import { mastra } from '../../../mastra';
17
+ *
18
+ * export const { GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD } = createNextRouteHandler({
19
+ * mastra,
20
+ * });
21
+ * ```
22
+ */
7
23
  function createNextRouteHandler(options) {
8
- const { mastra, tools = {}, prefix = "/api" } = options;
9
- let appPromise;
10
- function getApp() {
11
- if (!appPromise) {
12
- appPromise = initApp(mastra, tools, prefix);
13
- }
14
- return appPromise;
15
- }
16
- const handler = async (req) => {
17
- const app = await getApp();
18
- const honoHandler = handle(app);
19
- return honoHandler(req);
20
- };
21
- return {
22
- GET: handler,
23
- POST: handler,
24
- PUT: handler,
25
- DELETE: handler,
26
- PATCH: handler,
27
- OPTIONS: handler,
28
- HEAD: handler
29
- };
24
+ const { mastra, tools = {}, prefix = "/api" } = options;
25
+ let appPromise;
26
+ function getApp() {
27
+ if (!appPromise) appPromise = initApp(mastra, tools, prefix);
28
+ return appPromise;
29
+ }
30
+ const handler = async (req) => {
31
+ return handle(await getApp())(req);
32
+ };
33
+ return {
34
+ GET: handler,
35
+ POST: handler,
36
+ PUT: handler,
37
+ DELETE: handler,
38
+ PATCH: handler,
39
+ OPTIONS: handler,
40
+ HEAD: handler
41
+ };
30
42
  }
31
43
  async function initApp(mastra, tools, prefix) {
32
- const app = new Hono();
33
- const serverConfig = mastra.getServer();
34
- const apiRoutes = serverConfig?.apiRoutes;
35
- const customRouteAuthConfig = /* @__PURE__ */ new Map();
36
- if (apiRoutes) {
37
- for (const route of apiRoutes) {
38
- const requiresAuth = route.requiresAuth !== false;
39
- const routeKey = `${route.method}:${route.path}`;
40
- customRouteAuthConfig.set(routeKey, requiresAuth);
41
- }
42
- }
43
- const taskStore = new InMemoryTaskStore();
44
- const bodySizeLimit = serverConfig?.bodySizeLimit ?? 4.5 * 1024 * 1024;
45
- const honoServerAdapter = new MastraServer({
46
- app,
47
- mastra,
48
- tools,
49
- taskStore,
50
- bodyLimitOptions: {
51
- maxSize: bodySizeLimit,
52
- onError: (_err) => ({ error: "Request body too large" })
53
- },
54
- customRouteAuthConfig,
55
- customApiRoutes: apiRoutes,
56
- prefix,
57
- mcpOptions: serverConfig?.mcpOptions
58
- });
59
- await honoServerAdapter.init();
60
- return app;
44
+ const app = new Hono();
45
+ const serverConfig = mastra.getServer();
46
+ const apiRoutes = serverConfig?.apiRoutes;
47
+ const customRouteAuthConfig = /* @__PURE__ */ new Map();
48
+ if (apiRoutes) for (const route of apiRoutes) {
49
+ const requiresAuth = route.requiresAuth !== false;
50
+ const routeKey = `${route.method}:${route.path}`;
51
+ customRouteAuthConfig.set(routeKey, requiresAuth);
52
+ }
53
+ await new MastraServer({
54
+ app,
55
+ mastra,
56
+ tools,
57
+ taskStore: new InMemoryTaskStore(),
58
+ bodyLimitOptions: {
59
+ maxSize: serverConfig?.bodySizeLimit ?? 4.5 * 1024 * 1024,
60
+ onError: (_err) => ({ error: "Request body too large" })
61
+ },
62
+ customRouteAuthConfig,
63
+ customApiRoutes: apiRoutes,
64
+ prefix,
65
+ mcpOptions: serverConfig?.mcpOptions
66
+ }).init();
67
+ return app;
61
68
  }
62
-
69
+ //#endregion
63
70
  export { createNextRouteHandler };
64
- //# sourceMappingURL=index.js.map
71
+
65
72
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AA6DO,SAAS,uBAAuB,OAAA,EAAqD;AAC1F,EAAA,MAAM,EAAE,MAAA,EAAQ,KAAA,GAAQ,EAAC,EAAG,MAAA,GAAS,QAAO,GAAI,OAAA;AAGhD,EAAA,IAAI,UAAA;AAEJ,EAAA,SAAS,MAAA,GAAwB;AAC/B,IAAA,IAAI,CAAC,UAAA,EAAY;AACf,MAAA,UAAA,GAAa,OAAA,CAAQ,MAAA,EAAQ,KAAA,EAAO,MAAM,CAAA;AAAA,IAC5C;AACA,IAAA,OAAO,UAAA;AAAA,EACT;AAGA,EAAA,MAAM,OAAA,GAA4B,OAAM,GAAA,KAAO;AAC7C,IAAA,MAAM,GAAA,GAAM,MAAM,MAAA,EAAO;AACzB,IAAA,MAAM,WAAA,GAAc,OAAO,GAAG,CAAA;AAC9B,IAAA,OAAO,YAAY,GAAG,CAAA;AAAA,EACxB,CAAA;AAEA,EAAA,OAAO;AAAA,IACL,GAAA,EAAK,OAAA;AAAA,IACL,IAAA,EAAM,OAAA;AAAA,IACN,GAAA,EAAK,OAAA;AAAA,IACL,MAAA,EAAQ,OAAA;AAAA,IACR,KAAA,EAAO,OAAA;AAAA,IACP,OAAA,EAAS,OAAA;AAAA,IACT,IAAA,EAAM;AAAA,GACR;AACF;AAEA,eAAe,OAAA,CAAQ,MAAA,EAAgB,KAAA,EAAmB,MAAA,EAA+B;AACvF,EAAA,MAAM,GAAA,GAAM,IAAI,IAAA,EAAK;AAErB,EAAA,MAAM,YAAA,GAAe,OAAO,SAAA,EAAU;AACtC,EAAA,MAAM,YAAoC,YAAA,EAAc,SAAA;AAGxD,EAAA,MAAM,qBAAA,uBAA4B,GAAA,EAAqB;AACvD,EAAA,IAAI,SAAA,EAAW;AACb,IAAA,KAAA,MAAW,SAAS,SAAA,EAAW;AAC7B,MAAA,MAAM,YAAA,GAAe,MAAM,YAAA,KAAiB,KAAA;AAC5C,MAAA,MAAM,WAAW,CAAA,EAAG,KAAA,CAAM,MAAM,CAAA,CAAA,EAAI,MAAM,IAAI,CAAA,CAAA;AAC9C,MAAA,qBAAA,CAAsB,GAAA,CAAI,UAAU,YAAY,CAAA;AAAA,IAClD;AAAA,EACF;AAEA,EAAA,MAAM,SAAA,GAAY,IAAI,iBAAA,EAAkB;AAExC,EAAA,MAAM,aAAA,GAAgB,YAAA,EAAc,aAAA,IAAiB,GAAA,GAAM,IAAA,GAAO,IAAA;AAGlE,EAAA,MAAM,iBAAA,GAAoB,IAAI,YAAA,CAAa;AAAA,IACzC,GAAA;AAAA,IACA,MAAA;AAAA,IACA,KAAA;AAAA,IACA,SAAA;AAAA,IACA,gBAAA,EAAkB;AAAA,MAChB,OAAA,EAAS,aAAA;AAAA,MACT,OAAA,EAAS,CAAC,IAAA,MAAmB,EAAE,OAAO,wBAAA,EAAyB;AAAA,KACjE;AAAA,IACA,qBAAA;AAAA,IACA,eAAA,EAAiB,SAAA;AAAA,IACjB,MAAA;AAAA,IACA,YAAY,YAAA,EAAc;AAAA,GAC3B,CAAA;AAGD,EAAA,MAAM,kBAAkB,IAAA,EAAK;AAE7B,EAAA,OAAO,GAAA;AACT","file":"index.js","sourcesContent":["import type { ToolsInput } from '@mastra/core/agent';\nimport type { Mastra } from '@mastra/core/mastra';\nimport type { ApiRoute } from '@mastra/core/server';\nimport { MastraServer } from '@mastra/hono';\nimport type { HonoApp } from '@mastra/hono';\nimport { InMemoryTaskStore } from '@mastra/server/a2a/store';\nimport { Hono } from 'hono';\nimport { handle } from 'hono/vercel';\n\nexport interface NextRouteHandlerOptions {\n /**\n * The Mastra instance to serve.\n */\n mastra: Mastra;\n\n /**\n * Tools to register with the server.\n * @default {}\n */\n tools?: ToolsInput;\n\n /**\n * API route prefix. Should match the path where the catch-all route is mounted.\n * For example, if you mount at `app/api/[...mastra]/route.ts`, set this to `/api`.\n * @default '/api'\n */\n prefix?: string;\n}\n\n/**\n * A Next.js route handler function compatible with App Router.\n */\nexport type NextRouteHandler = (req: Request) => Response | Promise<Response>;\n\nexport interface NextRouteHandlers {\n GET: NextRouteHandler;\n POST: NextRouteHandler;\n PUT: NextRouteHandler;\n DELETE: NextRouteHandler;\n PATCH: NextRouteHandler;\n OPTIONS: NextRouteHandler;\n HEAD: NextRouteHandler;\n}\n\n/**\n * Creates Next.js App Router route handlers for a Mastra instance.\n *\n * Mount this in a catch-all route file such as:\n * `app/api/[...mastra]/route.ts`\n *\n * @example\n * ```ts\n * // app/api/[...mastra]/route.ts\n * import { createNextRouteHandler } from '@mastra/next';\n * import { mastra } from '../../../mastra';\n *\n * export const { GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD } = createNextRouteHandler({\n * mastra,\n * });\n * ```\n */\nexport function createNextRouteHandler(options: NextRouteHandlerOptions): NextRouteHandlers {\n const { mastra, tools = {}, prefix = '/api' } = options;\n\n // Lazily initialize the Hono app so the module-level export works synchronously\n let appPromise: Promise<Hono> | undefined;\n\n function getApp(): Promise<Hono> {\n if (!appPromise) {\n appPromise = initApp(mastra, tools, prefix);\n }\n return appPromise;\n }\n\n // Build a handler for each HTTP method\n const handler: NextRouteHandler = async req => {\n const app = await getApp();\n const honoHandler = handle(app);\n return honoHandler(req);\n };\n\n return {\n GET: handler,\n POST: handler,\n PUT: handler,\n DELETE: handler,\n PATCH: handler,\n OPTIONS: handler,\n HEAD: handler,\n };\n}\n\nasync function initApp(mastra: Mastra, tools: ToolsInput, prefix: string): Promise<Hono> {\n const app = new Hono();\n\n const serverConfig = mastra.getServer();\n const apiRoutes: ApiRoute[] | undefined = serverConfig?.apiRoutes;\n\n // Store custom route auth configurations\n const customRouteAuthConfig = new Map<string, boolean>();\n if (apiRoutes) {\n for (const route of apiRoutes) {\n const requiresAuth = route.requiresAuth !== false;\n const routeKey = `${route.method}:${route.path}`;\n customRouteAuthConfig.set(routeKey, requiresAuth);\n }\n }\n\n const taskStore = new InMemoryTaskStore();\n\n const bodySizeLimit = serverConfig?.bodySizeLimit ?? 4.5 * 1024 * 1024;\n\n // Create the MastraServer adapter\n const honoServerAdapter = new MastraServer({\n app: app as unknown as HonoApp,\n mastra,\n tools,\n taskStore,\n bodyLimitOptions: {\n maxSize: bodySizeLimit,\n onError: (_err: unknown) => ({ error: 'Request body too large' }),\n },\n customRouteAuthConfig,\n customApiRoutes: apiRoutes,\n prefix,\n mcpOptions: serverConfig?.mcpOptions,\n });\n\n // Initialize: registers context middleware, auth, routes, etc.\n await honoServerAdapter.init();\n\n return app;\n}\n"]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { ToolsInput } from '@mastra/core/agent';\nimport type { Mastra } from '@mastra/core/mastra';\nimport type { ApiRoute } from '@mastra/core/server';\nimport { MastraServer } from '@mastra/hono';\nimport type { HonoApp } from '@mastra/hono';\nimport { InMemoryTaskStore } from '@mastra/server/a2a/store';\nimport { Hono } from 'hono';\nimport { handle } from 'hono/vercel';\n\nexport interface NextRouteHandlerOptions {\n /**\n * The Mastra instance to serve.\n */\n mastra: Mastra;\n\n /**\n * Tools to register with the server.\n * @default {}\n */\n tools?: ToolsInput;\n\n /**\n * API route prefix. Should match the path where the catch-all route is mounted.\n * For example, if you mount at `app/api/[...mastra]/route.ts`, set this to `/api`.\n * @default '/api'\n */\n prefix?: string;\n}\n\n/**\n * A Next.js route handler function compatible with App Router.\n */\nexport type NextRouteHandler = (req: Request) => Response | Promise<Response>;\n\nexport interface NextRouteHandlers {\n GET: NextRouteHandler;\n POST: NextRouteHandler;\n PUT: NextRouteHandler;\n DELETE: NextRouteHandler;\n PATCH: NextRouteHandler;\n OPTIONS: NextRouteHandler;\n HEAD: NextRouteHandler;\n}\n\n/**\n * Creates Next.js App Router route handlers for a Mastra instance.\n *\n * Mount this in a catch-all route file such as:\n * `app/api/[...mastra]/route.ts`\n *\n * @example\n * ```ts\n * // app/api/[...mastra]/route.ts\n * import { createNextRouteHandler } from '@mastra/next';\n * import { mastra } from '../../../mastra';\n *\n * export const { GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD } = createNextRouteHandler({\n * mastra,\n * });\n * ```\n */\nexport function createNextRouteHandler(options: NextRouteHandlerOptions): NextRouteHandlers {\n const { mastra, tools = {}, prefix = '/api' } = options;\n\n // Lazily initialize the Hono app so the module-level export works synchronously\n let appPromise: Promise<Hono> | undefined;\n\n function getApp(): Promise<Hono> {\n if (!appPromise) {\n appPromise = initApp(mastra, tools, prefix);\n }\n return appPromise;\n }\n\n // Build a handler for each HTTP method\n const handler: NextRouteHandler = async req => {\n const app = await getApp();\n const honoHandler = handle(app);\n return honoHandler(req);\n };\n\n return {\n GET: handler,\n POST: handler,\n PUT: handler,\n DELETE: handler,\n PATCH: handler,\n OPTIONS: handler,\n HEAD: handler,\n };\n}\n\nasync function initApp(mastra: Mastra, tools: ToolsInput, prefix: string): Promise<Hono> {\n const app = new Hono();\n\n const serverConfig = mastra.getServer();\n const apiRoutes: ApiRoute[] | undefined = serverConfig?.apiRoutes;\n\n // Store custom route auth configurations\n const customRouteAuthConfig = new Map<string, boolean>();\n if (apiRoutes) {\n for (const route of apiRoutes) {\n const requiresAuth = route.requiresAuth !== false;\n const routeKey = `${route.method}:${route.path}`;\n customRouteAuthConfig.set(routeKey, requiresAuth);\n }\n }\n\n const taskStore = new InMemoryTaskStore();\n\n const bodySizeLimit = serverConfig?.bodySizeLimit ?? 4.5 * 1024 * 1024;\n\n // Create the MastraServer adapter\n const honoServerAdapter = new MastraServer({\n app: app as unknown as HonoApp,\n mastra,\n tools,\n taskStore,\n bodyLimitOptions: {\n maxSize: bodySizeLimit,\n onError: (_err: unknown) => ({ error: 'Request body too large' }),\n },\n customRouteAuthConfig,\n customApiRoutes: apiRoutes,\n prefix,\n mcpOptions: serverConfig?.mcpOptions,\n });\n\n // Initialize: registers context middleware, auth, routes, etc.\n await honoServerAdapter.init();\n\n return app;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA6DA,SAAgB,uBAAuB,SAAqD;CAC1F,MAAM,EAAE,QAAQ,QAAQ,CAAC,GAAG,SAAS,WAAW;CAGhD,IAAI;CAEJ,SAAS,SAAwB;EAC/B,IAAI,CAAC,YACH,aAAa,QAAQ,QAAQ,OAAO,MAAM;EAE5C,OAAO;CACT;CAGA,MAAM,UAA4B,OAAM,QAAO;EAG7C,OADoB,OAAO,MADT,OAAO,CAER,CAAC,CAAC,GAAG;CACxB;CAEA,OAAO;EACL,KAAK;EACL,MAAM;EACN,KAAK;EACL,QAAQ;EACR,OAAO;EACP,SAAS;EACT,MAAM;CACR;AACF;AAEA,eAAe,QAAQ,QAAgB,OAAmB,QAA+B;CACvF,MAAM,MAAM,IAAI,KAAK;CAErB,MAAM,eAAe,OAAO,UAAU;CACtC,MAAM,YAAoC,cAAc;CAGxD,MAAM,wCAAwB,IAAI,IAAqB;CACvD,IAAI,WACF,KAAK,MAAM,SAAS,WAAW;EAC7B,MAAM,eAAe,MAAM,iBAAiB;EAC5C,MAAM,WAAW,GAAG,MAAM,OAAO,GAAG,MAAM;EAC1C,sBAAsB,IAAI,UAAU,YAAY;CAClD;CAwBF,MAAM,IAhBwB,aAAa;EACpC;EACL;EACA;EACA,WAAA,IAToB,kBASZ;EACR,kBAAkB;GAChB,SATkB,cAAc,iBAAiB,MAAM,OAAO;GAU9D,UAAU,UAAmB,EAAE,OAAO,yBAAyB;EACjE;EACA;EACA,iBAAiB;EACjB;EACA,YAAY,cAAc;CAC5B,CAGsB,CAAC,CAAC,KAAK;CAE7B,OAAO;AACT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/next",
3
- "version": "0.2.10-alpha.0",
3
+ "version": "0.2.10-alpha.2",
4
4
  "description": "Mastra Next.js server adapter — drop your Mastra instance into a Next.js app",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -20,19 +20,19 @@
20
20
  },
21
21
  "license": "Apache-2.0",
22
22
  "dependencies": {
23
- "@mastra/server": "1.54.0-alpha.0",
24
- "@mastra/hono": "1.5.11-alpha.0"
23
+ "@mastra/server": "1.54.0-alpha.2",
24
+ "@mastra/hono": "1.5.11-alpha.2"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/node": "22.20.1",
28
28
  "eslint": "^10.7.0",
29
29
  "hono": "^4.12.8",
30
- "tsup": "^8.5.1",
30
+ "tsdown": "0.22.9",
31
31
  "typescript": "^6.0.3",
32
32
  "vitest": "4.1.10",
33
33
  "@internal/lint": "0.0.117",
34
34
  "@internal/types-builder": "0.0.92",
35
- "@mastra/core": "1.54.0-alpha.0"
35
+ "@mastra/core": "1.54.0-alpha.2"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@mastra/core": ">=1.50.0-0 <2.0.0-0",
@@ -55,7 +55,7 @@
55
55
  "url": "https://github.com/mastra-ai/mastra/issues"
56
56
  },
57
57
  "scripts": {
58
- "build": "tsup --silent --config tsup.config.ts",
58
+ "build": "tsdown --silent --config tsdown.config.ts",
59
59
  "build:watch": "pnpm build --watch",
60
60
  "test": "vitest run",
61
61
  "lint": "oxlint . && eslint .",