@mastra/next 0.2.37-alpha.9 → 0.2.37
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/dist/index.cjs +6 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -32,7 +32,8 @@ function createNextRouteHandler(options) {
|
|
|
32
32
|
return appPromise;
|
|
33
33
|
}
|
|
34
34
|
const handler = async (req) => {
|
|
35
|
-
|
|
35
|
+
const app = await getApp();
|
|
36
|
+
return (0, hono_vercel.handle)(app)(req);
|
|
36
37
|
};
|
|
37
38
|
return {
|
|
38
39
|
GET: handler,
|
|
@@ -54,13 +55,15 @@ async function initApp(mastra, tools, prefix) {
|
|
|
54
55
|
const routeKey = `${route.method}:${route.path}`;
|
|
55
56
|
customRouteAuthConfig.set(routeKey, requiresAuth);
|
|
56
57
|
}
|
|
58
|
+
const taskStore = new _mastra_server_a2a_store.InMemoryTaskStore();
|
|
59
|
+
const bodySizeLimit = serverConfig?.bodySizeLimit ?? 4718592;
|
|
57
60
|
await new _mastra_hono.MastraServer({
|
|
58
61
|
app,
|
|
59
62
|
mastra,
|
|
60
63
|
tools,
|
|
61
|
-
taskStore
|
|
64
|
+
taskStore,
|
|
62
65
|
bodyLimitOptions: {
|
|
63
|
-
maxSize:
|
|
66
|
+
maxSize: bodySizeLimit,
|
|
64
67
|
onError: (_err) => ({ error: "Request body too large" })
|
|
65
68
|
},
|
|
66
69
|
customRouteAuthConfig,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["handle","Hono","InMemoryTaskStore","MastraServer"],"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 // Clear a failed initialization so the next request can retry it\n appPromise ??= initApp(mastra, tools, prefix).catch(error => {\n appPromise = undefined;\n throw error;\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;EAE/B,eAAe,QAAQ,QAAQ,OAAO,MAAM,CAAC,CAAC,OAAM,UAAS;GAC3D,aAAa,KAAA;GACb,MAAM;EACR,CAAC;EACD,OAAO;CACT;CAGA,MAAM,UAA4B,OAAM,QAAO;EAC7C,MAAM,MAAM,MAAM,OAAO;EAEzB,QAAA,GADoBA,YAAAA,OAAAA,CAAO,GACV,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,IAAIC,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;CAGF,MAAM,YAAY,IAAIC,yBAAAA,kBAAkB;CAExC,MAAM,gBAAgB,cAAc,iBAAiB;CAmBrD,MAAM,IAhBwBC,aAAAA,aAAa;EACpC;EACL;EACA;EACA;EACA,kBAAkB;GAChB,SAAS;GACT,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
|
@@ -31,7 +31,8 @@ function createNextRouteHandler(options) {
|
|
|
31
31
|
return appPromise;
|
|
32
32
|
}
|
|
33
33
|
const handler = async (req) => {
|
|
34
|
-
|
|
34
|
+
const app = await getApp();
|
|
35
|
+
return handle(app)(req);
|
|
35
36
|
};
|
|
36
37
|
return {
|
|
37
38
|
GET: handler,
|
|
@@ -53,13 +54,15 @@ async function initApp(mastra, tools, prefix) {
|
|
|
53
54
|
const routeKey = `${route.method}:${route.path}`;
|
|
54
55
|
customRouteAuthConfig.set(routeKey, requiresAuth);
|
|
55
56
|
}
|
|
57
|
+
const taskStore = new InMemoryTaskStore();
|
|
58
|
+
const bodySizeLimit = serverConfig?.bodySizeLimit ?? 4718592;
|
|
56
59
|
await new MastraServer({
|
|
57
60
|
app,
|
|
58
61
|
mastra,
|
|
59
62
|
tools,
|
|
60
|
-
taskStore
|
|
63
|
+
taskStore,
|
|
61
64
|
bodyLimitOptions: {
|
|
62
|
-
maxSize:
|
|
65
|
+
maxSize: bodySizeLimit,
|
|
63
66
|
onError: (_err) => ({ error: "Request body too large" })
|
|
64
67
|
},
|
|
65
68
|
customRouteAuthConfig,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 // Clear a failed initialization so the next request can retry it\n appPromise ??= initApp(mastra, tools, prefix).catch(error => {\n appPromise = undefined;\n throw error;\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;EAE/B,eAAe,QAAQ,QAAQ,OAAO,MAAM,CAAC,CAAC,OAAM,UAAS;GAC3D,aAAa,KAAA;GACb,MAAM;EACR,CAAC;EACD,OAAO;CACT;CAGA,MAAM,UAA4B,OAAM,QAAO;
|
|
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 // Clear a failed initialization so the next request can retry it\n appPromise ??= initApp(mastra, tools, prefix).catch(error => {\n appPromise = undefined;\n throw error;\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;EAE/B,eAAe,QAAQ,QAAQ,OAAO,MAAM,CAAC,CAAC,OAAM,UAAS;GAC3D,aAAa,KAAA;GACb,MAAM;EACR,CAAC;EACD,OAAO;CACT;CAGA,MAAM,UAA4B,OAAM,QAAO;EAC7C,MAAM,MAAM,MAAM,OAAO;EAEzB,OADoB,OAAO,GACV,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;CAGF,MAAM,YAAY,IAAI,kBAAkB;CAExC,MAAM,gBAAgB,cAAc,iBAAiB;CAmBrD,MAAM,IAhBwB,aAAa;EACpC;EACL;EACA;EACA;EACA,kBAAkB;GAChB,SAAS;GACT,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.37
|
|
3
|
+
"version": "0.2.37",
|
|
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,8 +20,8 @@
|
|
|
20
20
|
},
|
|
21
21
|
"license": "Apache-2.0",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@mastra/
|
|
24
|
-
"@mastra/
|
|
23
|
+
"@mastra/server": "1.79.0",
|
|
24
|
+
"@mastra/hono": "1.7.21"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/node": "22.20.1",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"tsdown": "0.22.9",
|
|
30
30
|
"typescript": "^7.0.2",
|
|
31
31
|
"vitest": "4.1.11",
|
|
32
|
-
"@internal/types-builder": "0.0.
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
32
|
+
"@internal/types-builder": "0.0.120",
|
|
33
|
+
"@internal/lint": "0.0.145",
|
|
34
|
+
"@mastra/core": "1.79.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@mastra/core": ">=1.58.0-0 <2.0.0-0",
|