@mastra/deployer 1.87.0-alpha.10 → 1.87.0-alpha.11

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.10"
6
+ version: "1.87.0-alpha.11"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.87.0-alpha.10",
2
+ "version": "1.87.0-alpha.11",
3
3
  "package": "@mastra/deployer",
4
4
  "exports": {
5
5
  "Deployer": {
@@ -4881,6 +4881,103 @@ const getStudioPath = () => {
4881
4881
  }
4882
4882
  return process.env.MASTRA_STUDIO_PATH || (0, path.join)(__dirname$1, "studio");
4883
4883
  };
4884
+ const STUDIO_STATIC_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
4885
+ ".js",
4886
+ ".mjs",
4887
+ ".cjs",
4888
+ ".css",
4889
+ ".map",
4890
+ ".json",
4891
+ ".txt",
4892
+ ".xml",
4893
+ ".webmanifest",
4894
+ ".svg",
4895
+ ".png",
4896
+ ".jpg",
4897
+ ".jpeg",
4898
+ ".gif",
4899
+ ".webp",
4900
+ ".avif",
4901
+ ".ico",
4902
+ ".bmp",
4903
+ ".woff",
4904
+ ".woff2",
4905
+ ".ttf",
4906
+ ".otf",
4907
+ ".eot",
4908
+ ".wasm",
4909
+ ".mp4",
4910
+ ".webm",
4911
+ ".mp3",
4912
+ ".wav",
4913
+ ".pdf",
4914
+ ".zip",
4915
+ ".csv",
4916
+ ".tsv",
4917
+ ".dat",
4918
+ ".yml",
4919
+ ".yaml",
4920
+ ".toml",
4921
+ ".ini",
4922
+ ".log",
4923
+ ".md"
4924
+ ]);
4925
+ /**
4926
+ * Classify a path that is already known to be inside the enabled Studio mount as
4927
+ * a static-file request. `studioRelativePath` is the request path with the
4928
+ * configured Studio base removed (root mounting passes the original path).
4929
+ *
4930
+ * A request is static when it lives where Studio only ever serves files from —
4931
+ * `/assets/…` (Vite's hashed chunks), a top-level hidden asset folder such as
4932
+ * `/.well-known/…`, or a top-level non-`.html` file — when its last segment ends
4933
+ * in an extension the build serves files with, or when it maps to a real file in
4934
+ * the build. A *missing* file in any of those locations must still 404 rather
4935
+ * than silently become a successful HTML response, which is what the pre-fix
4936
+ * server did for every dotted path.
4937
+ *
4938
+ * Everything else is a client-side route and reaches the injected Studio HTML
4939
+ * fallback, so `/agents/lead.agent` and `/workflows/billing.v2/graph` work on a
4940
+ * hard load, as does any route that merely *contains* a dotted segment. The
4941
+ * decision never looks at the directories the build ships: a route may sit in a
4942
+ * directory whose name the build also uses, so `/agents/lead.agent` keeps working
4943
+ * even when a real `agents/` directory is part of the Studio build.
4944
+ *
4945
+ * Trade-off (maintainer decision, 2026-11-29, #30296): with no file behind it, a
4946
+ * suffixed last segment cannot be told apart from a missing asset. The decision
4947
+ * keeps the file: a route whose *last* segment names a file type is treated as a
4948
+ * missing file, so `/agents/release.json` and `/agents/report.csv` 404 by design.
4949
+ *
4950
+ * The Studio root is normalised to an absolute path before any lookup:
4951
+ * `getStudioPath()` can return a relative value (e.g. `MASTRA_STUDIO_PATH=studio`)
4952
+ * or one with a trailing separator, and the containment check has to compare like
4953
+ * with like or every lookup misses and real nested files fall through to the
4954
+ * HTML shell.
4955
+ */
4956
+ const isStudioStaticFileRequest = async (studioRelativePath) => {
4957
+ if (studioRelativePath.endsWith(".html")) return false;
4958
+ if (studioRelativePath.startsWith("/assets/")) return true;
4959
+ if (studioRelativePath.startsWith("/.")) return true;
4960
+ const withoutLeadingSlash = studioRelativePath.slice(1);
4961
+ const segments = withoutLeadingSlash.split("/");
4962
+ if (segments.length === 1 && withoutLeadingSlash.includes(".")) return true;
4963
+ const lastSegment = [...segments].reverse().find((segment) => segment.length > 0) ?? "";
4964
+ const extensionIndex = lastSegment.lastIndexOf(".");
4965
+ if (extensionIndex > 0 && extensionIndex < lastSegment.length - 1 && STUDIO_STATIC_FILE_EXTENSIONS.has(lastSegment.slice(extensionIndex).toLowerCase())) return true;
4966
+ const root = (0, path.resolve)(getStudioPath());
4967
+ const candidates = [studioRelativePath];
4968
+ try {
4969
+ const decoded = decodeURIComponent(studioRelativePath);
4970
+ if (decoded !== studioRelativePath) candidates.push(decoded);
4971
+ } catch {}
4972
+ for (const candidate of candidates) {
4973
+ const resolved = (0, path.resolve)(root, `.${candidate}`);
4974
+ if (!resolved.startsWith(`${root}${path.sep}`)) continue;
4975
+ try {
4976
+ if ((await (0, fs_promises.stat)(resolved)).isFile()) return true;
4977
+ } catch {}
4978
+ }
4979
+ return false;
4980
+ };
4884
4981
  function isSchemaApiRoute(route) {
4885
4982
  return "_mastraSchemaRoute" in route && route._mastraSchemaRoute === true;
4886
4983
  }
