@mastra/deployer 1.58.0-alpha.8 → 1.58.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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAIlD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAIhE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAc5B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAoBnD,KAAK,QAAQ,GAAG,YAAY,CAAC;AAE7B,KAAK,SAAS,GAAG,aAAa,GAAG;IAC/B,OAAO,EAAE,GAAG,CAAC;QAAE,UAAU,EAAE,+BAA+B,CAAA;KAAE,CAAC,CAAC;CAC/D,CAAC;AAwCF,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,wCAmB/D;AAED,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,mBAER;cAegC,QAAQ;eAAa,SAAS;2CAkahE;AAED,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAmC,mDAwHlG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAIlD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAIhE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAc5B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAoBnD,KAAK,QAAQ,GAAG,YAAY,CAAC;AAE7B,KAAK,SAAS,GAAG,aAAa,GAAG;IAC/B,OAAO,EAAE,GAAG,CAAC;QAAE,UAAU,EAAE,+BAA+B,CAAA;KAAE,CAAC,CAAC;CAC/D,CAAC;AA8CF,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,wCAmB/D;AAED,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,mBAER;cAegC,QAAQ;eAAa,SAAS;2CAsahE;AAED,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAmC,mDAwHlG"}
@@ -2983,6 +2983,54 @@ function toFetchResponse(res) {
2983
2983
  //#endregion
2984
2984
  //#region ../../server-adapters/hono/dist/index.js
2985
2985
  /**
2986
+ * Propagates a client disconnect to the simulated Node response produced by `toReqRes`.
2987
+ *
2988
+ * `fetch-to-node` builds the outgoing body from `res` events but never observes cancellation
2989
+ * of the stream it hands back. When an MCP Streamable HTTP client drops its session, nothing
2990
+ * tells `res` that the socket is gone, so the MCP transport keeps its SSE keep-alive timer
2991
+ * armed. The next keep-alive tick writes into an already-closed stream controller, and because
2992
+ * that write originates in a timer callback the resulting `ERR_INVALID_STATE` is unhandled and
2993
+ * takes down the process.
2994
+ *
2995
+ * Emitting `close` on `res` is the signal the MCP Node transport listens for: it aborts the
2996
+ * request's AbortController, which breaks the write loop and tears down the SSE stream,
2997
+ * clearing the keep-alive timer. No post-disconnect write is ever attempted.
2998
+ */
2999
+ function propagateClientDisconnect(fetchResponse, res) {
3000
+ const upstream = fetchResponse.body;
3001
+ if (!upstream) return fetchResponse;
3002
+ let disconnected = false;
3003
+ const disconnect = () => {
3004
+ if (disconnected) return;
3005
+ disconnected = true;
3006
+ try {
3007
+ res.emit("close");
3008
+ } catch {}
3009
+ reader.read().then(function drain({ done }) {
3010
+ return done ? void 0 : reader.read().then(drain);
3011
+ }, () => {});
3012
+ };
3013
+ const reader = upstream.getReader();
3014
+ const body = new ReadableStream({
3015
+ async pull(controller) {
3016
+ const { done, value } = await reader.read();
3017
+ if (done) {
3018
+ controller.close();
3019
+ return;
3020
+ }
3021
+ controller.enqueue(value);
3022
+ },
3023
+ cancel() {
3024
+ disconnect();
3025
+ }
3026
+ });
3027
+ return new Response(body, {
3028
+ status: fetchResponse.status,
3029
+ statusText: fetchResponse.statusText,
3030
+ headers: fetchResponse.headers
3031
+ });
3032
+ }
3033
+ /**
2986
3034
  * Set up WebSocket-based browser stream endpoint for real-time screencast viewing.
2987
3035
  *
2988
3036
  * Creates a WebSocket route at `/browser/:agentId/stream` that:
@@ -3322,7 +3370,7 @@ var MastraServer$1 = class extends MastraServer {
3322
3370
  }
3323
3371
  } catch {}
3324
3372
  });
3325
- return await toFetchResponse(res);
3373
+ return propagateClientDisconnect(await toFetchResponse(res), res);
3326
3374
  } else if (route.responseType === "mcp-sse") {
3327
3375
  const { server, ssePath, messagePath } = result;
3328
3376
  try {
@@ -3502,8 +3550,8 @@ var MastraServer$1 = class extends MastraServer {
3502
3550
  });
3503
3551
  }
3504
3552
  async registerCustomApiRoutes() {
3505
- if (!await this.buildCustomRouteHandler()) return;
3506
- const routes = this.customApiRoutes ?? this.mastra.getServer()?.apiRoutes ?? [];
3553
+ const routes = await this.registerSchemaApiRoutes();
3554
+ if (!await this.buildCustomRouteHandler(routes)) return;
3507
3555
  for (const route of routes) {
3508
3556
  const serverRoute = {
3509
3557
  method: route.method,
@@ -4315,6 +4363,9 @@ const getStudioPath = () => {
4315
4363
  if (import.meta.url) __dirname = dirname(fileURLToPath(import.meta.url));
4316
4364
  return process.env.MASTRA_STUDIO_PATH || join(__dirname, "studio");
4317
4365
  };
4366
+ function isSchemaApiRoute(route) {
4367
+ return "_mastraSchemaRoute" in route && route._mastraSchemaRoute === true;
4368
+ }
4318
4369
  const DEFAULT_CORS_ALLOW_METHODS = [
4319
4370
  "GET",
4320
4371
  "POST",
@@ -4346,7 +4397,8 @@ function getCorsConfig(serverCors, credentialsDefault) {
4346
4397
  };
4347
4398
  }
4348
4399
  function getRouteCorsConfig(apiRoutes, pathname, method) {
4349
- return (findMatchingCustomRoute(pathname, method, apiRoutes)?.route)?.cors;
4400
+ const route = findMatchingCustomRoute(pathname, method, apiRoutes)?.route;
4401
+ return route && !isSchemaApiRoute(route) ? route.cors : void 0;
4350
4402
  }
4351
4403
  function getToolExports(tools) {
4352
4404
  try {
@@ -4372,7 +4424,8 @@ async function createHonoServer(mastra, options = { tools: {} }) {
4372
4424
  const apiPrefix = server?.apiPrefix ?? "/api";
4373
4425
  const a2aTaskStore = new InMemoryTaskStore();
4374
4426
  const processedRoutes = (server?.apiRoutes)?.map((route) => {
4375
- if ("openapi" in route && route.openapi) {
4427
+ if (isSchemaApiRoute(route)) return route;
4428
+ if (route.openapi) {
4376
4429
  const existingMiddleware = route.middleware ? Array.isArray(route.middleware) ? route.middleware : [route.middleware] : [];
4377
4430
  return {
4378
4431
  ...route,