@mastra/deployer 1.8.0 → 1.9.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.
Files changed (72) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/LICENSE.md +15 -0
  3. package/dist/build/analyze/bundleExternals.d.ts +2 -0
  4. package/dist/build/analyze/bundleExternals.d.ts.map +1 -1
  5. package/dist/build/analyze/constants.d.ts.map +1 -1
  6. package/dist/build/analyze.cjs +2 -2
  7. package/dist/build/analyze.d.ts +1 -1
  8. package/dist/build/analyze.d.ts.map +1 -1
  9. package/dist/build/analyze.js +1 -1
  10. package/dist/build/bundler.cjs +3 -3
  11. package/dist/build/bundler.d.ts.map +1 -1
  12. package/dist/build/bundler.js +1 -1
  13. package/dist/build/index.cjs +18 -14
  14. package/dist/build/index.d.ts +2 -2
  15. package/dist/build/index.d.ts.map +1 -1
  16. package/dist/build/index.js +5 -5
  17. package/dist/build/utils.d.ts +43 -0
  18. package/dist/build/utils.d.ts.map +1 -1
  19. package/dist/bundler/index.cjs +3 -3
  20. package/dist/bundler/index.js +1 -1
  21. package/dist/{chunk-SYOOUXQR.cjs → chunk-2U66YH5A.cjs} +16 -16
  22. package/dist/{chunk-SYOOUXQR.cjs.map → chunk-2U66YH5A.cjs.map} +1 -1
  23. package/dist/{chunk-2ADDVHED.js → chunk-56QWTZZP.js} +7 -7
  24. package/dist/{chunk-2ADDVHED.js.map → chunk-56QWTZZP.js.map} +1 -1
  25. package/dist/{chunk-CAHLKF47.js → chunk-6UIXBIO6.js} +43 -22
  26. package/dist/chunk-6UIXBIO6.js.map +1 -0
  27. package/dist/{chunk-SAAWBL2Q.cjs → chunk-73SEUI3W.cjs} +79 -58
  28. package/dist/chunk-73SEUI3W.cjs.map +1 -0
  29. package/dist/{chunk-AMZJCH64.js → chunk-ANF3UFZ3.js} +3 -3
  30. package/dist/{chunk-AMZJCH64.js.map → chunk-ANF3UFZ3.js.map} +1 -1
  31. package/dist/{chunk-TOBYD27M.cjs → chunk-EBHDMP6N.cjs} +16 -16
  32. package/dist/{chunk-TOBYD27M.cjs.map → chunk-EBHDMP6N.cjs.map} +1 -1
  33. package/dist/{chunk-KRRQVSI7.js → chunk-EZBW45SX.js} +7 -13
  34. package/dist/chunk-EZBW45SX.js.map +1 -0
  35. package/dist/{chunk-ITC6JDLC.cjs → chunk-G7R456H2.cjs} +33 -2
  36. package/dist/chunk-G7R456H2.cjs.map +1 -0
  37. package/dist/{chunk-MIZUMHGW.js → chunk-IMLDKOVJ.js} +7 -7
  38. package/dist/{chunk-MIZUMHGW.js.map → chunk-IMLDKOVJ.js.map} +1 -1
  39. package/dist/{chunk-3WL6HPU3.js → chunk-O73YCD6A.js} +3 -3
  40. package/dist/{chunk-3WL6HPU3.js.map → chunk-O73YCD6A.js.map} +1 -1
  41. package/dist/{chunk-R2SIOO54.cjs → chunk-R2SYO6PH.cjs} +20 -26
  42. package/dist/chunk-R2SYO6PH.cjs.map +1 -0
  43. package/dist/{chunk-K7J2W7DJ.cjs → chunk-UPVHAZ5Q.cjs} +7 -7
  44. package/dist/{chunk-K7J2W7DJ.cjs.map → chunk-UPVHAZ5Q.cjs.map} +1 -1
  45. package/dist/{chunk-UKA2IZKF.js → chunk-XN3FKMO6.js} +32 -3
  46. package/dist/chunk-XN3FKMO6.js.map +1 -0
  47. package/dist/{chunk-E4SQOERA.cjs → chunk-YIUDHDPS.cjs} +4 -4
  48. package/dist/{chunk-E4SQOERA.cjs.map → chunk-YIUDHDPS.cjs.map} +1 -1
  49. package/dist/docs/SKILL.md +1 -1
  50. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  51. package/dist/index.cjs +4 -4
  52. package/dist/index.js +2 -2
  53. package/dist/server/index.cjs +151 -155
  54. package/dist/server/index.cjs.map +1 -1
  55. package/dist/server/index.d.ts.map +1 -1
  56. package/dist/server/index.js +149 -153
  57. package/dist/server/index.js.map +1 -1
  58. package/dist/validator/custom-resolver.cjs +28 -2
  59. package/dist/validator/custom-resolver.cjs.map +1 -1
  60. package/dist/validator/custom-resolver.d.ts +15 -1
  61. package/dist/validator/custom-resolver.d.ts.map +1 -1
  62. package/dist/validator/custom-resolver.js +27 -2
  63. package/dist/validator/custom-resolver.js.map +1 -1
  64. package/dist/validator/validate.d.ts +2 -1
  65. package/dist/validator/validate.d.ts.map +1 -1
  66. package/package.json +7 -7
  67. package/dist/chunk-CAHLKF47.js.map +0 -1
  68. package/dist/chunk-ITC6JDLC.cjs.map +0 -1
  69. package/dist/chunk-KRRQVSI7.js.map +0 -1
  70. package/dist/chunk-R2SIOO54.cjs.map +0 -1
  71. package/dist/chunk-SAAWBL2Q.cjs.map +0 -1
  72. package/dist/chunk-UKA2IZKF.js.map +0 -1
