@mastra/next 0.0.0-feat-dataset-tenancy-20260622154040
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 +56 -0
- package/LICENSE.md +30 -0
- package/dist/index.cjs +67 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +65 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# @mastra/next
|
|
2
|
+
|
|
3
|
+
## 0.0.0-feat-dataset-tenancy-20260622154040
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added `@mastra/next` — a server adapter for Next.js App Router. Drop your Mastra instance into a catch-all route to expose all Mastra API endpoints without manually wiring routes. ([#18230](https://github.com/mastra-ai/mastra/pull/18230))
|
|
8
|
+
|
|
9
|
+
**Usage**
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
// app/api/[...mastra]/route.ts
|
|
13
|
+
import { createNextRouteHandler } from '@mastra/next';
|
|
14
|
+
import { mastra } from '../../../mastra';
|
|
15
|
+
|
|
16
|
+
export const { GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD } = createNextRouteHandler({ mastra });
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [[`5bd72d2`](https://github.com/mastra-ai/mastra/commit/5bd72d255f45b5ea8ab342643bd463814a980a24), [`1cc9ee1`](https://github.com/mastra-ai/mastra/commit/1cc9ee1ba51db53020a735626d33017a60b4b5b3), [`417baae`](https://github.com/mastra-ai/mastra/commit/417baae40b995db5819c845036947f0c27dc1c00), [`74955f9`](https://github.com/mastra-ai/mastra/commit/74955f9120cde8b1d8ce4399232b4033236be858), [`30ebaf0`](https://github.com/mastra-ai/mastra/commit/30ebaf07bed5f4d30f2f257836c15d1bf7e40aae), [`5704634`](https://github.com/mastra-ai/mastra/commit/5704634b22133167dea337a942a34f57aaa3fa14), [`def2671`](https://github.com/mastra-ai/mastra/commit/def267176e72ebbb28823f7d2c35da3dbf637564), [`417baae`](https://github.com/mastra-ai/mastra/commit/417baae40b995db5819c845036947f0c27dc1c00), [`74955f9`](https://github.com/mastra-ai/mastra/commit/74955f9120cde8b1d8ce4399232b4033236be858), [`74955f9`](https://github.com/mastra-ai/mastra/commit/74955f9120cde8b1d8ce4399232b4033236be858), [`45cc2b4`](https://github.com/mastra-ai/mastra/commit/45cc2b4051fc96bcf72914263d757e63cad09892), [`6a1428a`](https://github.com/mastra-ai/mastra/commit/6a1428a23133fc070fc6c1caa08d28f3ba4fe5ff), [`7794d71`](https://github.com/mastra-ai/mastra/commit/7794d71872c68733a30e028dfb7b1705daf6c5d2), [`c0eda2b`](https://github.com/mastra-ai/mastra/commit/c0eda2bcd91a228427314b12c91d8b147f3a739f), [`c0eda2b`](https://github.com/mastra-ai/mastra/commit/c0eda2bcd91a228427314b12c91d8b147f3a739f), [`b13925b`](https://github.com/mastra-ai/mastra/commit/b13925bfa91aa8700f56fa54a9ce707ee7e4ba62), [`bf94ec6`](https://github.com/mastra-ai/mastra/commit/bf94ec68192d9f16e46ef7e5ac36370aeeddf35d), [`a29f371`](https://github.com/mastra-ai/mastra/commit/a29f371aef629ac8562661524a497127e93b5131), [`74955f9`](https://github.com/mastra-ai/mastra/commit/74955f9120cde8b1d8ce4399232b4033236be858), [`073f910`](https://github.com/mastra-ai/mastra/commit/073f910481e7d94b95ba3830f96531774ae95d33), [`ebbe1d3`](https://github.com/mastra-ai/mastra/commit/ebbe1d31a965a3adb0e728758f326b8122b4b55f), [`1f97ce5`](https://github.com/mastra-ai/mastra/commit/1f97ce5695463bebb4eaacf501da6fb403e20885), [`74955f9`](https://github.com/mastra-ai/mastra/commit/74955f9120cde8b1d8ce4399232b4033236be858), [`64f58c0`](https://github.com/mastra-ai/mastra/commit/64f58c04e78b40137497d47f781e897e416f22a5), [`74955f9`](https://github.com/mastra-ai/mastra/commit/74955f9120cde8b1d8ce4399232b4033236be858), [`ebbe1d3`](https://github.com/mastra-ai/mastra/commit/ebbe1d31a965a3adb0e728758f326b8122b4b55f), [`37ab9d3`](https://github.com/mastra-ai/mastra/commit/37ab9d3482cea21388008e522a5c781763832588), [`417baae`](https://github.com/mastra-ai/mastra/commit/417baae40b995db5819c845036947f0c27dc1c00), [`40f4d08`](https://github.com/mastra-ai/mastra/commit/40f4d08791a4f6a480d5f85cce5d159a74cf5a01), [`8e25a78`](https://github.com/mastra-ai/mastra/commit/8e25a78e0597575f0b0729bae8c5e190c84869b5), [`417baae`](https://github.com/mastra-ai/mastra/commit/417baae40b995db5819c845036947f0c27dc1c00), [`a5b22d3`](https://github.com/mastra-ai/mastra/commit/a5b22d314d62a68d801886a8d3d0eb6c089473db), [`def2671`](https://github.com/mastra-ai/mastra/commit/def267176e72ebbb28823f7d2c35da3dbf637564), [`ea55a1d`](https://github.com/mastra-ai/mastra/commit/ea55a1d67e656129b74d661a0e06fa274f503aa3), [`417baae`](https://github.com/mastra-ai/mastra/commit/417baae40b995db5819c845036947f0c27dc1c00), [`74955f9`](https://github.com/mastra-ai/mastra/commit/74955f9120cde8b1d8ce4399232b4033236be858), [`74955f9`](https://github.com/mastra-ai/mastra/commit/74955f9120cde8b1d8ce4399232b4033236be858)]:
|
|
22
|
+
- @mastra/core@0.0.0-feat-dataset-tenancy-20260622154040
|
|
23
|
+
- @mastra/hono@0.0.0-feat-dataset-tenancy-20260622154040
|
|
24
|
+
- @mastra/server@0.0.0-feat-dataset-tenancy-20260622154040
|
|
25
|
+
|
|
26
|
+
## 0.2.0-alpha.1
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- Updated dependencies [[`7794d71`](https://github.com/mastra-ai/mastra/commit/7794d71872c68733a30e028dfb7b1705daf6c5d2)]:
|
|
31
|
+
- @mastra/core@1.46.0-alpha.1
|
|
32
|
+
- @mastra/server@1.46.0-alpha.1
|
|
33
|
+
- @mastra/hono@1.5.1-alpha.1
|
|
34
|
+
|
|
35
|
+
## 0.2.0-alpha.0
|
|
36
|
+
|
|
37
|
+
### Minor Changes
|
|
38
|
+
|
|
39
|
+
- Added `@mastra/next` — a server adapter for Next.js App Router. Drop your Mastra instance into a catch-all route to expose all Mastra API endpoints without manually wiring routes. ([#18230](https://github.com/mastra-ai/mastra/pull/18230))
|
|
40
|
+
|
|
41
|
+
**Usage**
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
// app/api/[...mastra]/route.ts
|
|
45
|
+
import { createNextRouteHandler } from '@mastra/next';
|
|
46
|
+
import { mastra } from '../../../mastra';
|
|
47
|
+
|
|
48
|
+
export const { GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD } = createNextRouteHandler({ mastra });
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Patch Changes
|
|
52
|
+
|
|
53
|
+
- Updated dependencies [[`5bd72d2`](https://github.com/mastra-ai/mastra/commit/5bd72d255f45b5ea8ab342643bd463814a980a24), [`1cc9ee1`](https://github.com/mastra-ai/mastra/commit/1cc9ee1ba51db53020a735626d33017a60b4b5b3), [`417baae`](https://github.com/mastra-ai/mastra/commit/417baae40b995db5819c845036947f0c27dc1c00), [`74955f9`](https://github.com/mastra-ai/mastra/commit/74955f9120cde8b1d8ce4399232b4033236be858), [`30ebaf0`](https://github.com/mastra-ai/mastra/commit/30ebaf07bed5f4d30f2f257836c15d1bf7e40aae), [`5704634`](https://github.com/mastra-ai/mastra/commit/5704634b22133167dea337a942a34f57aaa3fa14), [`def2671`](https://github.com/mastra-ai/mastra/commit/def267176e72ebbb28823f7d2c35da3dbf637564), [`417baae`](https://github.com/mastra-ai/mastra/commit/417baae40b995db5819c845036947f0c27dc1c00), [`74955f9`](https://github.com/mastra-ai/mastra/commit/74955f9120cde8b1d8ce4399232b4033236be858), [`74955f9`](https://github.com/mastra-ai/mastra/commit/74955f9120cde8b1d8ce4399232b4033236be858), [`c0eda2b`](https://github.com/mastra-ai/mastra/commit/c0eda2bcd91a228427314b12c91d8b147f3a739f), [`c0eda2b`](https://github.com/mastra-ai/mastra/commit/c0eda2bcd91a228427314b12c91d8b147f3a739f), [`b13925b`](https://github.com/mastra-ai/mastra/commit/b13925bfa91aa8700f56fa54a9ce707ee7e4ba62), [`bf94ec6`](https://github.com/mastra-ai/mastra/commit/bf94ec68192d9f16e46ef7e5ac36370aeeddf35d), [`a29f371`](https://github.com/mastra-ai/mastra/commit/a29f371aef629ac8562661524a497127e93b5131), [`74955f9`](https://github.com/mastra-ai/mastra/commit/74955f9120cde8b1d8ce4399232b4033236be858), [`073f910`](https://github.com/mastra-ai/mastra/commit/073f910481e7d94b95ba3830f96531774ae95d33), [`ebbe1d3`](https://github.com/mastra-ai/mastra/commit/ebbe1d31a965a3adb0e728758f326b8122b4b55f), [`1f97ce5`](https://github.com/mastra-ai/mastra/commit/1f97ce5695463bebb4eaacf501da6fb403e20885), [`74955f9`](https://github.com/mastra-ai/mastra/commit/74955f9120cde8b1d8ce4399232b4033236be858), [`64f58c0`](https://github.com/mastra-ai/mastra/commit/64f58c04e78b40137497d47f781e897e416f22a5), [`74955f9`](https://github.com/mastra-ai/mastra/commit/74955f9120cde8b1d8ce4399232b4033236be858), [`ebbe1d3`](https://github.com/mastra-ai/mastra/commit/ebbe1d31a965a3adb0e728758f326b8122b4b55f), [`37ab9d3`](https://github.com/mastra-ai/mastra/commit/37ab9d3482cea21388008e522a5c781763832588), [`417baae`](https://github.com/mastra-ai/mastra/commit/417baae40b995db5819c845036947f0c27dc1c00), [`8e25a78`](https://github.com/mastra-ai/mastra/commit/8e25a78e0597575f0b0729bae8c5e190c84869b5), [`417baae`](https://github.com/mastra-ai/mastra/commit/417baae40b995db5819c845036947f0c27dc1c00), [`a5b22d3`](https://github.com/mastra-ai/mastra/commit/a5b22d314d62a68d801886a8d3d0eb6c089473db), [`def2671`](https://github.com/mastra-ai/mastra/commit/def267176e72ebbb28823f7d2c35da3dbf637564), [`ea55a1d`](https://github.com/mastra-ai/mastra/commit/ea55a1d67e656129b74d661a0e06fa274f503aa3), [`417baae`](https://github.com/mastra-ai/mastra/commit/417baae40b995db5819c845036947f0c27dc1c00), [`74955f9`](https://github.com/mastra-ai/mastra/commit/74955f9120cde8b1d8ce4399232b4033236be858), [`74955f9`](https://github.com/mastra-ai/mastra/commit/74955f9120cde8b1d8ce4399232b4033236be858)]:
|
|
54
|
+
- @mastra/core@1.46.0-alpha.0
|
|
55
|
+
- @mastra/hono@1.5.1-alpha.0
|
|
56
|
+
- @mastra/server@1.46.0-alpha.0
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Portions of this software are licensed as follows:
|
|
2
|
+
|
|
3
|
+
- All content that resides under any directory named "ee/" within this
|
|
4
|
+
repository, including but not limited to:
|
|
5
|
+
- `packages/core/src/auth/ee/`
|
|
6
|
+
- `packages/server/src/server/auth/ee/`
|
|
7
|
+
is licensed under the license defined in `ee/LICENSE`.
|
|
8
|
+
|
|
9
|
+
- All third-party components incorporated into the Mastra Software are
|
|
10
|
+
licensed under the original license provided by the owner of the
|
|
11
|
+
applicable component.
|
|
12
|
+
|
|
13
|
+
- Content outside of the above-mentioned directories or restrictions is
|
|
14
|
+
available under the "Apache License 2.0" as defined below.
|
|
15
|
+
|
|
16
|
+
# Apache License 2.0
|
|
17
|
+
|
|
18
|
+
Copyright (c) 2025 Kepler Software, Inc.
|
|
19
|
+
|
|
20
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
21
|
+
you may not use this file except in compliance with the License.
|
|
22
|
+
You may obtain a copy of the License at
|
|
23
|
+
|
|
24
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
25
|
+
|
|
26
|
+
Unless required by applicable law or agreed to in writing, software
|
|
27
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
28
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
29
|
+
See the License for the specific language governing permissions and
|
|
30
|
+
limitations under the License.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
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
|
|
9
|
+
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
|
+
};
|
|
32
|
+
}
|
|
33
|
+
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;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
exports.createNextRouteHandler = createNextRouteHandler;
|
|
66
|
+
//# sourceMappingURL=index.cjs.map
|
|
67
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +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"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ToolsInput } from '@mastra/core/agent';
|
|
2
|
+
import type { Mastra } from '@mastra/core/mastra';
|
|
3
|
+
export interface NextRouteHandlerOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The Mastra instance to serve.
|
|
6
|
+
*/
|
|
7
|
+
mastra: Mastra;
|
|
8
|
+
/**
|
|
9
|
+
* Tools to register with the server.
|
|
10
|
+
* @default {}
|
|
11
|
+
*/
|
|
12
|
+
tools?: ToolsInput;
|
|
13
|
+
/**
|
|
14
|
+
* API route prefix. Should match the path where the catch-all route is mounted.
|
|
15
|
+
* For example, if you mount at `app/api/[...mastra]/route.ts`, set this to `/api`.
|
|
16
|
+
* @default '/api'
|
|
17
|
+
*/
|
|
18
|
+
prefix?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A Next.js route handler function compatible with App Router.
|
|
22
|
+
*/
|
|
23
|
+
export type NextRouteHandler = (req: Request) => Response | Promise<Response>;
|
|
24
|
+
export interface NextRouteHandlers {
|
|
25
|
+
GET: NextRouteHandler;
|
|
26
|
+
POST: NextRouteHandler;
|
|
27
|
+
PUT: NextRouteHandler;
|
|
28
|
+
DELETE: NextRouteHandler;
|
|
29
|
+
PATCH: NextRouteHandler;
|
|
30
|
+
OPTIONS: NextRouteHandler;
|
|
31
|
+
HEAD: NextRouteHandler;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates Next.js App Router route handlers for a Mastra instance.
|
|
35
|
+
*
|
|
36
|
+
* Mount this in a catch-all route file such as:
|
|
37
|
+
* `app/api/[...mastra]/route.ts`
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* // app/api/[...mastra]/route.ts
|
|
42
|
+
* import { createNextRouteHandler } from '@mastra/next';
|
|
43
|
+
* import { mastra } from '../../../mastra.js';
|
|
44
|
+
*
|
|
45
|
+
* export const { GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD } = createNextRouteHandler({
|
|
46
|
+
* mastra,
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function createNextRouteHandler(options: NextRouteHandlerOptions): NextRouteHandlers;
|
|
51
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAQlD,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,KAAK,CAAC,EAAE,UAAU,CAAC;IAEnB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE9E,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,gBAAgB,CAAC;IACtB,IAAI,EAAE,gBAAgB,CAAC;IACvB,GAAG,EAAE,gBAAgB,CAAC;IACtB,MAAM,EAAE,gBAAgB,CAAC;IACzB,KAAK,EAAE,gBAAgB,CAAC;IACxB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,IAAI,EAAE,gBAAgB,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,GAAG,iBAAiB,CA6B1F"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
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
|
|
7
|
+
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
|
+
};
|
|
30
|
+
}
|
|
31
|
+
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;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { createNextRouteHandler };
|
|
64
|
+
//# sourceMappingURL=index.js.map
|
|
65
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mastra/next",
|
|
3
|
+
"version": "0.0.0-feat-dataset-tenancy-20260622154040",
|
|
4
|
+
"description": "Mastra Next.js server adapter — drop your Mastra instance into a Next.js app",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"license": "Apache-2.0",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@mastra/server": "0.0.0-feat-dataset-tenancy-20260622154040",
|
|
24
|
+
"@mastra/hono": "0.0.0-feat-dataset-tenancy-20260622154040"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "22.19.21",
|
|
28
|
+
"eslint": "^10.4.1",
|
|
29
|
+
"hono": "^4.12.8",
|
|
30
|
+
"tsup": "^8.5.1",
|
|
31
|
+
"typescript": "^6.0.3",
|
|
32
|
+
"vitest": "4.1.8",
|
|
33
|
+
"@mastra/core": "0.0.0-feat-dataset-tenancy-20260622154040",
|
|
34
|
+
"@internal/lint": "0.0.0-feat-dataset-tenancy-20260622154040",
|
|
35
|
+
"@internal/types-builder": "0.0.0-feat-dataset-tenancy-20260622154040"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"hono": "^4.12.8",
|
|
39
|
+
"@mastra/core": "0.0.0-feat-dataset-tenancy-20260622154040"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=22.13.0"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist",
|
|
46
|
+
"CHANGELOG.md"
|
|
47
|
+
],
|
|
48
|
+
"homepage": "https://mastra.ai",
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "git+https://github.com/mastra-ai/mastra.git",
|
|
52
|
+
"directory": "server-adapters/next"
|
|
53
|
+
},
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "https://github.com/mastra-ai/mastra/issues"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "tsup --silent --config tsup.config.ts",
|
|
59
|
+
"build:watch": "pnpm build --watch",
|
|
60
|
+
"test": "vitest run",
|
|
61
|
+
"lint": "eslint ."
|
|
62
|
+
}
|
|
63
|
+
}
|