@@ -4919,6 +5016,39 @@ function getRouteCorsConfig(apiRoutes, pathname, method) {
4919
5016
  const route = (0, _mastra_server_auth.findMatchingCustomRoute)(pathname, method, apiRoutes)?.route;
4920
5017
  return route && !isSchemaApiRoute(route) ? route.cors : void 0;
4921
5018
  }
5019
+ const splitOnUnquoted = (headerValue, delimiter) => {
5020
+ const parts = [];
5021
+ let currentPart = "";
5022
+ let quoted = false;
5023
+ for (let index = 0; index < headerValue.length; index += 1) {
5024
+ const character = headerValue.charAt(index);
5025
+ if (quoted && character === "\\") {
5026
+ currentPart += character + headerValue.charAt(index + 1);
5027
+ index += 1;
5028
+ continue;
5029
+ }
5030
+ if (character === "\"") quoted = !quoted;
5031
+ else if (character === delimiter && !quoted) {
5032
+ parts.push(currentPart);
5033
+ currentPart = "";
5034
+ continue;
5035
+ }
5036
+ currentPart += character;
5037
+ }
5038
+ parts.push(currentPart);
5039
+ return parts;
5040
+ };
5041
+ function explicitlyAcceptsJson(acceptHeader) {
5042
+ if (!acceptHeader) return false;
5043
+ return splitOnUnquoted(acceptHeader, ",").some((mediaRange) => {
5044
+ const [mediaType, ...parameters] = splitOnUnquoted(mediaRange, ";");
5045
+ if (mediaType?.trim().toLowerCase() !== "application/json") return false;
5046
+ const quality = parameters.map((parameter) => parameter.trim().toLowerCase()).find((parameter) => parameter.startsWith("q="));
5047
+ if (quality === void 0) return true;
5048
+ const qualityValue = Number.parseFloat(quality.slice(2));
5049
+ return Number.isNaN(qualityValue) || qualityValue > 0;
5050
+ });
5051
+ }
4922
5052
  function getToolExports(tools) {
4923
5053
  try {
4924
5054
  return tools.reduce((acc, toolModule) => {
@@ -5101,9 +5231,13 @@ async function createHonoServer(mastra, options = { tools: {} }) {
5101
5231
  app.get("*", async (c, next) => {
5102
5232
  const requestPath = c.req.path;
5103
5233
  if (requestPath === apiPrefix || requestPath.startsWith(`${apiPrefix}/`) || requestPath.startsWith("/swagger-ui") || requestPath.startsWith("/openapi.json")) return await next();
5104
- if (requestPath.includes(".") && !requestPath.endsWith(".html")) return await next();
5234
+ if ((requestPath === "/web" || requestPath.startsWith("/web/")) && explicitlyAcceptsJson(c.req.header("Accept"))) return await next();
5105
5235
  const isStudioRoute = studioBasePath === "" || requestPath === studioBasePath || requestPath.startsWith(`${studioBasePath}/`);
5106
- if (options?.studio && isStudioRoute) {
5236
+ const servesStudio = Boolean(options?.studio && isStudioRoute);
5237
+ if (servesStudio) {
5238
+ if (await isStudioStaticFileRequest(requestPath.slice(studioBasePath.length))) return await next();
5239
+ } else if (requestPath.includes(".") && !requestPath.endsWith(".html")) return await next();
5240
+ if (servesStudio) {
5107
5241
  const studioPath = getStudioPath();
5108
5242
  let indexHtml = await (0, fs_promises.readFile)((0, path.join)(studioPath, "index.html"), "utf-8");
5109
5243
  const port = serverOptions?.port ?? (Number(process.env.PORT) || 4111);
@@ -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.10/dist/index.js';
2
+ import type { HonoBindings, HonoVariables } from '../_types/@mastra_hono@1.7.29-alpha.11/dist/index.js';
3
3
  import { Hono } from 'hono';
4
4
  import type { ServerBundleOptions } from './types.js';
5
5
  type Bindings = HonoBindings;
@@ -1,8 +1,8 @@
1
1
  import "../index-CLddUTqr-FaVhUOQu.js";
2
2
  import { d as normalizeStudioBase, n as escapeStudioHtmlValue, o as injectStudioHtmlConfig } from "../utils-C8gwr-ur.js";
3
3
  import { createReadStream, existsSync, statSync } from "fs";
4
- import { readFile } from "fs/promises";
5
- import { dirname, join } from "path";
4
+ import { readFile, stat } from "fs/promises";
5
+ import { dirname, join, resolve, sep } from "path";
6
6
  import { Readable, Writable } from "stream";
7
7
  import { fileURLToPath } from "url";
8
8
  import * as https from "https";
@@ -4876,6 +4876,103 @@ const getStudioPath = () => {
4876
4876
  }
4877
4877
  return process.env.MASTRA_STUDIO_PATH || join(__dirname, "studio");
4878
4878
  };
4879
+ const STUDIO_STATIC_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
4880
+ ".js",
4881
+ ".mjs",
4882
+ ".cjs",
4883
+ ".css",
4884
+ ".map",
4885
+ ".json",
4886
+ ".txt",
4887
+ ".xml",
4888
+ ".webmanifest",
4889
+ ".svg",
4890
+ ".png",
4891
+ ".jpg",
4892
+ ".jpeg",
4893
+ ".gif",
4894
+ ".webp",
4895
+ ".avif",
4896
+ ".ico",
4897
+ ".bmp",
4898
+ ".woff",
4899
+ ".woff2",
4900
+ ".ttf",
4901
+ ".otf",
4902
+ ".eot",
4903
+ ".wasm",
4904
+ ".mp4",
4905
+ ".webm",
4906
+ ".mp3",
4907
+ ".wav",
4908
+ ".pdf",
4909
+ ".zip",
4910
+ ".csv",
4911
+ ".tsv",
4912
+ ".dat",
4913
+ ".yml",
4914
+ ".yaml",
4915
+ ".toml",
4916
+ ".ini",
4917
+ ".log",
4918
+ ".md"
4919
+ ]);
4920
+ /**
4921
+ * Classify a path that is already known to be inside the enabled Studio mount as
4922
+ * a static-file request. `studioRelativePath` is the request path with the
4923
+ * configured Studio base removed (root mounting passes the original path).
4924
+ *
4925
+ * A request is static when it lives where Studio only ever serves files from —
4926
+ * `/assets/…` (Vite's hashed chunks), a top-level hidden asset folder such as
4927
+ * `/.well-known/…`, or a top-level non-`.html` file — when its last segment ends
4928
+ * in an extension the build serves files with, or when it maps to a real file in
4929
+ * the build. A *missing* file in any of those locations must still 404 rather
4930
+ * than silently become a successful HTML response, which is what the pre-fix
4931
+ * server did for every dotted path.
4932
+ *
4933
+ * Everything else is a client-side route and reaches the injected Studio HTML
4934
+ * fallback, so `/agents/lead.agent` and `/workflows/billing.v2/graph` work on a
4935
+ * hard load, as does any route that merely *contains* a dotted segment. The
4936
+ * decision never looks at the directories the build ships: a route may sit in a
4937
+ * directory whose name the build also uses, so `/agents/lead.agent` keeps working
4938
+ * even when a real `agents/` directory is part of the Studio build.
4939
+ *
4940
+ * Trade-off (maintainer decision, 2026-11-29, #30296): with no file behind it, a
4941
+ * suffixed last segment cannot be told apart from a missing asset. The decision
4942
+ * keeps the file: a route whose *last* segment names a file type is treated as a
4943
+ * missing file, so `/agents/release.json` and `/agents/report.csv` 404 by design.
4944
+ *
4945
+ * The Studio root is normalised to an absolute path before any lookup:
4946
+ * `getStudioPath()` can return a relative value (e.g. `MASTRA_STUDIO_PATH=studio`)
4947
+ * or one with a trailing separator, and the containment check has to compare like
4948
+ * with like or every lookup misses and real nested files fall through to the
4949
+ * HTML shell.
4950
+ */
4951
+ const isStudioStaticFileRequest = async (studioRelativePath) => {
4952
+ if (studioRelativePath.endsWith(".html")) return false;
4953
+ if (studioRelativePath.startsWith("/assets/")) return true;
4954
+ if (studioRelativePath.startsWith("/.")) return true;
4955
+ const withoutLeadingSlash = studioRelativePath.slice(1);
4956
+ const segments = withoutLeadingSlash.split("/");
4957
+ if (segments.length === 1 && withoutLeadingSlash.includes(".")) return true;
4958
+ const lastSegment = [...segments].reverse().find((segment) => segment.length > 0) ?? "";
4959
+ const extensionIndex = lastSegment.lastIndexOf(".");
4960
+ if (extensionIndex > 0 && extensionIndex < lastSegment.length - 1 && STUDIO_STATIC_FILE_EXTENSIONS.has(lastSegment.slice(extensionIndex).toLowerCase())) return true;
4961
+ const root = resolve(getStudioPath());
4962
+ const candidates = [studioRelativePath];
4963
+ try {
4964
+ const decoded = decodeURIComponent(studioRelativePath);
4965
+ if (decoded !== studioRelativePath) candidates.push(decoded);
4966
+ } catch {}
4967
+ for (const candidate of candidates) {
4968
+ const resolved = resolve(root, `.${candidate}`);
4969
+ if (!resolved.startsWith(`${root}${sep}`)) continue;
4970
+ try {
4971
+ if ((await stat(resolved)).isFile()) return true;
4972
+ } catch {}
4973
+ }
4974
+ return false;
4975
+ };
4879
4976
  function isSchemaApiRoute(route) {
4880
4977
  return "_mastraSchemaRoute" in route && route._mastraSchemaRoute === true;
4881
4978
  }
@@ -4914,6 +5011,39 @@ function getRouteCorsConfig(apiRoutes, pathname, method) {
4914
5011
  const route = findMatchingCustomRoute(pathname, method, apiRoutes)?.route;
4915
5012
  return route && !isSchemaApiRoute(route) ? route.cors : void 0;
4916
5013
  }
5014
+ const splitOnUnquoted = (headerValue, delimiter) => {
5015
+ const parts = [];
5016
+ let currentPart = "";
5017
+ let quoted = false;
5018
+ for (let index = 0; index < headerValue.length; index += 1) {
5019
+ const character = headerValue.charAt(index);
5020
+ if (quoted && character === "\\") {
5021
+ currentPart += character + headerValue.charAt(index + 1);
5022
+ index += 1;
5023
+ continue;
5024
+ }
5025
+ if (character === "\"") quoted = !quoted;
5026
+ else if (character === delimiter && !quoted) {
5027
+ parts.push(currentPart);
5028
+ currentPart = "";
5029
+ continue;
5030
+ }
5031
+ currentPart += character;
5032
+ }
5033
+ parts.push(currentPart);
5034
+ return parts;
5035
+ };
5036
+ function explicitlyAcceptsJson(acceptHeader) {
5037
+ if (!acceptHeader) return false;
5038
+ return splitOnUnquoted(acceptHeader, ",").some((mediaRange) => {
5039
+ const [mediaType, ...parameters] = splitOnUnquoted(mediaRange, ";");
5040
+ if (mediaType?.trim().toLowerCase() !== "application/json") return false;
5041
+ const quality = parameters.map((parameter) => parameter.trim().toLowerCase()).find((parameter) => parameter.startsWith("q="));
5042
+ if (quality === void 0) return true;
5043
+ const qualityValue = Number.parseFloat(quality.slice(2));
5044
+ return Number.isNaN(qualityValue) || qualityValue > 0;
5045
+ });
5046
+ }
4917
5047
  function getToolExports(tools) {
4918
5048
  try {
4919
5049
  return tools.reduce((acc, toolModule) => {
@@ -5096,9 +5226,13 @@ async function createHonoServer(mastra, options = { tools: {} }) {
5096
5226
  app.get("*", async (c, next) => {
5097
5227
  const requestPath = c.req.path;
5098
5228
  if (requestPath === apiPrefix || requestPath.startsWith(`${apiPrefix}/`) || requestPath.startsWith("/swagger-ui") || requestPath.startsWith("/openapi.json")) return await next();
5099
- if (requestPath.includes(".") && !requestPath.endsWith(".html")) return await next();
5229
+ if ((requestPath === "/web" || requestPath.startsWith("/web/")) && explicitlyAcceptsJson(c.req.header("Accept"))) return await next();
5100
5230
  const isStudioRoute = studioBasePath === "" || requestPath === studioBasePath || requestPath.startsWith(`${studioBasePath}/`);
5101
- if (options?.studio && isStudioRoute) {
5231
+ const servesStudio = Boolean(options?.studio && isStudioRoute);
5232
+ if (servesStudio) {
5233
+ if (await isStudioStaticFileRequest(requestPath.slice(studioBasePath.length))) return await next();
5234
+ } else if (requestPath.includes(".") && !requestPath.endsWith(".html")) return await next();
5235
+ if (servesStudio) {
5102
5236
  const studioPath = getStudioPath();
5103
5237
  let indexHtml = await readFile(join(studioPath, "index.html"), "utf-8");
5104
5238
  const port = serverOptions?.port ?? (Number(process.env.PORT) || 4111);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/deployer",
3
- "version": "1.87.0-alpha.10",
3
+ "version": "1.87.0-alpha.11",
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.10"
117
+ "@mastra/server": "1.87.0-alpha.11"
118
118
  },
119
119
  "devDependencies": {
120
120
  "@hono/node-server": "^2.1.3",
@@ -135,14 +135,14 @@
135
135
  "vitest": "5.1.0",
136
136
  "zod": "^4.6.7",
137
137
  "@internal/core": "0.1.4",
138
- "@internal/types-builder": "0.0.127",
139
- "@internal/lint": "0.0.152",
140
138
  "@internal/deployer": "0.0.5",
139
+ "@internal/find-workspaces": "0.0.7",
140
+ "@internal/lint": "0.0.152",
141
+ "@internal/types-builder": "0.0.127",
141
142
  "@mastra/agent-browser": "0.7.1-alpha.0",
142
- "@mastra/core": "1.87.0-alpha.10",
143
- "@mastra/hono": "1.7.29-alpha.10",
144
- "@mastra/mcp": "^2.11.1-alpha.1",
145
- "@internal/find-workspaces": "0.0.7"
143
+ "@mastra/core": "1.87.0-alpha.11",
144
+ "@mastra/hono": "1.7.29-alpha.11",
145
+ "@mastra/mcp": "^2.11.1-alpha.1"
146
146
  },
147
147
  "peerDependencies": {
148
148
  "@mastra/core": ">=1.85.1-0 <2.0.0-0"