@@ -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;AAGlD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGhE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAW5B,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;AAEF,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;2CA8VhE;AAED,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAmC,mDAqDlG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAGlD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGhE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAW5B,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;AAEF,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;2CA0WhE;AAED,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAmC,mDAqDlG"}
@@ -1,4 +1,4 @@
1
- import { normalizeStudioBase } from '../chunk-UKA2IZKF.js';
1
+ import { normalizeStudioBase, injectStudioHtmlConfig } from '../chunk-XN3FKMO6.js';
2
2
  import { readFile } from 'fs/promises';
3
3
  import * as https from 'https';
4
4
  import { join, dirname } from 'path';
@@ -16,7 +16,6 @@ import { formatZodError } from '@mastra/server/handlers/error';
16
16
  import { MastraServer as MastraServer$1, normalizeQueryParams, redactStreamChunk } from '@mastra/server/server-adapter';
17
17
  import util from 'util';
18
18
  import { Buffer as Buffer$1 } from 'buffer';
19
- import { isDevPlaygroundRequest, isProtectedPath, canAccessPublicly, checkRules, defaultAuthConfig } from '@mastra/server/auth';
20
19
  import { InMemoryTaskStore } from '@mastra/server/a2a/store';
21
20
  import { Hono } from 'hono';
22
21
  import { cors } from 'hono/cors';
@@ -2655,6 +2654,8 @@ function toFetchResponse(res) {
2655
2654
  }
2656
2655
  return res.fetchResponse;
2657
2656
  }
