@mastra/deployer 1.36.0-alpha.0 → 1.36.0-alpha.10

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/CHANGELOG.md CHANGED
@@ -1,5 +1,138 @@
1
1
  # @mastra/deployer
2
2
 
3
+ ## 1.36.0-alpha.10
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`27fd1b7`](https://github.com/mastra-ai/mastra/commit/27fd1b79ac62eb7694f92587eb7d1be05b59be01), [`a702009`](https://github.com/mastra-ai/mastra/commit/a702009d3cfaa745120f501e21c783ed4d6a3072), [`48cf61e`](https://github.com/mastra-ai/mastra/commit/48cf61e2cc759a61b6631566acf381d46ca9e12e), [`8534d79`](https://github.com/mastra-ai/mastra/commit/8534d791fa1cb70fe1c19e2604c4b63cc10dd051), [`c78f8cd`](https://github.com/mastra-ai/mastra/commit/c78f8cd6222a86e6c60ae5210b6929ad5221b6fb), [`e146aad`](https://github.com/mastra-ai/mastra/commit/e146aadbba66c410ba0e74bac4c50135495cb8dd), [`1a0ec78`](https://github.com/mastra-ai/mastra/commit/1a0ec789a26cae443744e9abbd62ed6ee676af39), [`d52b6fe`](https://github.com/mastra-ai/mastra/commit/d52b6fe1c56853eb38864baae0bbfa75cc739ccb)]:
8
+ - @mastra/core@1.36.0-alpha.10
9
+ - @mastra/server@1.36.0-alpha.10
10
+
11
+ ## 1.36.0-alpha.9
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [[`bd92c15`](https://github.com/mastra-ai/mastra/commit/bd92c154238ce5d05e12d5477da07c7b7292c5e3), [`bd92c15`](https://github.com/mastra-ai/mastra/commit/bd92c154238ce5d05e12d5477da07c7b7292c5e3), [`1698f5e`](https://github.com/mastra-ai/mastra/commit/1698f5ec141d34f22a873efdb145ce3cdf848a5e)]:
16
+ - @mastra/server@1.36.0-alpha.9
17
+ - @mastra/core@1.36.0-alpha.9
18
+
19
+ ## 1.36.0-alpha.8
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies [[`9aee493`](https://github.com/mastra-ai/mastra/commit/9aee493ed6089b5133472623dcce49934bf2d509)]:
24
+ - @mastra/core@1.36.0-alpha.8
25
+ - @mastra/server@1.36.0-alpha.8
26
+
27
+ ## 1.36.0-alpha.7
28
+
29
+ ### Patch Changes
30
+
31
+ - Browser streaming now works for stored agents. The deployer's `getToolset` first checks the runtime agent registry, then falls back to the editor's stored-agent lookup, so agents created at runtime through the editor can stream browser sessions without being pre-registered in code. ([#16778](https://github.com/mastra-ai/mastra/pull/16778))
32
+
33
+ - Updated dependencies [[`a935b0a`](https://github.com/mastra-ai/mastra/commit/a935b0a0977ae3f196b33ec7621f528069c82db0), [`a935b0a`](https://github.com/mastra-ai/mastra/commit/a935b0a0977ae3f196b33ec7621f528069c82db0)]:
34
+ - @mastra/core@1.36.0-alpha.7
35
+ - @mastra/server@1.36.0-alpha.7
36
+
37
+ ## 1.36.0-alpha.6
38
+
39
+ ### Patch Changes
40
+
41
+ - Updated dependencies [[`71a820b`](https://github.com/mastra-ai/mastra/commit/71a820b2353fa1406772c50760a3732058a8b337)]:
42
+ - @mastra/core@1.36.0-alpha.6
43
+ - @mastra/server@1.36.0-alpha.6
44
+
45
+ ## 1.36.0-alpha.5
46
+
47
+ ### Patch Changes
48
+
49
+ - Updated dependencies [[`ac79462`](https://github.com/mastra-ai/mastra/commit/ac79462b98f1062394c45093aa515b0766f27ee2), [`19281c7`](https://github.com/mastra-ai/mastra/commit/19281c70424f757219782de16c2699743c5e04d0)]:
50
+ - @mastra/core@1.36.0-alpha.5
51
+ - @mastra/server@1.36.0-alpha.5
52
+
53
+ ## 1.36.0-alpha.4
54
+
55
+ ### Patch Changes
56
+
57
+ - Updated dependencies [[`c272d50`](https://github.com/mastra-ai/mastra/commit/c272d50610a54496b6b6d92ccd4d37b333a2613a), [`d8692af`](https://github.com/mastra-ai/mastra/commit/d8692afa253028e39cdce2aafa0ac414071a762e), [`841a222`](https://github.com/mastra-ai/mastra/commit/841a222560d8c19238f8213713f30535cdd82284)]:
58
+ - @mastra/core@1.36.0-alpha.4
59
+ - @mastra/server@1.36.0-alpha.4
60
+
61
+ ## 1.36.0-alpha.3
62
+
63
+ ### Patch Changes
64
+
65
+ - Updated dependencies [[`5556cc1`](https://github.com/mastra-ai/mastra/commit/5556cc1befec71518d84f826b3bfe3a079a9daf7), [`5499303`](https://github.com/mastra-ai/mastra/commit/54993032c1ebc09642625b78d2014e0cf84a3cae), [`5499303`](https://github.com/mastra-ai/mastra/commit/54993032c1ebc09642625b78d2014e0cf84a3cae), [`3498b49`](https://github.com/mastra-ai/mastra/commit/3498b4946be94f4313cd817733589680dcda5278), [`e47bca7`](https://github.com/mastra-ai/mastra/commit/e47bca7b72866d3abd173b9f530ac4318113a8ff), [`bfadd40`](https://github.com/mastra-ai/mastra/commit/bfadd4049df2977080f7f6c1602dc094a6e0f2f4), [`0031d0f`](https://github.com/mastra-ai/mastra/commit/0031d0f13831d7843ac5d498734a7d92862e2ce3), [`3498b49`](https://github.com/mastra-ai/mastra/commit/3498b4946be94f4313cd817733589680dcda5278), [`359439b`](https://github.com/mastra-ai/mastra/commit/359439bb8c635e048176306828195f8297f50021)]:
66
+ - @mastra/core@1.36.0-alpha.3
67
+ - @mastra/server@1.36.0-alpha.3
68
+
69
+ ## 1.36.0-alpha.2
70
+
71
+ ### Patch Changes
72
+
73
+ - When browser streaming is unavailable (the `ws` and `@hono/node-ws` packages aren't installed, or the deployer is running in a serverless environment), the deployer now registers a fallback `GET /api/agents/:agentId/browser/session` route that returns `{ hasSession: false, screencastAvailable: false }`. This lets clients detect that screencast won't work and skip the WebSocket upgrade instead of triggering a noisy reconnect loop. ([#16668](https://github.com/mastra-ai/mastra/pull/16668))
74
+
75
+ - Bumped the `@mastra/core` peer dependency floor from `>=1.32.0-0` to `>=1.34.0-0`. ([#16666](https://github.com/mastra-ai/mastra/pull/16666))
76
+
77
+ - Updated dependencies [[`5ba7253`](https://github.com/mastra-ai/mastra/commit/5ba7253745c85e8df8012a76d954c640ffa336f7), [`f73980d`](https://github.com/mastra-ai/mastra/commit/f73980d651eb5f7f1ab20582de4615a1b6f10fce), [`f73980d`](https://github.com/mastra-ai/mastra/commit/f73980d651eb5f7f1ab20582de4615a1b6f10fce), [`9c88701`](https://github.com/mastra-ai/mastra/commit/9c8870195b41a38dc40b6ba2aa55eda04df8fa69), [`f73980d`](https://github.com/mastra-ai/mastra/commit/f73980d651eb5f7f1ab20582de4615a1b6f10fce), [`9c88701`](https://github.com/mastra-ai/mastra/commit/9c8870195b41a38dc40b6ba2aa55eda04df8fa69), [`9c88701`](https://github.com/mastra-ai/mastra/commit/9c8870195b41a38dc40b6ba2aa55eda04df8fa69), [`9c88701`](https://github.com/mastra-ai/mastra/commit/9c8870195b41a38dc40b6ba2aa55eda04df8fa69), [`4e88dc6`](https://github.com/mastra-ai/mastra/commit/4e88dc6b89f154c0eae37221c8126be0c23c569f), [`19018f0`](https://github.com/mastra-ai/mastra/commit/19018f05722af74a5978781a7731a654b26f7f2a), [`5ba7253`](https://github.com/mastra-ai/mastra/commit/5ba7253745c85e8df8012a76d954c640ffa336f7)]:
78
+ - @mastra/core@1.36.0-alpha.2
79
+ - @mastra/server@1.36.0-alpha.2
80
+
81
+ ## 1.36.0-alpha.1
82
+
83
+ ### Minor Changes
84
+
85
+ - Added route-specific CORS configuration so credentialed cross-origin access can be limited to selected custom routes and channel webhooks. ([#16689](https://github.com/mastra-ai/mastra/pull/16689))
86
+
87
+ ```ts
88
+ registerApiRoute('/customer-webhook', {
89
+ method: 'POST',
90
+ cors: {
91
+ origin: ['https://customer-saas.example'],
92
+ credentials: true,
93
+ },
94
+ handler: async c => c.json({ ok: true }),
95
+ });
96
+ ```
97
+
98
+ ```ts
99
+ new Agent({
100
+ id: 'support-agent',
101
+ name: 'Support Agent',
102
+ instructions: '...',
103
+ model,
104
+ channels: {
105
+ adapters: {
106
+ web: {
107
+ adapter: createWebAdapter(),
108
+ cors: {
109
+ origin: ['https://customer-saas.example'],
110
+ credentials: true,
111
+ },
112
+ },
113
+ },
114
+ },
115
+ });
116
+ ```
117
+
118
+ Use `server.cors` for one global CORS policy across the server:
119
+
120
+ ```ts
121
+ new Mastra({
122
+ server: {
123
+ cors: {
124
+ origin: '*',
125
+ },
126
+ },
127
+ });
128
+ ```
129
+
130
+ ### Patch Changes
131
+
132
+ - Updated dependencies [[`8cdb86c`](https://github.com/mastra-ai/mastra/commit/8cdb86ceed1137bc2768e147dce85a0692b9fb26), [`eda90c5`](https://github.com/mastra-ai/mastra/commit/eda90c5bfd7de11805ecc9f4552716c895fbaf78), [`afc004f`](https://github.com/mastra-ai/mastra/commit/afc004f5cc7e30697809e7021820b9f5881e6719), [`408be73`](https://github.com/mastra-ai/mastra/commit/408be73449dfab92b51eab8c6623b6c443debc25)]:
133
+ - @mastra/core@1.36.0-alpha.1
134
+ - @mastra/server@1.36.0-alpha.1
135
+
3
136
  ## 1.36.0-alpha.0
4
137
 
5
138
  ### Patch Changes
@@ -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.36.0-alpha.0"
6
+ version: "1.36.0-alpha.10"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.36.0-alpha.0",
2
+ "version": "1.36.0-alpha.10",
3
3
  "package": "@mastra/deployer",
4
4
  "exports": {
5
5
  "Deps": {
@@ -17,6 +17,7 @@ var tools = require('@mastra/core/tools');
17
17
  var serverAdapter = require('@mastra/server/server-adapter');
18
18
  var util = require('util');
19
19
  var buffer = require('buffer');
20
+ var auth = require('@mastra/server/auth');
20
21
  var browserStream = require('@mastra/server/browser-stream');
21
22
  var store = require('@mastra/server/a2a/store');
22
23
  var hono = require('hono');
@@ -3183,6 +3184,9 @@ async function setupBrowserStream(app, config2) {
3183
3184
  }
3184
3185
  const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({ app });
3185
3186
  const registry2 = new browserStream.ViewerRegistry();
3187
+ const rawPrefix = config2.apiPrefix ?? "/api";
3188
+ const trimmed = rawPrefix.endsWith("/") ? rawPrefix.slice(0, -1) : rawPrefix;
3189
+ const apiPrefix = trimmed || "/api";
3186
3190
  app.get(
3187
3191
  "/browser/:agentId/stream",
3188
3192
  upgradeWebSocket((c) => {
@@ -3197,7 +3201,7 @@ async function setupBrowserStream(app, config2) {
3197
3201
  onMessage(event, _ws) {
3198
3202
  const data = typeof event.data === "string" ? event.data : null;
3199
3203
  if (data) {
3200
- browserStream.handleInputMessage(data, config2.getToolset, agentId, threadId);
3204
+ void browserStream.handleInputMessage(data, config2.getToolset, agentId, threadId);
3201
3205
  }
3202
3206
  },
3203
3207
  onClose(_event, ws) {
@@ -3210,12 +3214,25 @@ async function setupBrowserStream(app, config2) {
3210
3214
  };
3211
3215
  })
3212
3216
  );
3213
- app.post("/api/agents/:agentId/browser/close", async (c) => {
3217
+ app.get(`${apiPrefix}/agents/:agentId/browser/session`, async (c) => {
3214
3218
  const agentId = c.req.param("agentId");
3215
3219
  if (!agentId) {
3216
3220
  return c.json({ error: "Agent ID is required" }, 400);
3217
3221
  }
3218
- const toolset = config2.getToolset(agentId);
3222
+ const threadId = c.req.query("threadId");
3223
+ const toolset = await config2.getToolset(agentId);
3224
+ if (!toolset) {
3225
+ return c.json({ hasSession: false, screencastAvailable: true });
3226
+ }
3227
+ const hasSession = threadId ? toolset.hasThreadSession(threadId) : false;
3228
+ return c.json({ hasSession, screencastAvailable: true });
3229
+ });
3230
+ app.post(`${apiPrefix}/agents/:agentId/browser/close`, async (c) => {
3231
+ const agentId = c.req.param("agentId");
3232
+ if (!agentId) {
3233
+ return c.json({ error: "Agent ID is required" }, 400);
3234
+ }
3235
+ const toolset = await config2.getToolset(agentId);
3219
3236
  if (!toolset) {
3220
3237
  return c.json({ error: "No browser session for this agent" }, 404);
3221
3238
  }
@@ -3616,7 +3633,7 @@ var MastraServer = class extends serverAdapter.MastraServer {
3616
3633
  if (authConfig) {
3617
3634
  const hasPermission = await loadHasPermission();
3618
3635
  if (hasPermission) {
3619
- const userPermissions = c.get("requestContext").get("userPermissions");
3636
+ const userPermissions = c.get("requestContext").get("mastra__userPermissions");
3620
3637
  const permissionError = this.checkRoutePermission(route, userPermissions, hasPermission);
3621
3638
  if (permissionError) {
3622
3639
  return c.json(
@@ -3713,7 +3730,7 @@ var MastraServer = class extends serverAdapter.MastraServer {
3713
3730
  if (authConfig) {
3714
3731
  const hasPermission = await loadHasPermission();
3715
3732
  if (hasPermission) {
3716
- const userPermissions = c.get("requestContext").get("userPermissions");
3733
+ const userPermissions = c.get("requestContext").get("mastra__userPermissions");
3717
3734
  const permissionError = this.checkRoutePermission(serverRoute, userPermissions, hasPermission);
3718
3735
  if (permissionError) {
3719
3736
  return c.json(
@@ -4447,6 +4464,27 @@ var getStudioPath = () => {
4447
4464
  const studioPath = process.env.MASTRA_STUDIO_PATH || path.join(__dirname, "studio");
4448
4465
  return studioPath;
4449
4466
  };
4467
+ var DEFAULT_CORS_ALLOW_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"];
4468
+ var DEFAULT_CORS_ALLOW_HEADERS = ["Content-Type", "Authorization", "x-mastra-client-type", "x-mastra-dev-playground"];
4469
+ var DEFAULT_CORS_EXPOSE_HEADERS = ["Content-Length", "X-Requested-With"];
4470
+ function getCorsConfig(serverCors, credentialsDefault) {
4471
+ const userCors = serverCors && typeof serverCors === "object" ? serverCors : void 0;
4472
+ const origin = userCors && "origin" in userCors && userCors.origin ? userCors.origin : credentialsDefault ? (requestOrigin) => requestOrigin || void 0 : "*";
4473
+ const credentials = userCors && "credentials" in userCors ? userCors.credentials : credentialsDefault;
4474
+ return {
4475
+ origin,
4476
+ allowMethods: DEFAULT_CORS_ALLOW_METHODS,
4477
+ credentials,
4478
+ maxAge: 3600,
4479
+ ...userCors,
4480
+ allowHeaders: [...DEFAULT_CORS_ALLOW_HEADERS, ...userCors?.allowHeaders ?? []],
4481
+ exposeHeaders: [...DEFAULT_CORS_EXPOSE_HEADERS, ...userCors?.exposeHeaders ?? []]
4482
+ };
4483
+ }
4484
+ function getRouteCorsConfig(apiRoutes, pathname, method) {
4485
+ const route = auth.findMatchingCustomRoute(pathname, method, apiRoutes)?.route;
4486
+ return route?.cors;
4487
+ }
4450
4488
  function getToolExports(tools$1) {
4451
4489
  try {
4452
4490
  return tools$1.reduce((acc, toolModule) => {
@@ -4530,40 +4568,39 @@ async function createHonoServer(mastra, options = {
4530
4568
  }
4531
4569
  }
4532
4570
  const browserStreamSetup = await setupBrowserStream(app, {
4533
- getToolset: (agentId) => {
4534
- const agent = mastra.getAgentById(agentId);
4535
- return agent?.browser;
4536
- }
4571
+ getToolset: async (agentId) => {
4572
+ try {
4573
+ const runtimeAgent = mastra.getAgentById(agentId);
4574
+ if (runtimeAgent) {
4575
+ return runtimeAgent.browser;
4576
+ }
4577
+ } catch {
4578
+ }
4579
+ try {
4580
+ const storedAgent = await mastra.getEditor?.()?.agent.getById(agentId);
4581
+ return storedAgent?.browser;
4582
+ } catch {
4583
+ return void 0;
4584
+ }
4585
+ },
4586
+ apiPrefix
4537
4587
  });
4588
+ if (!browserStreamSetup) {
4589
+ app.get(
4590
+ `${apiPrefix}/agents/:agentId/browser/session`,
4591
+ (c) => c.json({ hasSession: false, screencastAvailable: false })
4592
+ );
4593
+ }
4538
4594
  if (server?.cors === false) {
4539
4595
  app.use("*", timeout.timeout(server?.timeout ?? 3 * 60 * 1e3));
4540
4596
  } else {
4541
4597
  const hasAuth = !!server?.auth;
4542
- let corsOrigin;
4543
- if (server?.cors && typeof server.cors === "object" && "origin" in server.cors && server.cors.origin) {
4544
- corsOrigin = server.cors.origin;
4545
- } else if (hasAuth) {
4546
- corsOrigin = (origin) => origin || void 0;
4547
- } else {
4548
- corsOrigin = "*";
4549
- }
4550
- const corsConfig = {
4551
- origin: corsOrigin,
4552
- allowMethods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
4553
- // Enable credentials for cookie-based auth (e.g., Better Auth sessions)
4554
- credentials: hasAuth ? true : false,
4555
- maxAge: 3600,
4556
- ...server?.cors,
4557
- allowHeaders: [
4558
- "Content-Type",
4559
- "Authorization",
4560
- "x-mastra-client-type",
4561
- "x-mastra-dev-playground",
4562
- ...server?.cors?.allowHeaders ?? []
4563
- ],
4564
- exposeHeaders: ["Content-Length", "X-Requested-With", ...server?.cors?.exposeHeaders ?? []]
4565
- };
4566
- app.use("*", timeout.timeout(server?.timeout ?? 3 * 60 * 1e3), cors.cors(corsConfig));
4598
+ app.use("*", timeout.timeout(server?.timeout ?? 3 * 60 * 1e3), async (c, next) => {
4599
+ const pathname = new URL(c.req.url).pathname;
4600
+ const method = c.req.method === "OPTIONS" ? c.req.header("Access-Control-Request-Method") ?? c.req.method : c.req.method;
4601
+ const routeCors = getRouteCorsConfig(processedRoutes, pathname, method);
4602
+ return cors.cors(routeCors ? getCorsConfig(routeCors, false) : getCorsConfig(server?.cors, hasAuth))(c, next);
4603
+ });
4567
4604
  }
4568
4605
  app.get(
4569
4606
  "/health",