@mastra/deployer 1.87.0-alpha.5 → 1.87.0-alpha.6

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.
@@ -3,7 +3,7 @@ name: mastra-deployer
3
3
  description: Documentation for @mastra/deployer. Use when working with @mastra/deployer APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/deployer"
6
- version: "1.87.0-alpha.5"
6
+ version: "1.87.0-alpha.6"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.87.0-alpha.5",
2
+ "version": "1.87.0-alpha.6",
3
3
  "package": "@mastra/deployer",
4
4
  "exports": {
5
5
  "Deployer": {
@@ -3628,6 +3628,18 @@ function cancelUnreadBodyOnAbort(response, signal) {
3628
3628
  if (signal.aborted) cancel();
3629
3629
  else signal.addEventListener("abort", cancel, { once: true });
3630
3630
  }
3631
+ /**
3632
+ * Releases an adapter-owned body branch that will not be forwarded. `Request.clone()` tees the body, so an unread
3633
+ * branch retains the whole body until GC. Cancelling the unused branch frees it while the forwarded branch streams.
3634
+ *
3635
+ * The cancel is intentionally fire-and-forget: fetch tee cancellation only settles once the sibling branch drains (or
3636
+ * is otherwise consumed), so awaiting it here would stall dispatch. Rejections are swallowed so cancellation failure
3637
+ * cannot turn into an unhandled rejection or replace the route response.
3638
+ */
3639
+ function releaseUnreadBody(body) {
3640
+ if (!body || body.locked) return;
3641
+ body.cancel("unused request body clone").catch(() => {});
3642
+ }
3631
3643
  const requestClones = /* @__PURE__ */ new WeakMap();
3632
3644
  /**
3633
3645
  * Clones a request and keeps the clone alive for as long as the request itself. Node 22 makes a request's body
@@ -3644,7 +3656,7 @@ function cloneRequest(request) {
3644
3656
  var MastraServer = class extends _mastra_server_server_adapter.MastraServer {
3645
3657
  createContextMiddleware() {
3646
3658
  return async (c, next) => {
3647
- if (this.hasCustomRouteHandler && BODY_METHODS.has(c.req.method) && c.req.raw.body) c.set(MASTRA_PRISTINE_REQUEST_KEY, c.req.raw.clone());
3659
+ if (this.hasCustomRouteHandler && BODY_METHODS.has(c.req.method) && c.req.raw.body && this.matchCustomRoute(c.req.url, c.req.method)) c.set(MASTRA_PRISTINE_REQUEST_KEY, c.req.raw.clone());
3648
3660
  const originalJson = c.req.json.bind(c.req);
3649
3661
  let jsonPromise;
3650
3662
  c.req.json = () => {
@@ -4033,64 +4045,82 @@ var MastraServer = class extends _mastra_server_server_adapter.MastraServer {
4033
4045
  if (!await this.buildCustomRouteHandler(routes)) return;
4034
4046
  for (const route of routes) {
4035
4047
  const routeHandler = async (c) => {
4036
- const { match, serverRoute, customRouteAuthConfig } = this.resolveCustomRouteAuth(c.req.url, c.req.method, c.req.path, route);
4037
- const authError = await this.checkRouteAuth(serverRoute, {
4038
- path: c.req.path,
4039
- method: c.req.method,
4040
- getHeader: (name) => c.req.header(name),
4041
- getQuery: (name) => c.req.query(name),
4042
- requestContext: c.get("requestContext"),
4043
- request: c.req.raw,
4044
- buildAuthorizeContext: () => c,
4045
- customRouteAuthConfig
4046
- });
4047
- if (authError) {
4048
- if (authError.headers) for (const [key, value] of Object.entries(authError.headers)) c.header(key, value);
4049
- if (authError.error) return c.json({ error: authError.error }, authError.status);
4050
- }
4051
- const permissionError = this.checkRouteRBAC(serverRoute, c.get("requestContext"));
4052
- if (permissionError) return c.json({
4053
- error: permissionError.error,
4054
- message: permissionError.message
4055
- }, permissionError.status);
4056
- const pristineRequest = c.get(MASTRA_PRISTINE_REQUEST_KEY) ?? c.req.raw;
4057
- let bodyParams = {};
4058
- if ((0, _mastra_server_server_adapter.getFGAProvider)(this.mastra, c.get("requestContext"))) {
4059
- const contentType = c.req.header("content-type");
4060
- if (contentType?.includes("application/json")) try {
4061
- const body = await pristineRequest.clone().json();
4062
- if (body && typeof body === "object" && !Array.isArray(body)) bodyParams = body;
4063
- } catch {
4064
- bodyParams = {};
4048
+ const originalRequest = c.req.raw;
4049
+ const pristineRequest = c.get(MASTRA_PRISTINE_REQUEST_KEY) ?? originalRequest;
4050
+ const hasPristine = pristineRequest !== originalRequest;
4051
+ let releasePristineBody = hasPristine;
4052
+ try {
4053
+ const { match, serverRoute, customRouteAuthConfig } = this.resolveCustomRouteAuth(c.req.url, c.req.method, c.req.path, route);
4054
+ const authError = await this.checkRouteAuth(serverRoute, {
4055
+ path: c.req.path,
4056
+ method: c.req.method,
4057
+ getHeader: (name) => c.req.header(name),
4058
+ getQuery: (name) => c.req.query(name),
4059
+ requestContext: c.get("requestContext"),
4060
+ request: c.req.raw,
4061
+ buildAuthorizeContext: () => c,
4062
+ customRouteAuthConfig
4063
+ });
4064
+ if (authError) {
4065
+ if (authError.headers) for (const [key, value] of Object.entries(authError.headers)) c.header(key, value);
4066
+ if (authError.error) return c.json({ error: authError.error }, authError.status);
4067
+ }
4068
+ const permissionError = this.checkRouteRBAC(serverRoute, c.get("requestContext"));
4069
+ if (permissionError) return c.json({
4070
+ error: permissionError.error,
4071
+ message: permissionError.message
4072
+ }, permissionError.status);
4073
+ let bodyParams = {};
4074
+ if ((0, _mastra_server_server_adapter.getFGAProvider)(this.mastra, c.get("requestContext"))) {
4075
+ const contentType = c.req.header("content-type");
4076
+ if (contentType?.includes("application/json")) try {
4077
+ const body = await pristineRequest.clone().json();
4078
+ if (body && typeof body === "object" && !Array.isArray(body)) bodyParams = body;
4079
+ } catch {
4080
+ bodyParams = {};
4081
+ }
4082
+ else if (contentType?.includes("application/x-www-form-urlencoded") || contentType?.includes("multipart/form-data")) try {
4083
+ bodyParams = Object.fromEntries(await pristineRequest.clone().formData());
4084
+ } catch {
4085
+ bodyParams = {};
4086
+ }
4065
4087
  }
4066
- else if (contentType?.includes("application/x-www-form-urlencoded") || contentType?.includes("multipart/form-data")) try {
4067
- bodyParams = Object.fromEntries(await pristineRequest.clone().formData());
4088
+ const fgaError = await (0, _mastra_server_server_adapter.checkRouteFGA)(this.mastra, serverRoute, c.get("requestContext"), {
4089
+ ...Object.fromEntries(new URL(c.req.url).searchParams.entries()),
4090
+ ...bodyParams,
4091
+ ...match ? match.params : c.req.param()
4092
+ });
4093
+ if (fgaError) return c.json({
4094
+ error: fgaError.error,
4095
+ message: fgaError.message
4096
+ }, fgaError.status);
4097
+ const reqHeaders = {};
4098
+ c.req.raw.headers.forEach((v, k) => {
4099
+ reqHeaders[k] = v;
4100
+ });
4101
+ let executionCtx;
4102
+ try {
4103
+ executionCtx = c.executionCtx;
4068
4104
  } catch {
4069
- bodyParams = {};
4105
+ executionCtx = void 0;
4070
4106
  }
4107
+ const originalUntouched = originalRequest.body !== null && !originalRequest.bodyUsed && !originalRequest.body.locked;
4108
+ let requestBody;
4109
+ if (!hasPristine) requestBody = originalRequest.body;
4110
+ else if (originalUntouched) {
4111
+ requestBody = originalRequest.body;
4112
+ releasePristineBody = false;
4113
+ releaseUnreadBody(pristineRequest.body);
4114
+ } else {
4115
+ requestBody = pristineRequest.body;
4116
+ releasePristineBody = false;
4117
+ }
4118
+ const response = await this.handleCustomRouteRequest(c.req.url, c.req.method, reqHeaders, requestBody, c.get("requestContext"), c.req.raw.signal, executionCtx);
4119
+ if (!response) return c.json({ error: "Not Found" }, 404);
4120
+ return response;
4121
+ } finally {
4122
+ if (releasePristineBody) releaseUnreadBody(pristineRequest.body);
4071
4123
  }
4072
- const fgaError = await (0, _mastra_server_server_adapter.checkRouteFGA)(this.mastra, serverRoute, c.get("requestContext"), {
4073
- ...Object.fromEntries(new URL(c.req.url).searchParams.entries()),
4074
- ...bodyParams,
4075
- ...match ? match.params : c.req.param()
4076
- });
4077
- if (fgaError) return c.json({
4078
- error: fgaError.error,
4079
- message: fgaError.message
4080
- }, fgaError.status);
4081
- const reqHeaders = {};
4082
- c.req.raw.headers.forEach((v, k) => {
4083
- reqHeaders[k] = v;
4084
- });
4085
- let executionCtx;
4086
- try {
4087
- executionCtx = c.executionCtx;
4088
- } catch {
4089
- executionCtx = void 0;
4090
- }
4091
- const response = await this.handleCustomRouteRequest(c.req.url, c.req.method, reqHeaders, pristineRequest.body, c.get("requestContext"), c.req.raw.signal, executionCtx);
4092
- if (!response) return c.json({ error: "Not Found" }, 404);
4093
- return response;
4094
4124
  };
4095
4125
  const method = route.method.toLowerCase();
4096
4126
  this.app[method](route.path, routeHandler);
@@ -1,5 +1,5 @@
1
1
  import type { Mastra } from '@mastra/core/mastra';
2
- import type { HonoBindings, HonoVariables } from '../_types/@mastra_hono@1.7.29-alpha.5/dist/index.js';
2
+ import type { HonoBindings, HonoVariables } from '../_types/@mastra_hono@1.7.29-alpha.6/dist/index.js';
3
3
  import { Hono } from 'hono';
4
4
  import type { ServerBundleOptions } from './types.js';
5
5
  type Bindings = HonoBindings;
@@ -3623,6 +3623,18 @@ function cancelUnreadBodyOnAbort(response, signal) {
3623
3623
  if (signal.aborted) cancel();
3624
3624
  else signal.addEventListener("abort", cancel, { once: true });
3625
3625
  }
3626
+ /**
3627
+ * Releases an adapter-owned body branch that will not be forwarded. `Request.clone()` tees the body, so an unread
3628
+ * branch retains the whole body until GC. Cancelling the unused branch frees it while the forwarded branch streams.
3629
+ *
3630
+ * The cancel is intentionally fire-and-forget: fetch tee cancellation only settles once the sibling branch drains (or
3631
+ * is otherwise consumed), so awaiting it here would stall dispatch. Rejections are swallowed so cancellation failure
3632
+ * cannot turn into an unhandled rejection or replace the route response.
3633
+ */
3634
+ function releaseUnreadBody(body) {
3635
+ if (!body || body.locked) return;
3636
+ body.cancel("unused request body clone").catch(() => {});
3637
+ }
3626
3638
  const requestClones = /* @__PURE__ */ new WeakMap();
3627
3639
  /**
3628
3640
  * Clones a request and keeps the clone alive for as long as the request itself. Node 22 makes a request's body
@@ -3639,7 +3651,7 @@ function cloneRequest(request) {
3639
3651
  var MastraServer$2 = class extends MastraServer {
3640
3652
  createContextMiddleware() {
3641
3653
  return async (c, next) => {
3642
- if (this.hasCustomRouteHandler && BODY_METHODS.has(c.req.method) && c.req.raw.body) c.set(MASTRA_PRISTINE_REQUEST_KEY, c.req.raw.clone());
3654
+ if (this.hasCustomRouteHandler && BODY_METHODS.has(c.req.method) && c.req.raw.body && this.matchCustomRoute(c.req.url, c.req.method)) c.set(MASTRA_PRISTINE_REQUEST_KEY, c.req.raw.clone());
3643
3655
  const originalJson = c.req.json.bind(c.req);
3644
3656
  let jsonPromise;
3645
3657
  c.req.json = () => {
@@ -4028,64 +4040,82 @@ var MastraServer$2 = class extends MastraServer {
4028
4040
  if (!await this.buildCustomRouteHandler(routes)) return;
4029
4041
  for (const route of routes) {
4030
4042
  const routeHandler = async (c) => {
4031
- const { match, serverRoute, customRouteAuthConfig } = this.resolveCustomRouteAuth(c.req.url, c.req.method, c.req.path, route);
4032
- const authError = await this.checkRouteAuth(serverRoute, {
4033
- path: c.req.path,
4034
- method: c.req.method,
4035
- getHeader: (name) => c.req.header(name),
4036
- getQuery: (name) => c.req.query(name),
4037
- requestContext: c.get("requestContext"),
4038
- request: c.req.raw,
4039
- buildAuthorizeContext: () => c,
4040
- customRouteAuthConfig
4041
- });
4042
- if (authError) {
4043
- if (authError.headers) for (const [key, value] of Object.entries(authError.headers)) c.header(key, value);
4044
- if (authError.error) return c.json({ error: authError.error }, authError.status);
4045
- }
4046
- const permissionError = this.checkRouteRBAC(serverRoute, c.get("requestContext"));
4047
- if (permissionError) return c.json({
4048
- error: permissionError.error,
4049
- message: permissionError.message
4050
- }, permissionError.status);
4051
- const pristineRequest = c.get(MASTRA_PRISTINE_REQUEST_KEY) ?? c.req.raw;
4052
- let bodyParams = {};
4053
- if (getFGAProvider(this.mastra, c.get("requestContext"))) {
4054
- const contentType = c.req.header("content-type");
4055
- if (contentType?.includes("application/json")) try {
4056
- const body = await pristineRequest.clone().json();
4057
- if (body && typeof body === "object" && !Array.isArray(body)) bodyParams = body;
4058
- } catch {
4059
- bodyParams = {};
4043
+ const originalRequest = c.req.raw;
4044
+ const pristineRequest = c.get(MASTRA_PRISTINE_REQUEST_KEY) ?? originalRequest;
4045
+ const hasPristine = pristineRequest !== originalRequest;
4046
+ let releasePristineBody = hasPristine;
4047
+ try {
4048
+ const { match, serverRoute, customRouteAuthConfig } = this.resolveCustomRouteAuth(c.req.url, c.req.method, c.req.path, route);
4049
+ const authError = await this.checkRouteAuth(serverRoute, {
4050
+ path: c.req.path,
4051
+ method: c.req.method,
4052
+ getHeader: (name) => c.req.header(name),
4053
+ getQuery: (name) => c.req.query(name),
4054
+ requestContext: c.get("requestContext"),
4055
+ request: c.req.raw,
4056
+ buildAuthorizeContext: () => c,
4057
+ customRouteAuthConfig
4058
+ });
4059
+ if (authError) {
4060
+ if (authError.headers) for (const [key, value] of Object.entries(authError.headers)) c.header(key, value);
4061
+ if (authError.error) return c.json({ error: authError.error }, authError.status);
4062
+ }
4063
+ const permissionError = this.checkRouteRBAC(serverRoute, c.get("requestContext"));
4064
+ if (permissionError) return c.json({
4065
+ error: permissionError.error,
4066
+ message: permissionError.message
4067
+ }, permissionError.status);
4068
+ let bodyParams = {};
4069
+ if (getFGAProvider(this.mastra, c.get("requestContext"))) {
4070
+ const contentType = c.req.header("content-type");
4071
+ if (contentType?.includes("application/json")) try {
4072
+ const body = await pristineRequest.clone().json();
4073
+ if (body && typeof body === "object" && !Array.isArray(body)) bodyParams = body;
4074
+ } catch {
4075
+ bodyParams = {};
4076
+ }
4077
+ else if (contentType?.includes("application/x-www-form-urlencoded") || contentType?.includes("multipart/form-data")) try {
4078
+ bodyParams = Object.fromEntries(await pristineRequest.clone().formData());
4079
+ } catch {
4080
+ bodyParams = {};
4081
+ }
4060
4082
  }
4061
- else if (contentType?.includes("application/x-www-form-urlencoded") || contentType?.includes("multipart/form-data")) try {
4062
- bodyParams = Object.fromEntries(await pristineRequest.clone().formData());
4083
+ const fgaError = await checkRouteFGA(this.mastra, serverRoute, c.get("requestContext"), {
4084
+ ...Object.fromEntries(new URL(c.req.url).searchParams.entries()),
4085
+ ...bodyParams,
4086
+ ...match ? match.params : c.req.param()
4087
+ });
4088
+ if (fgaError) return c.json({
4089
+ error: fgaError.error,
4090
+ message: fgaError.message
4091
+ }, fgaError.status);
4092
+ const reqHeaders = {};
4093
+ c.req.raw.headers.forEach((v, k) => {
4094
+ reqHeaders[k] = v;
4095
+ });
4096
+ let executionCtx;
4097
+ try {
4098
+ executionCtx = c.executionCtx;
4063
4099
  } catch {
4064
- bodyParams = {};
4100
+ executionCtx = void 0;
4065
4101
  }
4102
+ const originalUntouched = originalRequest.body !== null && !originalRequest.bodyUsed && !originalRequest.body.locked;
4103
+ let requestBody;
4104
+ if (!hasPristine) requestBody = originalRequest.body;
4105
+ else if (originalUntouched) {
4106
+ requestBody = originalRequest.body;
4107
+ releasePristineBody = false;
4108
+ releaseUnreadBody(pristineRequest.body);
4109
+ } else {
4110
+ requestBody = pristineRequest.body;
4111
+ releasePristineBody = false;
4112
+ }
4113
+ const response = await this.handleCustomRouteRequest(c.req.url, c.req.method, reqHeaders, requestBody, c.get("requestContext"), c.req.raw.signal, executionCtx);
4114
+ if (!response) return c.json({ error: "Not Found" }, 404);
4115
+ return response;
4116
+ } finally {
4117
+ if (releasePristineBody) releaseUnreadBody(pristineRequest.body);
4066
4118
  }
4067
- const fgaError = await checkRouteFGA(this.mastra, serverRoute, c.get("requestContext"), {
4068
- ...Object.fromEntries(new URL(c.req.url).searchParams.entries()),
4069
- ...bodyParams,
4070
- ...match ? match.params : c.req.param()
4071
- });
4072
- if (fgaError) return c.json({
4073
- error: fgaError.error,
4074
- message: fgaError.message
4075
- }, fgaError.status);
4076
- const reqHeaders = {};
4077
- c.req.raw.headers.forEach((v, k) => {
4078
- reqHeaders[k] = v;
4079
- });
4080
- let executionCtx;
4081
- try {
4082
- executionCtx = c.executionCtx;
4083
- } catch {
4084
- executionCtx = void 0;
4085
- }
4086
- const response = await this.handleCustomRouteRequest(c.req.url, c.req.method, reqHeaders, pristineRequest.body, c.get("requestContext"), c.req.raw.signal, executionCtx);
4087
- if (!response) return c.json({ error: "Not Found" }, 404);
4088
- return response;
4089
4119
  };
4090
4120
  const method = route.method.toLowerCase();
4091
4121
  this.app[method](route.path, routeHandler);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/deployer",
3
- "version": "1.87.0-alpha.5",
3
+ "version": "1.87.0-alpha.6",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "files": [
@@ -114,7 +114,7 @@
114
114
  "tinyglobby": "^0.2.17",
115
115
  "ws": "^8.23.0",
116
116
  "yaml": "^2.9.1",
117
- "@mastra/server": "1.87.0-alpha.5"
117
+ "@mastra/server": "1.87.0-alpha.6"
118
118
  },
119
119
  "devDependencies": {
120
120
  "@hono/node-server": "^2.1.3",
@@ -140,8 +140,8 @@
140
140
  "@internal/lint": "0.0.152",
141
141
  "@internal/types-builder": "0.0.127",
142
142
  "@mastra/agent-browser": "0.7.0",
143
- "@mastra/core": "1.87.0-alpha.5",
144
- "@mastra/hono": "1.7.29-alpha.5",
143
+ "@mastra/core": "1.87.0-alpha.6",
144
+ "@mastra/hono": "1.7.29-alpha.6",
145
145
  "@mastra/mcp": "^2.11.1-alpha.0"
146
146
  },
147
147
  "peerDependencies": {