2657
+
2658
+ // ../../server-adapters/hono/dist/index.js
2658
2659
  var HTTPException = class extends Error {
2659
2660
  res;
2660
2661
  status;
@@ -3056,117 +3057,18 @@ ZodError.create = (issues) => {
3056
3057
  const error = new ZodError(issues);
3057
3058
  return error;
3058
3059
  };
3059
- var authenticationMiddleware = async (c, next) => {
3060
- const mastra = c.get("mastra");
3061
- const authConfig = mastra.getServer()?.auth;
3062
- const customRouteAuthConfig = c.get("customRouteAuthConfig");
3063
- if (!authConfig) {
3064
- return next();
3065
- }
3066
- const path = c.req.path;
3067
- const method = c.req.method;
3068
- const getHeader = (name) => c.req.header(name);
3069
- if (isDevPlaygroundRequest(path, method, getHeader, authConfig, customRouteAuthConfig)) {
3070
- return next();
3071
- }
3072
- if (!isProtectedPath(c.req.path, c.req.method, authConfig, customRouteAuthConfig)) {
3073
- return next();
3074
- }
3075
- if (canAccessPublicly(c.req.path, c.req.method, authConfig)) {
3076
- return next();
3077
- }
3078
- const authHeader = c.req.header("Authorization");
3079
- let token = authHeader ? authHeader.replace("Bearer ", "") : null;
3080
- if (!token && c.req.query("apiKey")) {
3081
- token = c.req.query("apiKey") || null;
3082
- }
3083
- if (!token) {
3084
- return c.json({ error: "Authentication required" }, 401);
3085
- }
3086
- try {
3087
- let user;
3088
- if (typeof authConfig.authenticateToken === "function") {
3089
- user = await authConfig.authenticateToken(token, c.req);
3090
- } else {
3091
- throw new Error("No token verification method configured");
3092
- }
3093
- if (!user) {
3094
- return c.json({ error: "Invalid or expired token" }, 401);
3095
- }
3096
- c.get("requestContext").set("user", user);
3097
- return next();
3098
- } catch (err) {
3099
- mastra.getLogger()?.error("Authentication error", {
3100
- error: err instanceof Error ? { message: err.message, stack: err.stack } : err
3060
+ var _hasPermissionPromise;
3061
+ function loadHasPermission() {
3062
+ if (!_hasPermissionPromise) {
3063
+ _hasPermissionPromise = import('@mastra/core/auth/ee').then((m) => m.hasPermission).catch(() => {
3064
+ console.error(
3065
+ "[@mastra/hono] Auth features require @mastra/core >= 1.6.0. Please upgrade: npm install @mastra/core@latest"
3066
+ );
3067
+ return void 0;
3101
3068
  });
3102
- return c.json({ error: "Invalid or expired token" }, 401);
3103
3069
  }
3104
- };
3105
- var authorizationMiddleware = async (c, next) => {
3106
- const mastra = c.get("mastra");
3107
- const authConfig = mastra.getServer()?.auth;
3108
- const customRouteAuthConfig = c.get("customRouteAuthConfig");
3109
- if (!authConfig) {
3110
- return next();
3111
- }
3112
- const path = c.req.path;
3113
- const method = c.req.method;
3114
- const getHeader = (name) => c.req.header(name);
3115
- if (isDevPlaygroundRequest(path, method, getHeader, authConfig, customRouteAuthConfig)) {
3116
- return next();
3117
- }
3118
- if (!isProtectedPath(c.req.path, c.req.method, authConfig, customRouteAuthConfig)) {
3119
- return next();
3120
- }
3121
- if (canAccessPublicly(path, method, authConfig)) {
3122
- return next();
3123
- }
3124
- const user = c.get("requestContext").get("user");
3125
- if ("authorizeUser" in authConfig && typeof authConfig.authorizeUser === "function") {
3126
- try {
3127
- const isAuthorized = await authConfig.authorizeUser(user, c.req);
3128
- if (isAuthorized) {
3129
- return next();
3130
- }
3131
- return c.json({ error: "Access denied" }, 403);
3132
- } catch (err) {
3133
- mastra.getLogger()?.error("Authorization error in authorizeUser", {
3134
- error: err instanceof Error ? { message: err.message, stack: err.stack } : err
3135
- });
3136
- return c.json({ error: "Authorization error" }, 500);
3137
- }
3138
- }
3139
- if ("authorize" in authConfig && typeof authConfig.authorize === "function") {
3140
- try {
3141
- const isAuthorized = await authConfig.authorize(path, method, user, c);
3142
- if (isAuthorized) {
3143
- return next();
3144
- }
3145
- return c.json({ error: "Access denied" }, 403);
3146
- } catch (err) {
3147
- mastra.getLogger()?.error("Authorization error in authorize", {
3148
- error: err instanceof Error ? { message: err.message, stack: err.stack } : err,
3149
- path,
3150
- method
3151
- });
3152
- return c.json({ error: "Authorization error" }, 500);
3153
- }
3154
- }
3155
- if ("rules" in authConfig && authConfig.rules && authConfig.rules.length > 0) {
3156
- const isAuthorized = await checkRules(authConfig.rules, path, method, user);
3157
- if (isAuthorized) {
3158
- return next();
3159
- }
3160
- return c.json({ error: "Access denied" }, 403);
3161
- }
3162
- if (defaultAuthConfig.rules && defaultAuthConfig.rules.length > 0) {
3163
- const isAuthorized = await checkRules(defaultAuthConfig.rules, path, method, user);
3164
- if (isAuthorized) {
3165
- return next();
3166
- }
3167
- }
3168
- return c.json({ error: "Access denied" }, 403);
3169
- };
3070
+ return _hasPermissionPromise;
3071
+ }
3170
3072
  var MastraServer = class extends MastraServer$1 {
3171
3073
  createContextMiddleware() {
3172
3074
  return async (c, next) => {
@@ -3185,7 +3087,8 @@ var MastraServer = class extends MastraServer$1 {
3185
3087
  let paramsRequestContext;
3186
3088
  if (c.req.method === "POST" || c.req.method === "PUT") {
3187
3089
  const contentType = c.req.header("content-type");
3188
- if (contentType?.includes("application/json")) {
3090
+ const contentLength = c.req.header("content-length");
3091
+ if (contentType?.includes("application/json") && contentLength !== "0") {
3189
3092
  try {
3190
3093
  const body = await c.req.raw.clone().json();
3191
3094
  if (body.requestContext) {
@@ -3411,7 +3314,9 @@ var MastraServer = class extends MastraServer$1 {
3411
3314
  method: c.req.method,
3412
3315
  getHeader: (name) => c.req.header(name),
3413
3316
  getQuery: (name) => c.req.query(name),
3414
- requestContext: c.get("requestContext")
3317
+ requestContext: c.get("requestContext"),
3318
+ request: c.req.raw,
3319
+ buildAuthorizeContext: () => c
3415
3320
  });
3416
3321
  if (authError) {
3417
3322
  return c.json({ error: authError.error }, authError.status);
@@ -3492,8 +3397,27 @@ var MastraServer = class extends MastraServer$1 {
3492
3397
  registeredTools: c.get("registeredTools"),
3493
3398
  taskStore: c.get("taskStore"),
3494
3399
  abortSignal: c.get("abortSignal"),
3495
- routePrefix: prefix
3400
+ routePrefix: prefix,
3401
+ request: c.req.raw
3402
+ // Standard Request object with headers/cookies
3496
3403
  };
3404
+ const authConfig = this.mastra.getServer()?.auth;
3405
+ if (authConfig) {
3406
+ const hasPermission = await loadHasPermission();
3407
+ if (hasPermission) {
3408
+ const userPermissions = c.get("requestContext").get("userPermissions");
3409
+ const permissionError = this.checkRoutePermission(route, userPermissions, hasPermission);
3410
+ if (permissionError) {
3411
+ return c.json(
3412
+ {
3413
+ error: permissionError.error,
3414
+ message: permissionError.message
3415
+ },
3416
+ permissionError.status
3417
+ );
3418
+ }
3419
+ }
3420
+ }
3497
3421
  try {
3498
3422
  const result = await route.handler(handlerParams);
3499
3423
  return this.sendResponse(route, c, result, prefix);
@@ -3539,6 +3463,43 @@ var MastraServer = class extends MastraServer$1 {
3539
3463
  const handler = "handler" in route && route.handler ? route.handler : "createHandler" in route ? await route.createHandler({ mastra: this.mastra }) : void 0;
3540
3464
  if (!handler) continue;
3541
3465
  const middlewares = [];
3466
+ const serverRoute = {
3467
+ method: route.method,
3468
+ path: route.path,
3469
+ responseType: "json",
3470
+ handler: async () => {
3471
+ },
3472
+ requiresAuth: route.requiresAuth
3473
+ };
3474
+ middlewares.push(async (c, next) => {
3475
+ const authError = await this.checkRouteAuth(serverRoute, {
3476
+ path: c.req.path,
3477
+ method: c.req.method,
3478
+ getHeader: (name) => c.req.header(name),
3479
+ getQuery: (name) => c.req.query(name),
3480
+ requestContext: c.get("requestContext"),
3481
+ request: c.req.raw,
3482
+ buildAuthorizeContext: () => c
3483
+ });
3484
+ if (authError) {
3485
+ return c.json({ error: authError.error }, authError.status);
3486
+ }
3487
+ const authConfig = this.mastra.getServer()?.auth;
3488
+ if (authConfig) {
3489
+ const hasPermission = await loadHasPermission();
3490
+ if (hasPermission) {
3491
+ const userPermissions = c.get("requestContext").get("userPermissions");
3492
+ const permissionError = this.checkRoutePermission(serverRoute, userPermissions, hasPermission);
3493
+ if (permissionError) {
3494
+ return c.json(
3495
+ { error: permissionError.error, message: permissionError.message },
3496
+ permissionError.status
3497
+ );
3498
+ }
3499
+ }
3500
+ }
3501
+ return next();
3502
+ });
3542
3503
  if (route.middleware) {
3543
3504
  middlewares.push(...Array.isArray(route.middleware) ? route.middleware : [route.middleware]);
3544
3505
  }
@@ -3551,12 +3512,44 @@ var MastraServer = class extends MastraServer$1 {
3551
3512
  this.app.use("*", this.createContextMiddleware());
3552
3513
  }
3553
3514
  registerAuthMiddleware() {
3554
- const authConfig = this.mastra.getServer()?.auth;
3555
- if (!authConfig) {
3515
+ }
3516
+ registerHttpLoggingMiddleware() {
3517
+ if (!this.httpLoggingConfig?.enabled) {
3556
3518
  return;
3557
3519
  }
3558
- this.app.use("*", authenticationMiddleware);
3559
- this.app.use("*", authorizationMiddleware);
3520
+ this.app.use("*", async (c, next) => {
3521
+ if (!this.shouldLogRequest(c.req.path)) {
3522
+ return next();
3523
+ }
3524
+ const start = Date.now();
3525
+ const method = c.req.method;
3526
+ const path = c.req.path;
3527
+ await next();
3528
+ const duration = Date.now() - start;
3529
+ const status = c.res.status;
3530
+ const level = this.httpLoggingConfig?.level || "info";
3531
+ const logData = {
3532
+ method,
3533
+ path,
3534
+ status,
3535
+ duration: `${duration}ms`
3536
+ };
3537
+ if (this.httpLoggingConfig?.includeQueryParams) {
3538
+ logData.query = c.req.query();
3539
+ }
3540
+ if (this.httpLoggingConfig?.includeHeaders) {
3541
+ const headers = Object.fromEntries(c.req.raw.headers.entries());
3542
+ const redactHeaders = this.httpLoggingConfig.redactHeaders || [];
3543
+ redactHeaders.forEach((h) => {
3544
+ const key = h.toLowerCase();
3545
+ if (headers[key] !== void 0) {
3546
+ headers[key] = "[REDACTED]";
3547
+ }
3548
+ });
3549
+ logData.headers = headers;
3550
+ }
3551
+ this.logger[level](`${method} ${path} ${status} ${duration}ms`, logData);
3552
+ });
3560
3553
  }
3561
3554
  };
3562
3555
 
@@ -3917,9 +3910,16 @@ async function createHonoServer(mastra, options = {
3917
3910
  const server = mastra.getServer();
3918
3911
  const a2aTaskStore = new InMemoryTaskStore();
3919
3912
  const routes = server?.apiRoutes;
3913
+ const processedRoutes = routes?.map((route) => {
3914
+ if ("openapi" in route && route.openapi) {
3915
+ const existingMiddleware = route.middleware ? Array.isArray(route.middleware) ? route.middleware : [route.middleware] : [];
3916
+ return { ...route, middleware: [describeRoute(route.openapi), ...existingMiddleware] };
3917
+ }
3918
+ return route;
3919
+ });
3920
3920
  const customRouteAuthConfig = /* @__PURE__ */ new Map();
3921
- if (routes) {
3922
- for (const route of routes) {
3921
+ if (processedRoutes) {
3922
+ for (const route of processedRoutes) {
3923
3923
  const requiresAuth = route.requiresAuth !== false;
3924
3924
  const routeKey = `${route.method}:${route.path}`;
3925
3925
  customRouteAuthConfig.set(routeKey, requiresAuth);
@@ -3945,7 +3945,7 @@ async function createHonoServer(mastra, options = {
3945
3945
  bodyLimitOptions,
3946
3946
  openapiPath: options?.isDev || server?.build?.openAPIDocs ? "/openapi.json" : void 0,
3947
3947
  customRouteAuthConfig,
3948
- customApiRoutes: routes
3948
+ customApiRoutes: processedRoutes
3949
3949
  });
3950
3950
  honoServerAdapter.registerContextMiddleware();
3951
3951
  const serverMiddleware = mastra.getServerMiddleware?.();
@@ -3957,10 +3957,20 @@ async function createHonoServer(mastra, options = {
3957
3957
  if (server?.cors === false) {
3958
3958
  app.use("*", timeout(server?.timeout ?? 3 * 60 * 1e3));
3959
3959
  } else {
3960
+ const hasAuth = !!server?.auth;
3961
+ let corsOrigin;
3962
+ if (server?.cors && typeof server.cors === "object" && "origin" in server.cors && server.cors.origin) {
3963
+ corsOrigin = server.cors.origin;
3964
+ } else if (hasAuth) {
3965
+ corsOrigin = (origin) => origin || void 0;
3966
+ } else {
3967
+ corsOrigin = "*";
3968
+ }
3960
3969
  const corsConfig = {
3961
- origin: "*",
3970
+ origin: corsOrigin,
3962
3971
  allowMethods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
3963
- credentials: false,
3972
+ // Enable credentials for cookie-based auth (e.g., Better Auth sessions)
3973
+ credentials: hasAuth ? true : false,
3964
3974
  maxAge: 3600,
3965
3975
  ...server?.cors,
3966
3976
  allowHeaders: ["Content-Type", "Authorization", "x-mastra-client-type", ...server?.cors?.allowHeaders ?? []],
@@ -3996,6 +4006,7 @@ async function createHonoServer(mastra, options = {
3996
4006
  rootHandler
3997
4007
  );
3998
4008
  }
4009
+ await honoServerAdapter.validateEELicense();
3999
4010
  honoServerAdapter.registerAuthMiddleware();
4000
4011
  if (server?.middleware) {
4001
4012
  const normalizedMiddlewares = Array.isArray(server.middleware) ? server.middleware : [server.middleware];
@@ -4012,24 +4023,7 @@ async function createHonoServer(mastra, options = {
4012
4023
  app.use(middleware2.path, middleware2.handler);
4013
4024
  }
4014
4025
  }
4015
- if (routes) {
4016
- for (const route of routes) {
4017
- const middlewares = [];
4018
- if (route.middleware) {
4019
- middlewares.push(...Array.isArray(route.middleware) ? route.middleware : [route.middleware]);
4020
- }
4021
- if (route.openapi) {
4022
- middlewares.push(describeRoute(route.openapi));
4023
- }
4024
- const handler = "handler" in route ? route.handler : await route.createHandler({ mastra });
4025
- const allHandlers = [...middlewares, handler];
4026
- if (route.method === "ALL") {
4027
- app.all(route.path, allHandlers[0], ...allHandlers.slice(1));
4028
- } else {
4029
- app.on(route.method, route.path, allHandlers[0], ...allHandlers.slice(1));
4030
- }
4031
- }
4032
- }
4026
+ await honoServerAdapter.registerCustomApiRoutes();
4033
4027
  if (server?.build?.apiReqLogs) {
4034
4028
  app.use(logger());
4035
4029
  }
@@ -4129,18 +4123,20 @@ async function createHonoServer(mastra, options = {
4129
4123
  const escapeForHtml = (json) => {
4130
4124
  return json.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
4131
4125
  };
4132
- indexHtml = indexHtml.replace(`'%%MASTRA_SERVER_HOST%%'`, `'${host}'`);
4133
- indexHtml = indexHtml.replace(`'%%MASTRA_SERVER_PORT%%'`, `'${port}'`);
4134
- indexHtml = indexHtml.replace(`'%%MASTRA_API_PREFIX%%'`, `'${serverOptions?.apiPrefix ?? "/api"}'`);
4135
- indexHtml = indexHtml.replace(`'%%MASTRA_HIDE_CLOUD_CTA%%'`, `'${hideCloudCta}'`);
4136
- indexHtml = indexHtml.replace(`'%%MASTRA_SERVER_PROTOCOL%%'`, `'${protocol}'`);
4137
- indexHtml = indexHtml.replace(`'%%MASTRA_CLOUD_API_ENDPOINT%%'`, `'${cloudApiEndpoint}'`);
4138
- indexHtml = indexHtml.replace(`'%%MASTRA_EXPERIMENTAL_FEATURES%%'`, `'${experimentalFeatures}'`);
4139
- indexHtml = indexHtml.replace(
4140
- `'%%MASTRA_REQUEST_CONTEXT_PRESETS%%'`,
4141
- `'${escapeForHtml(requestContextPresets)}'`
4142
- );
4143
- indexHtml = indexHtml.replaceAll("%%MASTRA_STUDIO_BASE_PATH%%", studioBasePath);
4126
+ const autoDetectUrl = process.env.MASTRA_AUTO_DETECT_URL === "true";
4127
+ indexHtml = injectStudioHtmlConfig(indexHtml, {
4128
+ host: `'${host}'`,
4129
+ port: `'${port}'`,
4130
+ protocol: `'${protocol}'`,
4131
+ apiPrefix: `'${serverOptions?.apiPrefix ?? "/api"}'`,
4132
+ basePath: studioBasePath,
4133
+ hideCloudCta: `'${hideCloudCta}'`,
4134
+ cloudApiEndpoint: `'${cloudApiEndpoint}'`,
4135
+ experimentalFeatures: `'${experimentalFeatures}'`,
4136
+ telemetryDisabled: `''`,
4137
+ requestContextPresets: `'${escapeForHtml(requestContextPresets)}'`,
4138
+ autoDetectUrl: `'${autoDetectUrl}'`
4139
+ });
4144
4140
  return c.newResponse(indexHtml, 200, { "Content-Type": "text/html" });
4145
4141
  }
4146
4142
  return c.newResponse(html2, 200, { "Content-Type": "text/html" });