@mastra/deployer 1.61.0-alpha.2 → 1.61.0-alpha.4

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 (40) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/{analyze-skTsj9Fh.js → analyze-BoU8nN8Q.js} +2 -2
  3. package/dist/{analyze-skTsj9Fh.js.map → analyze-BoU8nN8Q.js.map} +1 -1
  4. package/dist/{analyze-D2KHXb6M.cjs → analyze-CMkpXdKQ.cjs} +2 -2
  5. package/dist/{analyze-D2KHXb6M.cjs.map → analyze-CMkpXdKQ.cjs.map} +1 -1
  6. package/dist/build/analyze.cjs +1 -1
  7. package/dist/build/analyze.js +1 -1
  8. package/dist/build/bundler.cjs +1 -1
  9. package/dist/build/bundler.js +1 -1
  10. package/dist/build/index.cjs +4 -4
  11. package/dist/build/index.js +4 -4
  12. package/dist/build/plugins/node-modules-extension-resolver.d.ts.map +1 -1
  13. package/dist/{build-Hzj7Fw8y.cjs → build-D1AcigJC.cjs} +4 -4
  14. package/dist/{build-Hzj7Fw8y.cjs.map → build-D1AcigJC.cjs.map} +1 -1
  15. package/dist/{build-D3kI9XB6.js → build-DyfOm0B6.js} +4 -4
  16. package/dist/{build-D3kI9XB6.js.map → build-DyfOm0B6.js.map} +1 -1
  17. package/dist/bundler/index.cjs +3 -3
  18. package/dist/bundler/index.js +3 -3
  19. package/dist/{bundler-CsE58j6k.js → bundler-CFQXmlz4.js} +2 -2
  20. package/dist/bundler-CFQXmlz4.js.map +1 -0
  21. package/dist/{bundler-CsD_DAiK.cjs → bundler-EFi87w8T.cjs} +2 -2
  22. package/dist/bundler-EFi87w8T.cjs.map +1 -0
  23. package/dist/{bundlerOptions-Bmxf9Z0E.js → bundlerOptions-CTvtXjv7.js} +2 -2
  24. package/dist/{bundlerOptions-Bmxf9Z0E.js.map → bundlerOptions-CTvtXjv7.js.map} +1 -1
  25. package/dist/{bundlerOptions-lPcUQJFc.cjs → bundlerOptions-Dcnmsdiv.cjs} +2 -2
  26. package/dist/{bundlerOptions-lPcUQJFc.cjs.map → bundlerOptions-Dcnmsdiv.cjs.map} +1 -1
  27. package/dist/docs/SKILL.md +1 -1
  28. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  29. package/dist/index.cjs +2 -2
  30. package/dist/index.js +2 -2
  31. package/dist/server/handlers/client.d.ts +7 -0
  32. package/dist/server/handlers/client.d.ts.map +1 -1
  33. package/dist/server/index.cjs +65 -20
  34. package/dist/server/index.cjs.map +1 -1
  35. package/dist/server/index.d.ts.map +1 -1
  36. package/dist/server/index.js +65 -20
  37. package/dist/server/index.js.map +1 -1
  38. package/package.json +7 -7
  39. package/dist/bundler-CsD_DAiK.cjs.map +0 -1
  40. package/dist/bundler-CsE58j6k.js.map +0 -1
@@ -3768,6 +3768,20 @@ function handleClientsRefresh(c) {
3768
3768
  "Access-Control-Allow-Origin": "*"
3769
3769
  } });
3770
3770
  }
