@mastra/deployer 1.22.0-alpha.1 → 1.22.0-alpha.3

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,25 @@
1
1
  # @mastra/deployer
2
2
 
3
+ ## 1.22.0-alpha.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`d87e6e6`](https://github.com/mastra-ai/mastra/commit/d87e6e61c42475a7b57768e71dfa12964326a632)]:
8
+ - @mastra/server@1.22.0-alpha.3
9
+ - @mastra/core@1.22.0-alpha.3
10
+
11
+ ## 1.22.0-alpha.2
12
+
13
+ ### Patch Changes
14
+
15
+ - Wire up browser streaming WebSocket support in deployed servers ([#14938](https://github.com/mastra-ai/mastra/pull/14938))
16
+
17
+ Browser streaming is now automatically available when an agent has a browser configured.
18
+
19
+ - Updated dependencies [[`cb15509`](https://github.com/mastra-ai/mastra/commit/cb15509b58f6a83e11b765c945082afc027db972), [`cb15509`](https://github.com/mastra-ai/mastra/commit/cb15509b58f6a83e11b765c945082afc027db972), [`80c5668`](https://github.com/mastra-ai/mastra/commit/80c5668e365470d3a96d3e953868fd7a643ff67c), [`3d478c1`](https://github.com/mastra-ai/mastra/commit/3d478c1e13f17b80f330ac49d7aa42ef929b93ff), [`f03f37a`](https://github.com/mastra-ai/mastra/commit/f03f37a5e5880f2bb2700514405e311f840c53d2), [`eecd0eb`](https://github.com/mastra-ai/mastra/commit/eecd0ebde7b54bbfe32e7ebbf5fe2c59b29dd685), [`6039f17`](https://github.com/mastra-ai/mastra/commit/6039f176f9c457304825ff1df8c83b8e457376c0), [`06b928d`](https://github.com/mastra-ai/mastra/commit/06b928dfc2f5630d023467476cc5919dfa858d0a), [`6a8d984`](https://github.com/mastra-ai/mastra/commit/6a8d9841f2933456ee1598099f488d742b600054)]:
20
+ - @mastra/core@1.22.0-alpha.2
21
+ - @mastra/server@1.22.0-alpha.2
22
+
3
23
  ## 1.22.0-alpha.1
4
24
 
5
25
  ### 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.22.0-alpha.1"
6
+ version: "1.22.0-alpha.3"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.22.0-alpha.1",
2
+ "version": "1.22.0-alpha.3",
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 browserStream = require('@mastra/server/browser-stream');
20
21
  var store = require('@mastra/server/a2a/store');
21
22
  var hono = require('hono');
22
23
  var compress = require('hono/compress');
@@ -3116,6 +3117,83 @@ var initializer2 = (inst, issues) => {
3116
3117
  });
3117
3118
  };
3118
3119
  var ZodError = /* @__PURE__ */ $constructor("ZodError", initializer2);
3120
+ async function setupBrowserStream(app, config2) {
3121
+ let createNodeWebSocket;
3122
+ try {
3123
+ const mod = "@hono/node-ws";
3124
+ const honoNodeWs = await import(
3125
+ /* @vite-ignore */
3126
+ /* webpackIgnore: true */
3127
+ mod
3128
+ );
3129
+ createNodeWebSocket = honoNodeWs.createNodeWebSocket;
3130
+ } catch {
3131
+ return null;
3132
+ }
3133
+ const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({ app });
3134
+ const registry2 = new browserStream.ViewerRegistry();
3135
+ app.get(
3136
+ "/browser/:agentId/stream",
3137
+ upgradeWebSocket((c) => {
3138
+ const agentId = c.req.param("agentId");
3139
+ const threadId = c.req.query("threadId");
3140
+ const viewerKey = threadId ? `${agentId}:${threadId}` : agentId;
3141
+ return {
3142
+ onOpen(_event, ws) {
3143
+ ws.send(JSON.stringify({ status: "connected" }));
3144
+ void registry2.addViewer(viewerKey, ws, config2.getToolset, agentId, threadId);
3145
+ },
3146
+ onMessage(event, _ws) {
3147
+ const data = typeof event.data === "string" ? event.data : null;
3148
+ if (data) {
3149
+ browserStream.handleInputMessage(data, config2.getToolset, agentId, threadId);
3150
+ }
3151
+ },
3152
+ onClose(_event, ws) {
3153
+ void registry2.removeViewer(viewerKey, ws);
3154
+ },
3155
+ onError(event, ws) {
3156
+ console.error("[BrowserStream] WebSocket error:", event);
3157
+ void registry2.removeViewer(viewerKey, ws);
3158
+ }
3159
+ };
3160
+ })
3161
+ );
3162
+ app.post("/api/agents/:agentId/browser/close", async (c) => {
3163
+ const agentId = c.req.param("agentId");
3164
+ if (!agentId) {
3165
+ return c.json({ error: "Agent ID is required" }, 400);
3166
+ }
3167
+ const toolset = config2.getToolset(agentId);
3168
+ if (!toolset) {
3169
+ return c.json({ error: "No browser session for this agent" }, 404);
3170
+ }
3171
+ try {
3172
+ let threadId;
3173
+ try {
3174
+ const body = await c.req.json();
3175
+ threadId = body?.threadId;
3176
+ } catch {
3177
+ }
3178
+ const scope = toolset.getScope();
3179
+ const viewerKey = threadId ? `${agentId}:${threadId}` : agentId;
3180
+ if (scope === "thread" && threadId) {
3181
+ await registry2.closeBrowserSession(viewerKey);
3182
+ if ("closeThreadSession" in toolset && typeof toolset.closeThreadSession === "function") {
3183
+ await toolset.closeThreadSession(threadId);
3184
+ }
3185
+ } else {
3186
+ await registry2.closeBrowserSession(viewerKey);
3187
+ await toolset.close();
3188
+ }
3189
+ return c.json({ success: true });
3190
+ } catch (error) {
3191
+ console.error(`[BrowserStream] Error closing browser for ${agentId}:`, error);
3192
+ return c.json({ error: "Failed to close browser" }, 500);
3193
+ }
3194
+ });
3195
+ return { injectWebSocket, registry: registry2 };
3196
+ }
3119
3197
  var _hasPermissionPromise;
3120
3198
  function loadHasPermission() {
3121
3199
  if (!_hasPermissionPromise) {
@@ -4021,6 +4099,12 @@ async function createHonoServer(mastra, options = {
4021
4099
  app.use(m.path, m.handler);
4022
4100
  }
4023
4101
  }
4102
+ const browserStreamSetup = await setupBrowserStream(app, {
4103
+ getToolset: (agentId) => {
4104
+ const agent = mastra.getAgentById(agentId);
4105
+ return agent?.browser;
4106
+ }
4107
+ });
4024
4108
  if (server?.cors === false) {
4025
4109
  app.use("*", timeout.timeout(server?.timeout ?? 3 * 60 * 1e3));
4026
4110
  } else {
@@ -4239,10 +4323,12 @@ async function createHonoServer(mastra, options = {
4239
4323
  })
4240
4324
  );
4241
4325
  }
4326
+ app.injectWebSocket = browserStreamSetup?.injectWebSocket;
4242
4327
  return app;
4243
4328
  }
4244
4329
  async function createNodeServer(mastra, options = { tools: {} }) {
4245
4330
  const app = await createHonoServer(mastra, options);
4331
+ const injectWebSocket = app.injectWebSocket;
4246
4332
  const serverOptions = mastra.getServer();
4247
4333
  const apiPrefix = serverOptions?.apiPrefix ?? "/api";
4248
4334
  const key = serverOptions?.https?.key ?? (process.env.MASTRA_HTTPS_KEY ? Buffer.from(process.env.MASTRA_HTTPS_KEY, "base64") : void 0);
@@ -4285,6 +4371,7 @@ async function createNodeServer(mastra, options = { tools: {} }) {
4285
4371
  }
4286
4372
  }
4287
4373
  );
4374
+ injectWebSocket?.(server);
4288
4375
  await mastra.startEventEngine();
4289
4376
  return server;
4290
4377
  }