@mastra/deployer 1.79.0-alpha.1 → 1.79.0-alpha.11
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/dist/_types/@mastra_hono/dist/browser-stream/index.d.ts +54 -2
- package/dist/_types/@mastra_hono/dist/index.d.ts +1 -0
- package/dist/{analyze-CcyVW_jJ.cjs → analyze-Cb5JJp7Y.cjs} +178 -31
- package/dist/analyze-Cb5JJp7Y.cjs.map +1 -0
- package/dist/{analyze-BP0cLyWH.js → analyze-CbVhoukh.js} +175 -28
- package/dist/analyze-CbVhoukh.js.map +1 -0
- package/dist/{arktype-aI7TBD0R-DCxjN6oF.cjs → arktype-aI7TBD0R-BP9yJr5x.cjs} +2 -2
- package/dist/arktype-aI7TBD0R-BP9yJr5x.cjs.map +1 -0
- package/dist/{arktype-aI7TBD0R-BGjyzmsj.js → arktype-aI7TBD0R-cgd8o1cq.js} +2 -2
- package/dist/arktype-aI7TBD0R-cgd8o1cq.js.map +1 -0
- package/dist/build/analyze.cjs +1 -1
- package/dist/build/analyze.js +1 -2
- package/dist/build/bundler.cjs +1 -1
- package/dist/build/bundler.js +1 -2
- package/dist/build/fs-routing/discover.d.ts.map +1 -1
- package/dist/build/index.cjs +6 -6
- package/dist/build/index.js +5 -5
- package/dist/build/package-info.d.ts.map +1 -1
- package/dist/build/plugins/tsconfig-paths.d.ts +4 -3
- package/dist/build/plugins/tsconfig-paths.d.ts.map +1 -1
- package/dist/build/shared/extract-mastra-option.d.ts.map +1 -1
- package/dist/{build-DGJW5-aB.cjs → build-DGwrw0dD.cjs} +112 -50
- package/dist/build-DGwrw0dD.cjs.map +1 -0
- package/dist/{build-CNYwIKPG.js → build-qnakIZAs.js} +72 -9
- package/dist/build-qnakIZAs.js.map +1 -0
- package/dist/bundler/find-workspaces.d.ts +52 -0
- package/dist/bundler/find-workspaces.d.ts.map +1 -0
- package/dist/bundler/index.cjs +27 -19
- package/dist/bundler/index.cjs.map +1 -1
- package/dist/bundler/index.d.ts +1 -1
- package/dist/bundler/index.d.ts.map +1 -1
- package/dist/bundler/index.js +25 -17
- package/dist/bundler/index.js.map +1 -1
- package/dist/bundler/workspaceDependencies.d.ts.map +1 -1
- package/dist/{bundler-DtMHSv5_.js → bundler-BUqyRuGu.js} +78 -69
- package/dist/bundler-BUqyRuGu.js.map +1 -0
- package/dist/{bundler-CxslAqI_.cjs → bundler-Dpd5nkcu.cjs} +84 -76
- package/dist/bundler-Dpd5nkcu.cjs.map +1 -0
- package/dist/{bundlerOptions-BtMp_x-T.cjs → bundlerOptions-DHcbcD1a.cjs} +53 -3
- package/dist/bundlerOptions-DHcbcD1a.cjs.map +1 -0
- package/dist/{bundlerOptions-ID9i-l8I.js → bundlerOptions-DMxva0Sp.js} +50 -2
- package/dist/bundlerOptions-DMxva0Sp.js.map +1 -0
- package/dist/{core-D3wM1JKp.js → core-75DLMtZL.js} +23 -19
- package/dist/core-75DLMtZL.js.map +1 -0
- package/dist/{core-QL_X0T4Y.cjs → core-XnTfh3E_.cjs} +23 -19
- package/dist/core-XnTfh3E_.cjs.map +1 -0
- package/dist/dist-DYm9bBZO.js.map +1 -1
- package/dist/dist-twPJIvYf.cjs.map +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/{effect-QlVUlMFu-B2nZ842E.cjs → effect-QlVUlMFu-CC0Mpf1v.cjs} +3 -3
- package/dist/{effect-QlVUlMFu-B2nZ842E.cjs.map → effect-QlVUlMFu-CC0Mpf1v.cjs.map} +1 -1
- package/dist/{effect-QlVUlMFu-DbWuPaWV.js → effect-QlVUlMFu-Cvay38Oi.js} +3 -3
- package/dist/{effect-QlVUlMFu-DbWuPaWV.js.map → effect-QlVUlMFu-Cvay38Oi.js.map} +1 -1
- package/dist/{esm-D-wYOO-S.js → esm-ClsnEB2d.js} +111 -113
- package/dist/{esm-D-wYOO-S.js.map → esm-ClsnEB2d.js.map} +1 -1
- package/dist/{esm-Ai6osZ1a.cjs → esm-D74qc_jV.cjs} +111 -113
- package/dist/{esm-Ai6osZ1a.cjs.map → esm-D74qc_jV.cjs.map} +1 -1
- package/dist/{index-CLddUTqr-BXqo9et4.js → index-CLddUTqr-86A1rnBL.js} +8 -8
- package/dist/{index-CLddUTqr-BXqo9et4.js.map → index-CLddUTqr-86A1rnBL.js.map} +1 -1
- package/dist/{index-CLddUTqr-DsGkVS-W.cjs → index-CLddUTqr-D0GzVJyg.cjs} +8 -8
- package/dist/{index-CLddUTqr-DsGkVS-W.cjs.map → index-CLddUTqr-D0GzVJyg.cjs.map} +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.js +3 -3
- package/dist/{rolldown-runtime-emK7D4bc.cjs → rolldown-runtime-Gi87jfEt.cjs} +2 -2
- package/dist/server/index.cjs +338 -84
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +316 -62
- package/dist/server/index.js.map +1 -1
- package/dist/services/deps.d.ts +13 -1
- package/dist/services/deps.d.ts.map +1 -1
- package/dist/services/index.cjs +1 -1
- package/dist/services/index.js +1 -2
- package/dist/{services-DXqmEy8F.js → services-183Omg3U.js} +167 -31
- package/dist/services-183Omg3U.js.map +1 -0
- package/dist/{services-D_V7afWX.cjs → services-C1jM_6ta.cjs} +180 -31
- package/dist/services-C1jM_6ta.cjs.map +1 -0
- package/dist/{sury-CWZTCd75-ChXu4j-p.cjs → sury-CWZTCd75-TIJwZAOz.cjs} +3 -3
- package/dist/{sury-CWZTCd75-ChXu4j-p.cjs.map → sury-CWZTCd75-TIJwZAOz.cjs.map} +1 -1
- package/dist/{sury-CWZTCd75-OKz7uWLi.js → sury-CWZTCd75-r5hgAI0o.js} +3 -3
- package/dist/{sury-CWZTCd75-OKz7uWLi.js.map → sury-CWZTCd75-r5hgAI0o.js.map} +1 -1
- package/dist/{typebox-Dei93FPO-KTtPU745.cjs → typebox-Dei93FPO-B14DOQQD.cjs} +2 -2
- package/dist/typebox-Dei93FPO-B14DOQQD.cjs.map +1 -0
- package/dist/{typebox-Dei93FPO-C5ACKU09.js → typebox-Dei93FPO-BCfJ-0cP.js} +2 -2
- package/dist/typebox-Dei93FPO-BCfJ-0cP.js.map +1 -0
- package/dist/{utils-Bsr_sEcH.cjs → utils-C-gJcJAo.cjs} +4 -4
- package/dist/utils-C-gJcJAo.cjs.map +1 -0
- package/dist/{valibot--1zFm7rT-BeX3W1HK.cjs → valibot--1zFm7rT-BiQdCU9y.cjs} +3 -3
- package/dist/{valibot--1zFm7rT-BeX3W1HK.cjs.map → valibot--1zFm7rT-BiQdCU9y.cjs.map} +1 -1
- package/dist/{valibot--1zFm7rT-BuVb-6oJ.js → valibot--1zFm7rT-CU_2XLpq.js} +3 -3
- package/dist/{valibot--1zFm7rT-BuVb-6oJ.js.map → valibot--1zFm7rT-CU_2XLpq.js.map} +1 -1
- package/dist/validator/custom-resolver.cjs +1 -1
- package/dist/validator/custom-resolver.cjs.map +1 -1
- package/dist/validator/loader.cjs.map +1 -1
- package/dist/validator/loader.js.map +1 -1
- package/dist/{zod-Bwrt9trS-D5b1oyiT.js → zod-Bwrt9trS-BurSNK0g.js} +5 -5
- package/dist/{zod-Bwrt9trS-D5b1oyiT.js.map → zod-Bwrt9trS-BurSNK0g.js.map} +1 -1
- package/dist/{zod-Bwrt9trS-DGQs9DWc.cjs → zod-Bwrt9trS-Kv0hKWrV.cjs} +5 -5
- package/dist/{zod-Bwrt9trS-DGQs9DWc.cjs.map → zod-Bwrt9trS-Kv0hKWrV.cjs.map} +1 -1
- package/package.json +11 -14
- package/dist/analyze-BP0cLyWH.js.map +0 -1
- package/dist/analyze-CcyVW_jJ.cjs.map +0 -1
- package/dist/arktype-aI7TBD0R-BGjyzmsj.js.map +0 -1
- package/dist/arktype-aI7TBD0R-DCxjN6oF.cjs.map +0 -1
- package/dist/build-CNYwIKPG.js.map +0 -1
- package/dist/build-DGJW5-aB.cjs.map +0 -1
- package/dist/bundler-CxslAqI_.cjs.map +0 -1
- package/dist/bundler-DtMHSv5_.js.map +0 -1
- package/dist/bundlerOptions-BtMp_x-T.cjs.map +0 -1
- package/dist/bundlerOptions-ID9i-l8I.js.map +0 -1
- package/dist/core-D3wM1JKp.js.map +0 -1
- package/dist/core-QL_X0T4Y.cjs.map +0 -1
- package/dist/services-DXqmEy8F.js.map +0 -1
- package/dist/services-D_V7afWX.cjs.map +0 -1
- package/dist/typebox-Dei93FPO-C5ACKU09.js.map +0 -1
- package/dist/typebox-Dei93FPO-KTtPU745.cjs.map +0 -1
- package/dist/utils-Bsr_sEcH.cjs.map +0 -1
package/dist/server/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_rolldown_runtime = require("../rolldown-runtime-
|
|
3
|
-
const require_utils = require("../utils-
|
|
4
|
-
require("../index-CLddUTqr-
|
|
2
|
+
const require_rolldown_runtime = require("../rolldown-runtime-Gi87jfEt.cjs");
|
|
3
|
+
const require_utils = require("../utils-C-gJcJAo.cjs");
|
|
4
|
+
require("../index-CLddUTqr-D0GzVJyg.cjs");
|
|
5
5
|
let fs = require("fs");
|
|
6
6
|
let fs_promises = require("fs/promises");
|
|
7
7
|
let path = require("path");
|
|
@@ -23,7 +23,7 @@ util = require_rolldown_runtime.__toESM(util, 1);
|
|
|
23
23
|
let buffer = require("buffer");
|
|
24
24
|
let hono_body_limit = require("hono/body-limit");
|
|
25
25
|
let hono_streaming = require("hono/streaming");
|
|
26
|
-
require("@mastra/core/request-context");
|
|
26
|
+
let _mastra_core_request_context = require("@mastra/core/request-context");
|
|
27
27
|
let _mastra_server_auth = require("@mastra/server/auth");
|
|
28
28
|
let _mastra_server_browser_stream = require("@mastra/server/browser-stream");
|
|
29
29
|
let _mastra_server_a2a_store = require("@mastra/server/a2a/store");
|
|
@@ -797,10 +797,10 @@ function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromi
|
|
|
797
797
|
}
|
|
798
798
|
}
|
|
799
799
|
}
|
|
800
|
-
function writeFromReadableStream(stream
|
|
801
|
-
if (stream
|
|
800
|
+
function writeFromReadableStream(stream, writable) {
|
|
801
|
+
if (stream.locked) throw new TypeError("ReadableStream is locked.");
|
|
802
802
|
else if (writable.destroyed) return;
|
|
803
|
-
return writeFromReadableStreamDefaultReader(stream
|
|
803
|
+
return writeFromReadableStreamDefaultReader(stream.getReader(), writable);
|
|
804
804
|
}
|
|
805
805
|
const buildOutgoingHttpHeaders = (headers, defaultContentType) => {
|
|
806
806
|
const res = {};
|
|
@@ -817,7 +817,7 @@ const buildOutgoingHttpHeaders = (headers, defaultContentType) => {
|
|
|
817
817
|
const outgoingEnded = Symbol("outgoingEnded");
|
|
818
818
|
const incomingDraining = Symbol("incomingDraining");
|
|
819
819
|
const DRAIN_TIMEOUT_MS = 500;
|
|
820
|
-
const MAX_DRAIN_BYTES =
|
|
820
|
+
const MAX_DRAIN_BYTES = 67108864;
|
|
821
821
|
const drainIncoming = (incoming) => {
|
|
822
822
|
const incomingWithDrainState = incoming;
|
|
823
823
|
if (incoming.destroyed || incomingWithDrainState[incomingDraining]) return;
|
|
@@ -1405,10 +1405,10 @@ const ENCODINGS = {
|
|
|
1405
1405
|
gzip: ".gz"
|
|
1406
1406
|
};
|
|
1407
1407
|
const ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
|
|
1408
|
-
const getStats = (path
|
|
1408
|
+
const getStats = (path) => {
|
|
1409
1409
|
let stats;
|
|
1410
1410
|
try {
|
|
1411
|
-
stats = (0, fs.statSync)(path
|
|
1411
|
+
stats = (0, fs.statSync)(path);
|
|
1412
1412
|
} catch {}
|
|
1413
1413
|
return stats;
|
|
1414
1414
|
};
|
|
@@ -1477,29 +1477,29 @@ const serveStatic = (options = { root: "" }) => {
|
|
|
1477
1477
|
await options.onNotFound?.(c.req.path, c);
|
|
1478
1478
|
return next();
|
|
1479
1479
|
}
|
|
1480
|
-
let path$
|
|
1481
|
-
let stats = getStats(path$
|
|
1480
|
+
let path$1 = (0, path.join)(root, !optionPath && options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename);
|
|
1481
|
+
let stats = getStats(path$1);
|
|
1482
1482
|
if (stats && stats.isDirectory()) {
|
|
1483
1483
|
const indexFile = options.index ?? "index.html";
|
|
1484
|
-
path$
|
|
1485
|
-
stats = getStats(path$
|
|
1484
|
+
path$1 = (0, path.join)(path$1, indexFile);
|
|
1485
|
+
stats = getStats(path$1);
|
|
1486
1486
|
}
|
|
1487
1487
|
if (!stats) {
|
|
1488
|
-
await options.onNotFound?.(path$
|
|
1488
|
+
await options.onNotFound?.(path$1, c);
|
|
1489
1489
|
return next();
|
|
1490
1490
|
}
|
|
1491
|
-
const mimeType = (0, hono_utils_mime.getMimeType)(path$
|
|
1491
|
+
const mimeType = (0, hono_utils_mime.getMimeType)(path$1);
|
|
1492
1492
|
c.header("Content-Type", mimeType || "application/octet-stream");
|
|
1493
1493
|
if (options.precompressed && (!mimeType || mimeType === "application/octet-stream" || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
|
|
1494
1494
|
const acceptEncodingSet = new Set(c.req.header("Accept-Encoding")?.split(",").map((encoding) => encoding.trim()));
|
|
1495
1495
|
for (const encoding of ENCODINGS_ORDERED_KEYS) {
|
|
1496
1496
|
if (!acceptEncodingSet.has(encoding)) continue;
|
|
1497
|
-
const precompressedStats = getStats(path$
|
|
1497
|
+
const precompressedStats = getStats(path$1 + ENCODINGS[encoding]);
|
|
1498
1498
|
if (precompressedStats) {
|
|
1499
1499
|
c.header("Content-Encoding", encoding);
|
|
1500
1500
|
c.header("Vary", "Accept-Encoding", { append: true });
|
|
1501
1501
|
stats = precompressedStats;
|
|
1502
|
-
path$
|
|
1502
|
+
path$1 = path$1 + ENCODINGS[encoding];
|
|
1503
1503
|
break;
|
|
1504
1504
|
}
|
|
1505
1505
|
}
|
|
@@ -1514,7 +1514,7 @@ const serveStatic = (options = { root: "" }) => {
|
|
|
1514
1514
|
result = c.body(null);
|
|
1515
1515
|
} else if (!range) {
|
|
1516
1516
|
c.header("Content-Length", size.toString());
|
|
1517
|
-
result = c.body(createStreamBody((0, fs.createReadStream)(path$
|
|
1517
|
+
result = c.body(createStreamBody((0, fs.createReadStream)(path$1)), 200);
|
|
1518
1518
|
} else {
|
|
1519
1519
|
c.header("Accept-Ranges", "bytes");
|
|
1520
1520
|
const resolvedRange = resolveByteRange(parseByteRange(range) ?? {
|
|
@@ -1527,7 +1527,7 @@ const serveStatic = (options = { root: "" }) => {
|
|
|
1527
1527
|
} else {
|
|
1528
1528
|
const { start, end } = resolvedRange;
|
|
1529
1529
|
const chunkSize = end - start + 1;
|
|
1530
|
-
const stream = (0, fs.createReadStream)(path$
|
|
1530
|
+
const stream = (0, fs.createReadStream)(path$1, {
|
|
1531
1531
|
start,
|
|
1532
1532
|
end
|
|
1533
1533
|
});
|
|
@@ -1536,7 +1536,7 @@ const serveStatic = (options = { root: "" }) => {
|
|
|
1536
1536
|
result = c.body(createStreamBody(stream), 206);
|
|
1537
1537
|
}
|
|
1538
1538
|
}
|
|
1539
|
-
await options.onFound?.(path$
|
|
1539
|
+
await options.onFound?.(path$1, c);
|
|
1540
1540
|
return result;
|
|
1541
1541
|
};
|
|
1542
1542
|
};
|
|
@@ -1764,13 +1764,15 @@ var ERR_INVALID_ARG_TYPE = class extends TypeError {
|
|
|
1764
1764
|
}
|
|
1765
1765
|
if (other.length > 0) msg += " or ";
|
|
1766
1766
|
}
|
|
1767
|
-
if (other.length > 0)
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1767
|
+
if (other.length > 0) {
|
|
1768
|
+
if (other.length > 2) {
|
|
1769
|
+
const last = other.pop();
|
|
1770
|
+
msg += `one of ${other.join(", ")}, or ${last}`;
|
|
1771
|
+
} else if (other.length === 2) msg += `one of ${other[0]} or ${other[1]}`;
|
|
1772
|
+
else {
|
|
1773
|
+
if (other[0].toLowerCase() !== other[0]) msg += "an ";
|
|
1774
|
+
msg += `${other[0]}`;
|
|
1775
|
+
}
|
|
1774
1776
|
}
|
|
1775
1777
|
msg += `. Received ${determineSpecificType(actual)}`;
|
|
1776
1778
|
super(msg);
|
|
@@ -1971,11 +1973,13 @@ var FetchIncomingMessage = class extends stream.Readable {
|
|
|
1971
1973
|
field = field.slice(1);
|
|
1972
1974
|
if (typeof dest[field] === "string") dest[field] += (flag === 0 ? ", " : "; ") + value;
|
|
1973
1975
|
else dest[field] = value;
|
|
1974
|
-
} else if (flag === 1)
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
else
|
|
1978
|
-
|
|
1976
|
+
} else if (flag === 1) {
|
|
1977
|
+
if (dest["set-cookie"] !== void 0) dest["set-cookie"].push(value);
|
|
1978
|
+
else dest["set-cookie"] = [value];
|
|
1979
|
+
} else if (this.joinDuplicateHeaders) {
|
|
1980
|
+
if (dest[field] === void 0) dest[field] = value;
|
|
1981
|
+
else dest[field] += ", " + value;
|
|
1982
|
+
} else if (dest[field] === void 0) dest[field] = value;
|
|
1979
1983
|
}
|
|
1980
1984
|
_addHeaderLineDistinct(field, value, dest) {
|
|
1981
1985
|
field = field.toLowerCase();
|
|
@@ -2056,7 +2060,6 @@ function matchKnownFields(field, lowercased = false) {
|
|
|
2056
2060
|
case 19:
|
|
2057
2061
|
if (field === "Proxy-Authorization" || field === "proxy-authorization") return "proxy-authorization";
|
|
2058
2062
|
if (field === "If-Unmodified-Since" || field === "if-unmodified-since") return "if-unmodified-since";
|
|
2059
|
-
break;
|
|
2060
2063
|
}
|
|
2061
2064
|
if (lowercased) return "\0" + field;
|
|
2062
2065
|
return matchKnownFields(field.toLowerCase(), true);
|
|
@@ -2105,7 +2108,7 @@ function utcDate() {
|
|
|
2105
2108
|
//#endregion
|
|
2106
2109
|
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/fetch-to-node/2.1.0/75a085586b95f3a18a440f8655a7cb5c851846ab2c5e6ad2c4ae036e3bbaa05c/node_modules/fetch-to-node/dist/fetch-to-node/internal-streams-state.js
|
|
2107
2110
|
function getDefaultHighWaterMark(objectMode) {
|
|
2108
|
-
return objectMode ? 16 :
|
|
2111
|
+
return objectMode ? 16 : 65536;
|
|
2109
2112
|
}
|
|
2110
2113
|
//#endregion
|
|
2111
2114
|
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/fetch-to-node/2.1.0/75a085586b95f3a18a440f8655a7cb5c851846ab2c5e6ad2c4ae036e3bbaa05c/node_modules/fetch-to-node/dist/fetch-to-node/http-common.js
|
|
@@ -2393,15 +2396,16 @@ var FetchOutgoingMessage = class extends stream.Writable {
|
|
|
2393
2396
|
const entry = headers[key];
|
|
2394
2397
|
processHeader(this, state, entry[0], entry[1], false);
|
|
2395
2398
|
}
|
|
2396
|
-
else if (Array.isArray(headers))
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2399
|
+
else if (Array.isArray(headers)) {
|
|
2400
|
+
if (headers.length && Array.isArray(headers[0])) for (let i = 0; i < headers.length; i++) {
|
|
2401
|
+
const entry = headers[i];
|
|
2402
|
+
processHeader(this, state, entry[0], entry[1], true);
|
|
2403
|
+
}
|
|
2404
|
+
else {
|
|
2405
|
+
if (headers.length % 2 !== 0) throw new ERR_INVALID_ARG_VALUE("headers", headers);
|
|
2406
|
+
for (let n = 0; n < headers.length; n += 2) processHeader(this, state, headers[n], headers[n + 1], true);
|
|
2407
|
+
}
|
|
2408
|
+
} else for (const key in headers) if (headers.hasOwnProperty(key)) {
|
|
2405
2409
|
const _headers = headers;
|
|
2406
2410
|
processHeader(this, state, key, _headers[key], true);
|
|
2407
2411
|
}
|
|
@@ -2430,13 +2434,15 @@ var FetchOutgoingMessage = class extends stream.Writable {
|
|
|
2430
2434
|
header += "Connection: close\r\n";
|
|
2431
2435
|
}
|
|
2432
2436
|
}
|
|
2433
|
-
if (!state.contLen && !state.te)
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2437
|
+
if (!state.contLen && !state.te) {
|
|
2438
|
+
if (!this._hasBody) this.chunkedEncoding = false;
|
|
2439
|
+
else if (!this.useChunkedEncodingByDefault) this._last = true;
|
|
2440
|
+
else if (!state.trailer && !this._removedContLen && typeof this._contentLength === "number") header += "Content-Length: " + this._contentLength + "\r\n";
|
|
2441
|
+
else if (!this._removedTE) {
|
|
2442
|
+
header += "Transfer-Encoding: chunked\r\n";
|
|
2443
|
+
this.chunkedEncoding = true;
|
|
2444
|
+
} else this._last = true;
|
|
2445
|
+
}
|
|
2440
2446
|
if (this.chunkedEncoding !== true && state.trailer) throw new ERR_HTTP_TRAILER_INVALID();
|
|
2441
2447
|
this._header = header + "\r\n";
|
|
2442
2448
|
this._headerSent = false;
|
|
@@ -2580,9 +2586,7 @@ var FetchOutgoingMessage = class extends stream.Writable {
|
|
|
2580
2586
|
case "transfer-encoding":
|
|
2581
2587
|
this._removedTE = true;
|
|
2582
2588
|
break;
|
|
2583
|
-
case "date":
|
|
2584
|
-
this.sendDate = false;
|
|
2585
|
-
break;
|
|
2589
|
+
case "date": this.sendDate = false;
|
|
2586
2590
|
}
|
|
2587
2591
|
if (this[kOutHeaders] !== null) delete this[kOutHeaders][key];
|
|
2588
2592
|
}
|
|
@@ -2653,8 +2657,10 @@ var FetchOutgoingMessage = class extends stream.Writable {
|
|
|
2653
2657
|
if (this._writtenDataBuffer != null) this._writtenDataBuffer.cork();
|
|
2654
2658
|
write_(this, chunk, encoding, null, true);
|
|
2655
2659
|
} else if (this.finished) {
|
|
2656
|
-
if (typeof callback === "function")
|
|
2657
|
-
|
|
2660
|
+
if (typeof callback === "function") {
|
|
2661
|
+
if (!this.writableFinished) this.on("finish", callback);
|
|
2662
|
+
else callback(new ERR_STREAM_ALREADY_FINISHED("end"));
|
|
2663
|
+
}
|
|
2658
2664
|
return this;
|
|
2659
2665
|
} else if (!this._header) {
|
|
2660
2666
|
if (this._writtenDataBuffer != null) this._writtenDataBuffer.cork();
|
|
@@ -2719,8 +2725,10 @@ var FetchOutgoingMessage = class extends stream.Writable {
|
|
|
2719
2725
|
};
|
|
2720
2726
|
function processHeader(self, state, key, value, validate) {
|
|
2721
2727
|
if (validate) validateHeaderName(key);
|
|
2722
|
-
if (isContentDispositionField(key) && self._contentLength)
|
|
2723
|
-
|
|
2728
|
+
if (isContentDispositionField(key) && self._contentLength) {
|
|
2729
|
+
if (Array.isArray(value)) for (let i = 0; i < value.length; i++) value[i] = String(buffer.Buffer.from(String(value[i]), "latin1"));
|
|
2730
|
+
else value = String(buffer.Buffer.from(String(value), "latin1"));
|
|
2731
|
+
}
|
|
2724
2732
|
if (Array.isArray(value)) {
|
|
2725
2733
|
if ((value.length < 2 || !isCookieField(key)) && (!self[kUniqueHeaders] || !self[kUniqueHeaders].has(key.toLowerCase()))) {
|
|
2726
2734
|
for (let i = 0; i < value.length; i++) storeHeader(self, state, key, value[i], validate);
|
|
@@ -2770,9 +2778,7 @@ function matchHeader(self, state, field, value) {
|
|
|
2770
2778
|
case "trailer":
|
|
2771
2779
|
state[field] = true;
|
|
2772
2780
|
break;
|
|
2773
|
-
case "keep-alive":
|
|
2774
|
-
self._defaultKeepAlive = false;
|
|
2775
|
-
break;
|
|
2781
|
+
case "keep-alive": self._defaultKeepAlive = false;
|
|
2776
2782
|
}
|
|
2777
2783
|
}
|
|
2778
2784
|
function onError(msg, err, callback) {
|
|
@@ -2815,10 +2821,12 @@ function write_(msg, chunk, encoding, callback, fromEnd) {
|
|
|
2815
2821
|
}
|
|
2816
2822
|
msg._implicitHeader();
|
|
2817
2823
|
}
|
|
2818
|
-
if (!msg._hasBody)
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2824
|
+
if (!msg._hasBody) {
|
|
2825
|
+
if (msg[kRejectNonStandardBodyWrites]) throw new ERR_HTTP_BODY_NOT_ALLOWED();
|
|
2826
|
+
else {
|
|
2827
|
+
setTimeout(callback, 0);
|
|
2828
|
+
return true;
|
|
2829
|
+
}
|
|
2822
2830
|
}
|
|
2823
2831
|
if (!fromEnd && msg._writtenDataBuffer != null && !msg._writtenDataBuffer.writableCorked) {
|
|
2824
2832
|
msg._writtenDataBuffer.cork();
|
|
@@ -3016,8 +3024,10 @@ var FetchServerResponse = class FetchServerResponse extends FetchOutgoingMessage
|
|
|
3016
3024
|
}
|
|
3017
3025
|
data = data.slice(this.writtenHeaderBytes);
|
|
3018
3026
|
}
|
|
3019
|
-
if (typeof data === "string")
|
|
3020
|
-
|
|
3027
|
+
if (typeof data === "string") {
|
|
3028
|
+
if (encoding === void 0 || encoding === "utf8" || encoding === "utf-8") data = FetchServerResponse.encoder.encode(data);
|
|
3029
|
+
else data = buffer.Buffer.from(data, encoding ?? void 0);
|
|
3030
|
+
}
|
|
3021
3031
|
return data ?? buffer.Buffer.from([]);
|
|
3022
3032
|
}
|
|
3023
3033
|
_finish() {
|
|
@@ -3201,6 +3211,191 @@ function propagateClientDisconnect(fetchResponse, res) {
|
|
|
3201
3211
|
headers: fetchResponse.headers
|
|
3202
3212
|
});
|
|
3203
3213
|
}
|
|
3214
|
+
function createAuthMiddleware({ mastra, requiresAuth = true }) {
|
|
3215
|
+
return async (c, next) => {
|
|
3216
|
+
if (!requiresAuth) return next();
|
|
3217
|
+
const authConfig = mastra.getServer()?.auth;
|
|
3218
|
+
if (!authConfig) return next();
|
|
3219
|
+
const requestContext = c.get("requestContext") ?? new _mastra_core_request_context.RequestContext();
|
|
3220
|
+
c.set("requestContext", requestContext);
|
|
3221
|
+
c.set("mastra", c.get("mastra") ?? mastra);
|
|
3222
|
+
const path = c.req.path;
|
|
3223
|
+
const method = c.req.method;
|
|
3224
|
+
const customRouteAuthConfig = new Map(c.get("customRouteAuthConfig") ?? []);
|
|
3225
|
+
if (!(0, _mastra_server_auth.isCustomRoutePublic)(path, method, customRouteAuthConfig)) customRouteAuthConfig.set(`${method}:${path}`, true);
|
|
3226
|
+
const authHeader = c.req.header("Authorization");
|
|
3227
|
+
let token = authHeader ? authHeader.replace("Bearer ", "") : null;
|
|
3228
|
+
if (!token) token = c.req.query("apiKey") || null;
|
|
3229
|
+
const result = await (0, _mastra_server_auth.coreAuthMiddleware)({
|
|
3230
|
+
path,
|
|
3231
|
+
method,
|
|
3232
|
+
getHeader: (name) => c.req.header(name),
|
|
3233
|
+
mastra,
|
|
3234
|
+
authConfig,
|
|
3235
|
+
customRouteAuthConfig,
|
|
3236
|
+
requestContext,
|
|
3237
|
+
rawRequest: c.req.raw,
|
|
3238
|
+
token,
|
|
3239
|
+
buildAuthorizeContext: () => c
|
|
3240
|
+
});
|
|
3241
|
+
for (const [key, value] of Object.entries(result.headers ?? {})) c.header(key, value, key.toLowerCase() === "set-cookie" ? { append: true } : void 0);
|
|
3242
|
+
if (result.action === "next") return next();
|
|
3243
|
+
return c.json(result.body, result.status);
|
|
3244
|
+
};
|
|
3245
|
+
}
|
|
3246
|
+
const TICKET_BYTES = 32;
|
|
3247
|
+
/**
|
|
3248
|
+
* How long an issued ticket stays valid. A ticket is minted immediately before
|
|
3249
|
+
* the socket is opened, so this only has to cover the round trip plus the
|
|
3250
|
+
* handshake — short enough that a ticket leaked from a log is useless by the
|
|
3251
|
+
* time anyone can act on it.
|
|
3252
|
+
*/
|
|
3253
|
+
const UPGRADE_TICKET_TTL_MS = 3e4;
|
|
3254
|
+
/**
|
|
3255
|
+
* Ceiling on tracked per-agent issuance counters, so the limiter can't grow
|
|
3256
|
+
* without bound as agent ids are invented. Counters are evicted oldest first.
|
|
3257
|
+
*/
|
|
3258
|
+
const MAX_TRACKED_AGENTS = 500;
|
|
3259
|
+
/** 256 bits of base64url, so the ticket can't be guessed or enumerated. */
|
|
3260
|
+
function createTicketValue() {
|
|
3261
|
+
const bytes = new Uint8Array(TICKET_BYTES);
|
|
3262
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
3263
|
+
return btoa(String.fromCharCode(...bytes)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
3264
|
+
}
|
|
3265
|
+
/**
|
|
3266
|
+
* Short-lived, single-use credentials for browser WebSocket upgrades.
|
|
3267
|
+
*
|
|
3268
|
+
* A browser cannot set an `Authorization` header on a WebSocket handshake, so a
|
|
3269
|
+
* deployment that authenticates with a header token would otherwise have to put
|
|
3270
|
+
* that reusable token in the handshake URL, where proxies and access logs can
|
|
3271
|
+
* retain it. Instead the client asks an authenticated HTTP route for a ticket,
|
|
3272
|
+
* and the ticket — worthless once spent, and scoped to one agent and thread —
|
|
3273
|
+
* travels in the URL instead.
|
|
3274
|
+
*
|
|
3275
|
+
* In-process, like the `ViewerRegistry` and the browser sessions it serves: a
|
|
3276
|
+
* screencast is bound to the process holding the browser, so a ticket store
|
|
3277
|
+
* shared across replicas would buy nothing. A ticket presented to a different
|
|
3278
|
+
* replica fails for the same reason the stream itself would.
|
|
3279
|
+
*
|
|
3280
|
+
* Issuance is bounded so the mint endpoint can't be turned into memory or CPU
|
|
3281
|
+
* exhaustion: tickets that are never spent live at most one TTL, a full store
|
|
3282
|
+
* rejects instead of growing, and each agent has a request allowance. Expiry is
|
|
3283
|
+
* swept from the front of the insertion-ordered map, so cleanup costs the
|
|
3284
|
+
* number of entries actually expired rather than a scan of every outstanding
|
|
3285
|
+
* ticket per request.
|
|
3286
|
+
*/
|
|
3287
|
+
var UpgradeTicketStore = class {
|
|
3288
|
+
#tickets = /* @__PURE__ */ new Map();
|
|
3289
|
+
#issuance = /* @__PURE__ */ new Map();
|
|
3290
|
+
#now;
|
|
3291
|
+
constructor(now = () => Date.now()) {
|
|
3292
|
+
this.#now = now;
|
|
3293
|
+
}
|
|
3294
|
+
/**
|
|
3295
|
+
* Issue a ticket bound to one agent and thread. Returns `{ ok: false }` when
|
|
3296
|
+
* the agent exceeded its allowance or the store is at capacity.
|
|
3297
|
+
*/
|
|
3298
|
+
issue(agentId, threadId, ttlMs = UPGRADE_TICKET_TTL_MS) {
|
|
3299
|
+
const now = this.#now();
|
|
3300
|
+
this.#prune(now);
|
|
3301
|
+
if (this.#tickets.size >= 500) return {
|
|
3302
|
+
ok: false,
|
|
3303
|
+
reason: "capacity"
|
|
3304
|
+
};
|
|
3305
|
+
const window = this.#issuance.get(agentId);
|
|
3306
|
+
if (!window || now - window.windowStart >= 6e4) this.#trackIssuance(agentId, {
|
|
3307
|
+
windowStart: now,
|
|
3308
|
+
count: 0
|
|
3309
|
+
});
|
|
3310
|
+
else if (window.count >= 30) return {
|
|
3311
|
+
ok: false,
|
|
3312
|
+
reason: "rate-limited"
|
|
3313
|
+
};
|
|
3314
|
+
this.#issuance.get(agentId).count += 1;
|
|
3315
|
+
const ticket = createTicketValue();
|
|
3316
|
+
this.#tickets.set(ticket, {
|
|
3317
|
+
agentId,
|
|
3318
|
+
threadId,
|
|
3319
|
+
expiresAt: now + ttlMs
|
|
3320
|
+
});
|
|
3321
|
+
return {
|
|
3322
|
+
ok: true,
|
|
3323
|
+
ticket,
|
|
3324
|
+
expiresIn: Math.ceil(ttlMs / 1e3)
|
|
3325
|
+
};
|
|
3326
|
+
}
|
|
3327
|
+
/**
|
|
3328
|
+
* Spend a ticket. Returns `true` only when the ticket is unexpired and was
|
|
3329
|
+
* issued for this exact agent and thread, in which case it is consumed and a
|
|
3330
|
+
* second presentation fails.
|
|
3331
|
+
*/
|
|
3332
|
+
consume(ticket, agentId, threadId) {
|
|
3333
|
+
const entry = this.#tickets.get(ticket);
|
|
3334
|
+
if (!entry) return false;
|
|
3335
|
+
if (entry.expiresAt <= this.#now()) return false;
|
|
3336
|
+
if (entry.agentId !== agentId) return false;
|
|
3337
|
+
if ((entry.threadId ?? void 0) !== (threadId ?? void 0)) return false;
|
|
3338
|
+
this.#tickets.delete(ticket);
|
|
3339
|
+
return true;
|
|
3340
|
+
}
|
|
3341
|
+
/**
|
|
3342
|
+
* Drop expired tickets from the front of the insertion-ordered map. Tickets
|
|
3343
|
+
* are inserted in issue order and share a TTL, so the entries after the first
|
|
3344
|
+
* live one are live too and the sweep can stop there.
|
|
3345
|
+
*/
|
|
3346
|
+
#prune(now) {
|
|
3347
|
+
for (const [ticket, entry] of this.#tickets) {
|
|
3348
|
+
if (entry.expiresAt > now) break;
|
|
3349
|
+
this.#tickets.delete(ticket);
|
|
3350
|
+
}
|
|
3351
|
+
}
|
|
3352
|
+
/** Record an issuance window, evicting the oldest counter when at the cap. */
|
|
3353
|
+
#trackIssuance(agentId, window) {
|
|
3354
|
+
this.#issuance.delete(agentId);
|
|
3355
|
+
this.#issuance.set(agentId, window);
|
|
3356
|
+
if (this.#issuance.size > MAX_TRACKED_AGENTS) {
|
|
3357
|
+
const oldest = this.#issuance.keys().next().value;
|
|
3358
|
+
if (oldest !== void 0) this.#issuance.delete(oldest);
|
|
3359
|
+
}
|
|
3360
|
+
}
|
|
3361
|
+
};
|
|
3362
|
+
const TICKET_BODY_MAX_BYTES = 4096;
|
|
3363
|
+
/**
|
|
3364
|
+
* Resolve an `allowedOrigins` value against the request's `Origin` header.
|
|
3365
|
+
*
|
|
3366
|
+
* Mirrors Hono's `cors.origin` semantics so the same config value means the same
|
|
3367
|
+
* thing on the upgrade as it does on the HTTP routes: `'*'` allows everything,
|
|
3368
|
+
* array entries match literally, and a callback is only an approval when it
|
|
3369
|
+
* returns the request's own origin (the value Hono would echo back) or `'*'`.
|
|
3370
|
+
*/
|
|
3371
|
+
async function isOriginAllowed(allowedOrigins, origin, c) {
|
|
3372
|
+
if (Array.isArray(allowedOrigins)) return allowedOrigins.includes(origin);
|
|
3373
|
+
if (typeof allowedOrigins === "function") {
|
|
3374
|
+
const allowed = await allowedOrigins(origin, c);
|
|
3375
|
+
return allowed === origin || allowed === "*";
|
|
3376
|
+
}
|
|
3377
|
+
return allowedOrigins === "*" || allowedOrigins === origin;
|
|
3378
|
+
}
|
|
3379
|
+
/**
|
|
3380
|
+
* Is the `Origin` header the server's own origin?
|
|
3381
|
+
*
|
|
3382
|
+
* A Studio served by this server connects back to the same host, and operators
|
|
3383
|
+
* don't add their own origin to a CORS allowlist because same-origin requests
|
|
3384
|
+
* never needed CORS. Comparing hosts (rather than scheme + host) keeps that
|
|
3385
|
+
* working behind TLS-terminating proxies, where the server sees `http` while the
|
|
3386
|
+
* browser sends `https`.
|
|
3387
|
+
*/
|
|
3388
|
+
function isSameOrigin(origin, requestHost) {
|
|
3389
|
+
if (!requestHost) return false;
|
|
3390
|
+
let originHost;
|
|
3391
|
+
try {
|
|
3392
|
+
originHost = new URL(origin).host;
|
|
3393
|
+
} catch {
|
|
3394
|
+
return false;
|
|
3395
|
+
}
|
|
3396
|
+
const host = (requestHost.split(",")[0] ?? "").trim();
|
|
3397
|
+
return originHost !== "" && originHost.toLowerCase() === host.toLowerCase();
|
|
3398
|
+
}
|
|
3204
3399
|
/**
|
|
3205
3400
|
* Set up WebSocket-based browser stream endpoint for real-time screencast viewing.
|
|
3206
3401
|
*
|
|
@@ -3210,6 +3405,17 @@ function propagateClientDisconnect(fetchResponse, res) {
|
|
|
3210
3405
|
* - Broadcasts frames to all connected viewers
|
|
3211
3406
|
* - Stops screencast when last viewer disconnects
|
|
3212
3407
|
*
|
|
3408
|
+
* All routes are authenticated with the server's auth configuration. Browsers
|
|
3409
|
+
* cannot attach an `Authorization` header to a WebSocket upgrade, so
|
|
3410
|
+
* session-cookie providers authenticate from the upgrade request's cookies.
|
|
3411
|
+
* Clients that authenticate with a header token instead request a short-lived,
|
|
3412
|
+
* single-use ticket from `POST ${apiPrefix}/agents/:agentId/browser/stream-ticket`
|
|
3413
|
+
* and pass it to the upgrade as `?ticket=`, which keeps the reusable credential
|
|
3414
|
+
* out of the URL. Non-browser clients can pass the token as the `apiKey` query
|
|
3415
|
+
* parameter — use a short-lived token, since a URL can be retained in proxy and
|
|
3416
|
+
* access logs, and prefer the `Authorization` header on the HTTP routes where the
|
|
3417
|
+
* client can set one.
|
|
3418
|
+
*
|
|
3213
3419
|
* **Note**: Requires `ws` package to be installed. If not available, returns null
|
|
3214
3420
|
* and logs a warning. Browser streaming will be disabled but everything else works.
|
|
3215
3421
|
*
|
|
@@ -3225,6 +3431,7 @@ function propagateClientDisconnect(fetchResponse, res) {
|
|
|
3225
3431
|
*
|
|
3226
3432
|
* const app = new Hono();
|
|
3227
3433
|
* const browserStream = await setupBrowserStream(app, {
|
|
3434
|
+
* mastra,
|
|
3228
3435
|
* getToolset: (agentId) => browserToolsets.get(agentId),
|
|
3229
3436
|
* });
|
|
3230
3437
|
*
|
|
@@ -3247,7 +3454,24 @@ async function setupBrowserStream(app, config) {
|
|
|
3247
3454
|
const registry = new _mastra_server_browser_stream.ViewerRegistry();
|
|
3248
3455
|
const rawPrefix = config.apiPrefix ?? "/api";
|
|
3249
3456
|
const apiPrefix = (rawPrefix.endsWith("/") ? rawPrefix.slice(0, -1) : rawPrefix) || "/api";
|
|
3250
|
-
|
|
3457
|
+
const authenticate = createAuthMiddleware({ mastra: config.mastra });
|
|
3458
|
+
const upgradeTickets = new UpgradeTicketStore();
|
|
3459
|
+
const authorizeUpgrade = async (c, next) => {
|
|
3460
|
+
const ticket = c.req.query("ticket");
|
|
3461
|
+
if (!ticket) return authenticate(c, next);
|
|
3462
|
+
const agentId = c.req.param("agentId");
|
|
3463
|
+
if (!upgradeTickets.consume(ticket, agentId, c.req.query("threadId"))) return c.json({ error: "Invalid or expired upgrade ticket" }, 401);
|
|
3464
|
+
return next();
|
|
3465
|
+
};
|
|
3466
|
+
const allowedOrigins = config.allowedOrigins;
|
|
3467
|
+
const checkOrigin = async (c, next) => {
|
|
3468
|
+
const origin = c.req.header("origin");
|
|
3469
|
+
if (!allowedOrigins || !origin) return next();
|
|
3470
|
+
if (isSameOrigin(origin, c.req.header("x-forwarded-host") ?? c.req.header("host"))) return next();
|
|
3471
|
+
if (!await isOriginAllowed(allowedOrigins, origin, c)) return c.text("Forbidden", 403);
|
|
3472
|
+
return next();
|
|
3473
|
+
};
|
|
3474
|
+
app.get("/browser/:agentId/stream", checkOrigin, authorizeUpgrade, upgradeWebSocket((c) => {
|
|
3251
3475
|
const agentId = c.req.param("agentId");
|
|
3252
3476
|
const threadId = c.req.query("threadId");
|
|
3253
3477
|
const viewerKey = threadId ? `${agentId}:${threadId}` : agentId;
|
|
@@ -3269,7 +3493,29 @@ async function setupBrowserStream(app, config) {
|
|
|
3269
3493
|
}
|
|
3270
3494
|
};
|
|
3271
3495
|
}));
|
|
3272
|
-
|
|
3496
|
+
const ticketBodyLimit = (0, hono_body_limit.bodyLimit)({
|
|
3497
|
+
maxSize: TICKET_BODY_MAX_BYTES,
|
|
3498
|
+
onError: (c) => c.json({ error: "Request body too large" }, 413)
|
|
3499
|
+
});
|
|
3500
|
+
app.post(`${apiPrefix}/agents/:agentId/browser/stream-ticket`, authenticate, ticketBodyLimit, async (c) => {
|
|
3501
|
+
const agentId = c.req.param("agentId");
|
|
3502
|
+
if (!agentId) return c.json({ error: "Agent ID is required" }, 400);
|
|
3503
|
+
let threadId = c.req.query("threadId");
|
|
3504
|
+
try {
|
|
3505
|
+
const body = await c.req.json();
|
|
3506
|
+
if (!threadId && typeof body?.threadId === "string") threadId = body.threadId;
|
|
3507
|
+
} catch {}
|
|
3508
|
+
const issued = upgradeTickets.issue(agentId, threadId);
|
|
3509
|
+
if (!issued.ok) {
|
|
3510
|
+
const error = issued.reason === "capacity" ? "Too many outstanding browser stream upgrade tickets" : "Too many browser stream upgrade tickets requested";
|
|
3511
|
+
return c.json({ error }, 429);
|
|
3512
|
+
}
|
|
3513
|
+
return c.json({
|
|
3514
|
+
ticket: issued.ticket,
|
|
3515
|
+
expiresIn: issued.expiresIn
|
|
3516
|
+
});
|
|
3517
|
+
});
|
|
3518
|
+
app.get(`${apiPrefix}/agents/:agentId/browser/session`, authenticate, async (c) => {
|
|
3273
3519
|
const agentId = c.req.param("agentId");
|
|
3274
3520
|
if (!agentId) return c.json({ error: "Agent ID is required" }, 400);
|
|
3275
3521
|
const threadId = c.req.query("threadId");
|
|
@@ -3284,7 +3530,7 @@ async function setupBrowserStream(app, config) {
|
|
|
3284
3530
|
screencastAvailable: true
|
|
3285
3531
|
});
|
|
3286
3532
|
});
|
|
3287
|
-
app.post(`${apiPrefix}/agents/:agentId/browser/close`, async (c) => {
|
|
3533
|
+
app.post(`${apiPrefix}/agents/:agentId/browser/close`, authenticate, ticketBodyLimit, async (c) => {
|
|
3288
3534
|
const agentId = c.req.param("agentId");
|
|
3289
3535
|
if (!agentId) return c.json({ error: "Agent ID is required" }, 400);
|
|
3290
3536
|
const toolset = await config.getToolset(agentId);
|
|
@@ -3896,7 +4142,7 @@ var MastraServer = class extends _mastra_server_server_adapter.MastraServer {
|
|
|
3896
4142
|
}
|
|
3897
4143
|
};
|
|
3898
4144
|
//#endregion
|
|
3899
|
-
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/hono-openapi/1.3.1/
|
|
4145
|
+
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/hono-openapi/1.3.1/158235e7235efea6160a30c3ca102ac021a6d2f9183c16a3ddab0c84f82188b4/node_modules/hono-openapi/dist/index.js
|
|
3900
4146
|
const uniqueSymbol = Symbol("openapi");
|
|
3901
4147
|
function describeRoute(spec) {
|
|
3902
4148
|
const middleware = async (_c, next) => {
|
|
@@ -4596,9 +4842,12 @@ function welcomeHtml(apiPrefix = "/api") {
|
|
|
4596
4842
|
//#region src/server/index.ts
|
|
4597
4843
|
const getStudioPath = () => {
|
|
4598
4844
|
if (process.env.MASTRA_STUDIO_PATH) return process.env.MASTRA_STUDIO_PATH;
|
|
4599
|
-
let __dirname = ".";
|
|
4600
|
-
if (require("url").pathToFileURL(__filename).href)
|
|
4601
|
-
|
|
4845
|
+
let __dirname$1 = ".";
|
|
4846
|
+
if (require("url").pathToFileURL(__filename).href) {
|
|
4847
|
+
const __filename$1 = (0, url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
|
|
4848
|
+
__dirname$1 = (0, path.dirname)(__filename$1);
|
|
4849
|
+
}
|
|
4850
|
+
return process.env.MASTRA_STUDIO_PATH || (0, path.join)(__dirname$1, "studio");
|
|
4602
4851
|
};
|
|
4603
4852
|
function isSchemaApiRoute(route) {
|
|
4604
4853
|
return "_mastraSchemaRoute" in route && route._mastraSchemaRoute === true;
|
|
@@ -4683,7 +4932,7 @@ async function createHonoServer(mastra, options = { tools: {} }) {
|
|
|
4683
4932
|
return errorHandler(err, c, options.isDev);
|
|
4684
4933
|
});
|
|
4685
4934
|
const bodyLimitOptions = {
|
|
4686
|
-
maxSize: server?.bodySizeLimit ??
|
|
4935
|
+
maxSize: server?.bodySizeLimit ?? 4718592,
|
|
4687
4936
|
onError: () => ({ error: "Request body too large" })
|
|
4688
4937
|
};
|
|
4689
4938
|
const honoServerAdapter = new MastraServer({
|
|
@@ -4701,7 +4950,10 @@ async function createHonoServer(mastra, options = { tools: {} }) {
|
|
|
4701
4950
|
honoServerAdapter.registerContextMiddleware();
|
|
4702
4951
|
const serverMiddleware = mastra.getServerMiddleware?.();
|
|
4703
4952
|
if (serverMiddleware && serverMiddleware.length > 0) for (const m of serverMiddleware) app.use(m.path, skipIfFrameworkPublic(m.handler));
|
|
4953
|
+
const browserStreamOrigins = server?.cors && typeof server.cors === "object" && "origin" in server.cors ? server.cors.origin : void 0;
|
|
4704
4954
|
const browserStreamSetup = options.browserStream === false ? null : await setupBrowserStream(app, {
|
|
4955
|
+
mastra,
|
|
4956
|
+
allowedOrigins: browserStreamOrigins,
|
|
4705
4957
|
getToolset: async (agentId) => {
|
|
4706
4958
|
const resolveBrowser = async (agent) => {
|
|
4707
4959
|
if (!agent) return void 0;
|
|
@@ -4728,14 +4980,15 @@ async function createHonoServer(mastra, options = { tools: {} }) {
|
|
|
4728
4980
|
hasSession: false,
|
|
4729
4981
|
screencastAvailable: false
|
|
4730
4982
|
}));
|
|
4731
|
-
if (server?.cors === false) app.use("*", (0, hono_timeout.timeout)(server?.timeout ??
|
|
4983
|
+
if (server?.cors === false) app.use("*", (0, hono_timeout.timeout)(server?.timeout ?? 18e4));
|
|
4732
4984
|
else {
|
|
4733
4985
|
const hasAuth = !!server?.auth;
|
|
4734
|
-
app.use("*", (0, hono_timeout.timeout)(server?.timeout ??
|
|
4986
|
+
app.use("*", (0, hono_timeout.timeout)(server?.timeout ?? 18e4), async (c, next) => {
|
|
4735
4987
|
const pathname = new URL(c.req.url).pathname;
|
|
4736
4988
|
const method = c.req.method === "OPTIONS" ? c.req.header("Access-Control-Request-Method") ?? c.req.method : c.req.method;
|
|
4737
4989
|
const routeCors = getRouteCorsConfig(processedRoutes, pathname, method);
|
|
4738
|
-
|
|
4990
|
+
const corsOptions = routeCors ? getCorsConfig(routeCors, false) : getCorsConfig(server?.cors, hasAuth);
|
|
4991
|
+
return (0, hono_cors.cors)(corsOptions)(c, next);
|
|
4739
4992
|
});
|
|
4740
4993
|
}
|
|
4741
4994
|
app.get("/health", describeRoute({
|
|
@@ -4804,8 +5057,8 @@ async function createHonoServer(mastra, options = { tools: {} }) {
|
|
|
4804
5057
|
const studioPath = getStudioPath();
|
|
4805
5058
|
app.use(`${studioBasePath}/assets/*`, serveStatic({
|
|
4806
5059
|
root: (0, path.join)(studioPath, "assets"),
|
|
4807
|
-
rewriteRequestPath: (path
|
|
4808
|
-
let rewritten = path
|
|
5060
|
+
rewriteRequestPath: (path) => {
|
|
5061
|
+
let rewritten = path;
|
|
4809
5062
|
if (studioBasePath && rewritten.startsWith(studioBasePath)) rewritten = rewritten.slice(studioBasePath.length);
|
|
4810
5063
|
if (rewritten.startsWith("/assets")) rewritten = rewritten.slice(7);
|
|
4811
5064
|
return rewritten;
|
|
@@ -4818,7 +5071,8 @@ async function createHonoServer(mastra, options = { tools: {} }) {
|
|
|
4818
5071
|
if (requestPath.includes(".") && !requestPath.endsWith(".html")) return await next();
|
|
4819
5072
|
const isStudioRoute = studioBasePath === "" || requestPath === studioBasePath || requestPath.startsWith(`${studioBasePath}/`);
|
|
4820
5073
|
if (options?.studio && isStudioRoute) {
|
|
4821
|
-
|
|
5074
|
+
const studioPath = getStudioPath();
|
|
5075
|
+
let indexHtml = await (0, fs_promises.readFile)((0, path.join)(studioPath, "index.html"), "utf-8");
|
|
4822
5076
|
const port = serverOptions?.port ?? (Number(process.env.PORT) || 4111);
|
|
4823
5077
|
const hideCloudCta = process.env.MASTRA_HIDE_CLOUD_CTA === "true";
|
|
4824
5078
|
const host = serverOptions?.host ?? process.env.MASTRA_HOST ?? "localhost";
|
|
@@ -4869,9 +5123,9 @@ async function createHonoServer(mastra, options = { tools: {} }) {
|
|
|
4869
5123
|
const studioPath = studioBasePath ? `${studioBasePath}/*` : "*";
|
|
4870
5124
|
app.use(studioPath, serveStatic({
|
|
4871
5125
|
root: studioRootPath,
|
|
4872
|
-
rewriteRequestPath: (path
|
|
4873
|
-
if (studioBasePath && path
|
|
4874
|
-
return path
|
|
5126
|
+
rewriteRequestPath: (path) => {
|
|
5127
|
+
if (studioBasePath && path.startsWith(studioBasePath)) return path.slice(studioBasePath.length);
|
|
5128
|
+
return path;
|
|
4875
5129
|
}
|
|
4876
5130
|
}));
|
|
4877
5131
|
}
|