@mastra/deployer 1.36.0-alpha.1 → 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.
@@ -3184,6 +3184,9 @@ async function setupBrowserStream(app, config2) {
3184
3184
  }
3185
3185
  const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({ app });
3186
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";
3187
3190
  app.get(
3188
3191
  "/browser/:agentId/stream",
3189
3192
  upgradeWebSocket((c) => {
@@ -3198,7 +3201,7 @@ async function setupBrowserStream(app, config2) {
3198
3201
  onMessage(event, _ws) {
3199
3202
  const data = typeof event.data === "string" ? event.data : null;
3200
3203
  if (data) {
3201
- browserStream.handleInputMessage(data, config2.getToolset, agentId, threadId);
3204
+ void browserStream.handleInputMessage(data, config2.getToolset, agentId, threadId);
3202
3205
  }
3203
3206
  },
3204
3207
  onClose(_event, ws) {
@@ -3211,12 +3214,25 @@ async function setupBrowserStream(app, config2) {
3211
3214
  };
3212
3215
  })
3213
3216
  );
3214
- app.post("/api/agents/:agentId/browser/close", async (c) => {
3217
+ app.get(`${apiPrefix}/agents/:agentId/browser/session`, async (c) => {
3215
3218
  const agentId = c.req.param("agentId");
3216
3219
  if (!agentId) {
3217
3220
  return c.json({ error: "Agent ID is required" }, 400);
3218
3221
  }
3219
- 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);
3220
3236
  if (!toolset) {
3221
3237
  return c.json({ error: "No browser session for this agent" }, 404);
3222
3238
  }
@@ -3617,7 +3633,7 @@ var MastraServer = class extends serverAdapter.MastraServer {
3617
3633
  if (authConfig) {
3618
3634
  const hasPermission = await loadHasPermission();
3619
3635
  if (hasPermission) {
3620
- const userPermissions = c.get("requestContext").get("userPermissions");
3636
+ const userPermissions = c.get("requestContext").get("mastra__userPermissions");
3621
3637
  const permissionError = this.checkRoutePermission(route, userPermissions, hasPermission);
3622
3638
  if (permissionError) {
3623
3639
  return c.json(
@@ -3714,7 +3730,7 @@ var MastraServer = class extends serverAdapter.MastraServer {
3714
3730
  if (authConfig) {
3715
3731
  const hasPermission = await loadHasPermission();
3716
3732
  if (hasPermission) {
3717
- const userPermissions = c.get("requestContext").get("userPermissions");
3733
+ const userPermissions = c.get("requestContext").get("mastra__userPermissions");
3718
3734
  const permissionError = this.checkRoutePermission(serverRoute, userPermissions, hasPermission);
3719
3735
  if (permissionError) {
3720
3736
  return c.json(
@@ -4552,11 +4568,29 @@ async function createHonoServer(mastra, options = {
4552
4568
  }
4553
4569
  }
4554
4570
  const browserStreamSetup = await setupBrowserStream(app, {
4555
- getToolset: (agentId) => {
4556
- const agent = mastra.getAgentById(agentId);
4557
- return agent?.browser;
4558
- }
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
4559
4587
  });
4588
+ if (!browserStreamSetup) {
4589
+ app.get(
4590
+ `${apiPrefix}/agents/:agentId/browser/session`,
4591
+ (c) => c.json({ hasSession: false, screencastAvailable: false })
4592
+ );
4593
+ }
4560
4594
  if (server?.cors === false) {
4561
4595
  app.use("*", timeout.timeout(server?.timeout ?? 3 * 60 * 1e3));
4562
4596
  } else {