@mastra/tanstack-start 0.0.0
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 +65 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +63 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
|
|
7
|
+
// src/index.ts
|
|
8
|
+
function createStartRouteHandler(options) {
|
|
9
|
+
const { mastra, tools = {}, prefix = "/api" } = options;
|
|
10
|
+
let appPromise;
|
|
11
|
+
function getApp() {
|
|
12
|
+
if (!appPromise) {
|
|
13
|
+
appPromise = initApp(mastra, tools, prefix);
|
|
14
|
+
}
|
|
15
|
+
return appPromise;
|
|
16
|
+
}
|
|
17
|
+
const handler = async ({ request }) => {
|
|
18
|
+
const app = await getApp();
|
|
19
|
+
return app.fetch(request);
|
|
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.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 store.InMemoryTaskStore();
|
|
44
|
+
const bodySizeLimit = serverConfig?.bodySizeLimit ?? 4.5 * 1024 * 1024;
|
|
45
|
+
const honoServerAdapter = new hono$1.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
|
+
exports.createStartRouteHandler = createStartRouteHandler;
|
|
64
|
+
//# sourceMappingURL=index.cjs.map
|
|
65
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["Hono","InMemoryTaskStore","MastraServer"],"mappings":";;;;;;;AAuEO,SAAS,wBAAwB,OAAA,EAAuD;AAC7F,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;AAEA,EAAA,MAAM,OAAA,GAA6B,OAAO,EAAE,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AS,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';\n\n/**\n * Context provided to each TanStack Start server route handler.\n */\nexport interface StartHandlerContext {\n request: Request;\n params: Record<string, string>;\n}\n\nexport interface StartRouteHandlerOptions {\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 `src/routes/api/$.ts`, set this to `/api`.\n * @default '/api'\n */\n prefix?: string;\n}\n\n/**\n * A TanStack Start server route handler function.\n */\nexport type StartRouteHandler = (ctx: StartHandlerContext) => Response | Promise<Response>;\n\nexport interface StartRouteHandlers {\n GET: StartRouteHandler;\n POST: StartRouteHandler;\n PUT: StartRouteHandler;\n DELETE: StartRouteHandler;\n PATCH: StartRouteHandler;\n OPTIONS: StartRouteHandler;\n HEAD: StartRouteHandler;\n}\n\n/**\n * Creates TanStack Start server route handlers for a Mastra instance.\n *\n * Mount this in a catch-all (splat) server route file such as:\n * `src/routes/api/$.ts`\n *\n * @example\n * ```ts\n * // src/routes/api/$.ts\n * import { createFileRoute } from '@tanstack/react-router';\n * import { createStartRouteHandler } from '@mastra/tanstack-start';\n * import { mastra } from '../../mastra';\n *\n * export const Route = createFileRoute('/api/$')({\n * server: {\n * handlers: createStartRouteHandler({ mastra }),\n * },\n * });\n * ```\n */\nexport function createStartRouteHandler(options: StartRouteHandlerOptions): StartRouteHandlers {\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 const handler: StartRouteHandler = async ({ request }) => {\n const app = await getApp();\n return app.fetch(request);\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,61 @@
|
|
|
1
|
+
import type { ToolsInput } from '@mastra/core/agent';
|
|
2
|
+
import type { Mastra } from '@mastra/core/mastra';
|
|
3
|
+
/**
|
|
4
|
+
* Context provided to each TanStack Start server route handler.
|
|
5
|
+
*/
|
|
6
|
+
export interface StartHandlerContext {
|
|
7
|
+
request: Request;
|
|
8
|
+
params: Record<string, string>;
|
|
9
|
+
}
|
|
10
|
+
export interface StartRouteHandlerOptions {
|
|
11
|
+
/**
|
|
12
|
+
* The Mastra instance to serve.
|
|
13
|
+
*/
|
|
14
|
+
mastra: Mastra;
|
|
15
|
+
/**
|
|
16
|
+
* Tools to register with the server.
|
|
17
|
+
* @default {}
|
|
18
|
+
*/
|
|
19
|
+
tools?: ToolsInput;
|
|
20
|
+
/**
|
|
21
|
+
* API route prefix. Should match the path where the catch-all route is mounted.
|
|
22
|
+
* For example, if you mount at `src/routes/api/$.ts`, set this to `/api`.
|
|
23
|
+
* @default '/api'
|
|
24
|
+
*/
|
|
25
|
+
prefix?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A TanStack Start server route handler function.
|
|
29
|
+
*/
|
|
30
|
+
export type StartRouteHandler = (ctx: StartHandlerContext) => Response | Promise<Response>;
|
|
31
|
+
export interface StartRouteHandlers {
|
|
32
|
+
GET: StartRouteHandler;
|
|
33
|
+
POST: StartRouteHandler;
|
|
34
|
+
PUT: StartRouteHandler;
|
|
35
|
+
DELETE: StartRouteHandler;
|
|
36
|
+
PATCH: StartRouteHandler;
|
|
37
|
+
OPTIONS: StartRouteHandler;
|
|
38
|
+
HEAD: StartRouteHandler;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Creates TanStack Start server route handlers for a Mastra instance.
|
|
42
|
+
*
|
|
43
|
+
* Mount this in a catch-all (splat) server route file such as:
|
|
44
|
+
* `src/routes/api/$.ts`
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* // src/routes/api/$.ts
|
|
49
|
+
* import { createFileRoute } from '@tanstack/react-router';
|
|
50
|
+
* import { createStartRouteHandler } from '@mastra/tanstack-start';
|
|
51
|
+
* import { mastra } from '../../mastra.js';
|
|
52
|
+
*
|
|
53
|
+
* export const Route = createFileRoute('/api/$')({
|
|
54
|
+
* server: {
|
|
55
|
+
* handlers: createStartRouteHandler({ mastra }),
|
|
56
|
+
* },
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function createStartRouteHandler(options: StartRouteHandlerOptions): StartRouteHandlers;
|
|
61
|
+
//# 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;AAOlD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,wBAAwB;IACvC;;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,iBAAiB,GAAG,CAAC,GAAG,EAAE,mBAAmB,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE3F,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,iBAAiB,CAAC;IACvB,IAAI,EAAE,iBAAiB,CAAC;IACxB,GAAG,EAAE,iBAAiB,CAAC;IACvB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,KAAK,EAAE,iBAAiB,CAAC;IACzB,OAAO,EAAE,iBAAiB,CAAC;IAC3B,IAAI,EAAE,iBAAiB,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,wBAAwB,GAAG,kBAAkB,CA2B7F"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { MastraServer } from '@mastra/hono';
|
|
2
|
+
import { InMemoryTaskStore } from '@mastra/server/a2a/store';
|
|
3
|
+
import { Hono } from 'hono';
|
|
4
|
+
|
|
5
|
+
// src/index.ts
|
|
6
|
+
function createStartRouteHandler(options) {
|
|
7
|
+
const { mastra, tools = {}, prefix = "/api" } = options;
|
|
8
|
+
let appPromise;
|
|
9
|
+
function getApp() {
|
|
10
|
+
if (!appPromise) {
|
|
11
|
+
appPromise = initApp(mastra, tools, prefix);
|
|
12
|
+
}
|
|
13
|
+
return appPromise;
|
|
14
|
+
}
|
|
15
|
+
const handler = async ({ request }) => {
|
|
16
|
+
const app = await getApp();
|
|
17
|
+
return app.fetch(request);
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
GET: handler,
|
|
21
|
+
POST: handler,
|
|
22
|
+
PUT: handler,
|
|
23
|
+
DELETE: handler,
|
|
24
|
+
PATCH: handler,
|
|
25
|
+
OPTIONS: handler,
|
|
26
|
+
HEAD: handler
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
async function initApp(mastra, tools, prefix) {
|
|
30
|
+
const app = new Hono();
|
|
31
|
+
const serverConfig = mastra.getServer();
|
|
32
|
+
const apiRoutes = serverConfig?.apiRoutes;
|
|
33
|
+
const customRouteAuthConfig = /* @__PURE__ */ new Map();
|
|
34
|
+
if (apiRoutes) {
|
|
35
|
+
for (const route of apiRoutes) {
|
|
36
|
+
const requiresAuth = route.requiresAuth !== false;
|
|
37
|
+
const routeKey = `${route.method}:${route.path}`;
|
|
38
|
+
customRouteAuthConfig.set(routeKey, requiresAuth);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const taskStore = new InMemoryTaskStore();
|
|
42
|
+
const bodySizeLimit = serverConfig?.bodySizeLimit ?? 4.5 * 1024 * 1024;
|
|
43
|
+
const honoServerAdapter = new MastraServer({
|
|
44
|
+
app,
|
|
45
|
+
mastra,
|
|
46
|
+
tools,
|
|
47
|
+
taskStore,
|
|
48
|
+
bodyLimitOptions: {
|
|
49
|
+
maxSize: bodySizeLimit,
|
|
50
|
+
onError: (_err) => ({ error: "Request body too large" })
|
|
51
|
+
},
|
|
52
|
+
customRouteAuthConfig,
|
|
53
|
+
customApiRoutes: apiRoutes,
|
|
54
|
+
prefix,
|
|
55
|
+
mcpOptions: serverConfig?.mcpOptions
|
|
56
|
+
});
|
|
57
|
+
await honoServerAdapter.init();
|
|
58
|
+
return app;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { createStartRouteHandler };
|
|
62
|
+
//# sourceMappingURL=index.js.map
|
|
63
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAuEO,SAAS,wBAAwB,OAAA,EAAuD;AAC7F,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;AAEA,EAAA,MAAM,OAAA,GAA6B,OAAO,EAAE,OAAA,EAAQ,KAAM;AACxD,IAAA,MAAM,GAAA,GAAM,MAAM,MAAA,EAAO;AACzB,IAAA,OAAO,GAAA,CAAI,MAAM,OAAO,CAAA;AAAA,EAC1B,CAAA;AAEA,EAAA,OAAO;AAAA,IACL,GAAA,EAAK,OAAA;AAAA,IACL,IAAA,EAAM,OAAA;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,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';\n\n/**\n * Context provided to each TanStack Start server route handler.\n */\nexport interface StartHandlerContext {\n request: Request;\n params: Record<string, string>;\n}\n\nexport interface StartRouteHandlerOptions {\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 `src/routes/api/$.ts`, set this to `/api`.\n * @default '/api'\n */\n prefix?: string;\n}\n\n/**\n * A TanStack Start server route handler function.\n */\nexport type StartRouteHandler = (ctx: StartHandlerContext) => Response | Promise<Response>;\n\nexport interface StartRouteHandlers {\n GET: StartRouteHandler;\n POST: StartRouteHandler;\n PUT: StartRouteHandler;\n DELETE: StartRouteHandler;\n PATCH: StartRouteHandler;\n OPTIONS: StartRouteHandler;\n HEAD: StartRouteHandler;\n}\n\n/**\n * Creates TanStack Start server route handlers for a Mastra instance.\n *\n * Mount this in a catch-all (splat) server route file such as:\n * `src/routes/api/$.ts`\n *\n * @example\n * ```ts\n * // src/routes/api/$.ts\n * import { createFileRoute } from '@tanstack/react-router';\n * import { createStartRouteHandler } from '@mastra/tanstack-start';\n * import { mastra } from '../../mastra';\n *\n * export const Route = createFileRoute('/api/$')({\n * server: {\n * handlers: createStartRouteHandler({ mastra }),\n * },\n * });\n * ```\n */\nexport function createStartRouteHandler(options: StartRouteHandlerOptions): StartRouteHandlers {\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 const handler: StartRouteHandler = async ({ request }) => {\n const app = await getApp();\n return app.fetch(request);\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/tanstack-start",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Mastra TanStack Start server adapter — drop your Mastra instance into a TanStack Start 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
|
+
"scripts": {
|
|
22
|
+
"build": "tsup --silent --config tsup.config.ts",
|
|
23
|
+
"build:watch": "pnpm build --watch",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"lint": "eslint ."
|
|
26
|
+
},
|
|
27
|
+
"license": "Apache-2.0",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@mastra/server": "workspace:*",
|
|
30
|
+
"@mastra/hono": "workspace:*"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@internal/lint": "workspace:*",
|
|
34
|
+
"@internal/types-builder": "workspace:*",
|
|
35
|
+
"@mastra/core": "workspace:*",
|
|
36
|
+
"@types/node": "22.19.21",
|
|
37
|
+
"eslint": "^10.4.1",
|
|
38
|
+
"hono": "^4.12.8",
|
|
39
|
+
"tsup": "^8.5.1",
|
|
40
|
+
"typescript": "catalog:",
|
|
41
|
+
"vitest": "catalog:"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@mastra/core": ">=1.34.0-0 <2.0.0-0",
|
|
45
|
+
"hono": "^4.12.8"
|
|
46
|
+
},
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=22.13.0"
|
|
49
|
+
},
|
|
50
|
+
"files": [
|
|
51
|
+
"dist",
|
|
52
|
+
"CHANGELOG.md"
|
|
53
|
+
],
|
|
54
|
+
"homepage": "https://mastra.ai",
|
|
55
|
+
"repository": {
|
|
56
|
+
"type": "git",
|
|
57
|
+
"url": "git+https://github.com/mastra-ai/mastra.git",
|
|
58
|
+
"directory": "server-adapters/tanstack-start"
|
|
59
|
+
},
|
|
60
|
+
"bugs": {
|
|
61
|
+
"url": "https://github.com/mastra-ai/mastra/issues"
|
|
62
|
+
}
|
|
63
|
+
}
|