3771
+ /**
3772
+ * End every open refresh SSE stream. Studio keeps one of these connections
3773
+ * open for its whole lifetime, so without this the graceful-shutdown drain
3774
+ * would wait on them until the drain deadline (stalling `mastra dev` hot
3775
+ * reloads while Studio is open).
3776
+ */
3777
+ function closeRefreshStreams() {
3778
+ clients.forEach((controller) => {
3779
+ try {
3780
+ controller.close();
3781
+ } catch {}
3782
+ });
3783
+ clients.clear();
3784
+ }
3771
3785
  function handleTriggerClientsRefresh(c) {
3772
3786
  clients.forEach((controller) => {
3773
3787
  try {
@@ -4633,6 +4647,8 @@ async function createNodeServer(mastra, options = { tools: {} }) {
4633
4647
  const injectWebSocket = app.injectWebSocket;
4634
4648
  const serverOptions = mastra.getServer();
4635
4649
  const apiPrefix = serverOptions?.apiPrefix ?? "/api";
4650
+ const drainTimeoutMs = serverOptions?.drainTimeout ?? 5e3;
4651
+ if (serverOptions?.handleShutdownSignals !== false && (!Number.isFinite(drainTimeoutMs) || drainTimeoutMs < 0 || drainTimeoutMs > 2147483647)) throw new RangeError("server.drainTimeout must be a finite number between 0 and 2147483647 milliseconds");
4636
4652
  const key = serverOptions?.https?.key ?? (process.env.MASTRA_HTTPS_KEY ? Buffer.from(process.env.MASTRA_HTTPS_KEY, "base64") : void 0);
4637
4653
  const cert = serverOptions?.https?.cert ?? (process.env.MASTRA_HTTPS_CERT ? Buffer.from(process.env.MASTRA_HTTPS_CERT, "base64") : void 0);
4638
4654
  const isHttpsEnabled = Boolean(key && cert);
@@ -4674,33 +4690,62 @@ async function createNodeServer(mastra, options = { tools: {} }) {
4674
4690
  else await workerLifecycle.startEventEngine();
4675
4691
  import("@mastra/core/telemetry").then(({ syncUsageTelemetry }) => syncUsageTelemetry(mastra)).catch(() => {});
4676
4692
  import("@mastra/core/telemetry").then(({ syncFeatureUsageTelemetry }) => syncFeatureUsageTelemetry(mastra)).catch(() => {});
4677
- const SHUTDOWN_TIMEOUT_MS = 5e3;
4678
- let shuttingDown = false;
4679
- const shutdown = async (signal) => {
4680
- if (shuttingDown) return;
4681
- shuttingDown = true;
4682
- const logger = mastra.getLogger();
4683
- logger.info("Shutting down Mastra server", { signal });
4684
- server.close();
4685
- const lifecycle = mastra;
4686
- if (typeof lifecycle.shutdown === "function") {
4693
+ if (serverOptions?.handleShutdownSignals !== false) {
4694
+ const CORE_SHUTDOWN_TIMEOUT_MS = 5e3;
4695
+ const timedOut = Symbol("shutdown-timeout");
4696
+ const race = async (work, ms) => {
4687
4697
  let timeout;
4688
- const timedOut = Symbol("shutdown-timeout");
4689
4698
  const timeoutPromise = new Promise((resolve) => {
4690
- timeout = setTimeout(() => resolve(timedOut), SHUTDOWN_TIMEOUT_MS);
4699
+ timeout = setTimeout(() => resolve(timedOut), ms);
4691
4700
  });
4692
4701
  try {
4693
- if (await Promise.race([lifecycle.shutdown(), timeoutPromise]) === timedOut) logger.warn("Mastra shutdown timed out; forcing exit", { timeoutMs: SHUTDOWN_TIMEOUT_MS });
4694
- } catch (error) {
4695
- logger.error("Error during Mastra shutdown", { error });
4702
+ return await Promise.race([work, timeoutPromise]);
4696
4703
  } finally {
4697
4704
  clearTimeout(timeout);
4698
4705
  }
4699
- }
4700
- process.exit(0);
4701
- };
4702
- process.once("SIGINT", () => void shutdown("SIGINT"));
4703
- process.once("SIGTERM", () => void shutdown("SIGTERM"));
4706
+ };
4707
+ let shuttingDown = false;
4708
+ const shutdown = async (signal) => {
4709
+ if (shuttingDown) {
4710
+ process.exit(1);
4711
+ return;
4712
+ }
4713
+ shuttingDown = true;
4714
+ const logger = mastra.getLogger();
4715
+ logger.info("Shutting down Mastra server", { signal });
4716
+ try {
4717
+ const drained = new Promise((resolve) => {
4718
+ server.close(() => resolve());
4719
+ });
4720
+ closeRefreshStreams();
4721
+ const closeIdleConnections = () => server.closeIdleConnections?.();
4722
+ closeIdleConnections();
4723
+ const idleSweep = setInterval(closeIdleConnections, 100);
4724
+ idleSweep.unref?.();
4725
+ try {
4726
+ if (await race(drained, drainTimeoutMs) === timedOut) {
4727
+ logger.warn("Mastra server drain timed out; closing remaining HTTP connections", { timeoutMs: drainTimeoutMs });
4728
+ server.closeAllConnections?.();
4729
+ }
4730
+ } finally {
4731
+ clearInterval(idleSweep);
4732
+ }
4733
+ } catch (error) {
4734
+ logger.error("Error while draining Mastra server", { error });
4735
+ }
4736
+ try {
4737
+ const lifecycle = mastra;
4738
+ if (typeof lifecycle.shutdown === "function") {
4739
+ if (await race(lifecycle.shutdown(), CORE_SHUTDOWN_TIMEOUT_MS) === timedOut) logger.warn("Mastra shutdown timed out; forcing exit", { timeoutMs: CORE_SHUTDOWN_TIMEOUT_MS });
4740
+ }
4741
+ } catch (error) {
4742
+ logger.error("Error during Mastra shutdown", { error });
4743
+ }
4744
+ process.exit(0);
4745
+ };
4746
+ process.on("SIGINT", () => void shutdown("SIGINT"));
4747
+ process.on("SIGTERM", () => void shutdown("SIGTERM"));
4748
+ }
4704
4749
  return server;
4705
4750
  }
4706
4751
  //#endregion