@mastra/deployer 1.61.0-alpha.1 → 1.61.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 +20 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/server/handlers/client.d.ts +7 -0
- package/dist/server/handlers/client.d.ts.map +1 -1
- package/dist/server/index.cjs +58 -20
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +58 -20
- package/dist/server/index.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAIlD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAIhE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAmB5B,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;AA8CF,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;2CAsahE;AAED,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAmC,mDAsKlG"}
|
package/dist/server/index.js
CHANGED
|
@@ -3763,6 +3763,20 @@ function handleClientsRefresh(c) {
|
|
|
3763
3763
|
"Access-Control-Allow-Origin": "*"
|
|
3764
3764
|
} });
|
|
3765
3765
|
}
|
|
3766
|
+
/**
|
|
3767
|
+
* End every open refresh SSE stream. Studio keeps one of these connections
|
|
3768
|
+
* open for its whole lifetime, so without this the graceful-shutdown drain
|
|
3769
|
+
* would wait on them until the drain deadline (stalling `mastra dev` hot
|
|
3770
|
+
* reloads while Studio is open).
|
|
3771
|
+
*/
|
|
3772
|
+
function closeRefreshStreams() {
|
|
3773
|
+
clients.forEach((controller) => {
|
|
3774
|
+
try {
|
|
3775
|
+
controller.close();
|
|
3776
|
+
} catch {}
|
|
3777
|
+
});
|
|
3778
|
+
clients.clear();
|
|
3779
|
+
}
|
|
3766
3780
|
function handleTriggerClientsRefresh(c) {
|
|
3767
3781
|
clients.forEach((controller) => {
|
|
3768
3782
|
try {
|
|
@@ -4628,6 +4642,8 @@ async function createNodeServer(mastra, options = { tools: {} }) {
|
|
|
4628
4642
|
const injectWebSocket = app.injectWebSocket;
|
|
4629
4643
|
const serverOptions = mastra.getServer();
|
|
4630
4644
|
const apiPrefix = serverOptions?.apiPrefix ?? "/api";
|
|
4645
|
+
const drainTimeoutMs = serverOptions?.drainTimeout ?? 5e3;
|
|
4646
|
+
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");
|
|
4631
4647
|
const key = serverOptions?.https?.key ?? (process.env.MASTRA_HTTPS_KEY ? Buffer.from(process.env.MASTRA_HTTPS_KEY, "base64") : void 0);
|
|
4632
4648
|
const cert = serverOptions?.https?.cert ?? (process.env.MASTRA_HTTPS_CERT ? Buffer.from(process.env.MASTRA_HTTPS_CERT, "base64") : void 0);
|
|
4633
4649
|
const isHttpsEnabled = Boolean(key && cert);
|
|
@@ -4669,33 +4685,55 @@ async function createNodeServer(mastra, options = { tools: {} }) {
|
|
|
4669
4685
|
else await workerLifecycle.startEventEngine();
|
|
4670
4686
|
import("@mastra/core/telemetry").then(({ syncUsageTelemetry }) => syncUsageTelemetry(mastra)).catch(() => {});
|
|
4671
4687
|
import("@mastra/core/telemetry").then(({ syncFeatureUsageTelemetry }) => syncFeatureUsageTelemetry(mastra)).catch(() => {});
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
shuttingDown = true;
|
|
4677
|
-
const logger = mastra.getLogger();
|
|
4678
|
-
logger.info("Shutting down Mastra server", { signal });
|
|
4679
|
-
server.close();
|
|
4680
|
-
const lifecycle = mastra;
|
|
4681
|
-
if (typeof lifecycle.shutdown === "function") {
|
|
4688
|
+
if (serverOptions?.handleShutdownSignals !== false) {
|
|
4689
|
+
const CORE_SHUTDOWN_TIMEOUT_MS = 5e3;
|
|
4690
|
+
const timedOut = Symbol("shutdown-timeout");
|
|
4691
|
+
const race = async (work, ms) => {
|
|
4682
4692
|
let timeout;
|
|
4683
|
-
const timedOut = Symbol("shutdown-timeout");
|
|
4684
4693
|
const timeoutPromise = new Promise((resolve) => {
|
|
4685
|
-
timeout = setTimeout(() => resolve(timedOut),
|
|
4694
|
+
timeout = setTimeout(() => resolve(timedOut), ms);
|
|
4686
4695
|
});
|
|
4687
4696
|
try {
|
|
4688
|
-
|
|
4689
|
-
} catch (error) {
|
|
4690
|
-
logger.error("Error during Mastra shutdown", { error });
|
|
4697
|
+
return await Promise.race([work, timeoutPromise]);
|
|
4691
4698
|
} finally {
|
|
4692
4699
|
clearTimeout(timeout);
|
|
4693
4700
|
}
|
|
4694
|
-
}
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
|
|
4698
|
-
|
|
4701
|
+
};
|
|
4702
|
+
let shuttingDown = false;
|
|
4703
|
+
const shutdown = async (signal) => {
|
|
4704
|
+
if (shuttingDown) {
|
|
4705
|
+
process.exit(1);
|
|
4706
|
+
return;
|
|
4707
|
+
}
|
|
4708
|
+
shuttingDown = true;
|
|
4709
|
+
const logger = mastra.getLogger();
|
|
4710
|
+
logger.info("Shutting down Mastra server", { signal });
|
|
4711
|
+
try {
|
|
4712
|
+
const drained = new Promise((resolve) => {
|
|
4713
|
+
server.close(() => resolve());
|
|
4714
|
+
});
|
|
4715
|
+
closeRefreshStreams();
|
|
4716
|
+
server.closeIdleConnections?.();
|
|
4717
|
+
if (await race(drained, drainTimeoutMs) === timedOut) {
|
|
4718
|
+
logger.warn("Mastra server drain timed out; closing remaining HTTP connections", { timeoutMs: drainTimeoutMs });
|
|
4719
|
+
server.closeAllConnections?.();
|
|
4720
|
+
}
|
|
4721
|
+
} catch (error) {
|
|
4722
|
+
logger.error("Error while draining Mastra server", { error });
|
|
4723
|
+
}
|
|
4724
|
+
try {
|
|
4725
|
+
const lifecycle = mastra;
|
|
4726
|
+
if (typeof lifecycle.shutdown === "function") {
|
|
4727
|
+
if (await race(lifecycle.shutdown(), CORE_SHUTDOWN_TIMEOUT_MS) === timedOut) logger.warn("Mastra shutdown timed out; forcing exit", { timeoutMs: CORE_SHUTDOWN_TIMEOUT_MS });
|
|
4728
|
+
}
|
|
4729
|
+
} catch (error) {
|
|
4730
|
+
logger.error("Error during Mastra shutdown", { error });
|
|
4731
|
+
}
|
|
4732
|
+
process.exit(0);
|
|
4733
|
+
};
|
|
4734
|
+
process.on("SIGINT", () => void shutdown("SIGINT"));
|
|
4735
|
+
process.on("SIGTERM", () => void shutdown("SIGTERM"));
|
|
4736
|
+
}
|
|
4699
4737
|
return server;
|
|
4700
4738
|
}
|
|
4701
4739
|
//#endregion
|