@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAIlD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAKhE,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;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAIlD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAKhE,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;2CA4bhE;AAED,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAmC,mDAmMlG"}
|
package/dist/server/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { d as normalizeStudioBase, n as escapeStudioHtmlValue, o as injectStudioHtmlConfig } from "../utils-Bl3Lm7SI.js";
|
|
2
|
-
import "../index-CLddUTqr-
|
|
2
|
+
import "../index-CLddUTqr-86A1rnBL.js";
|
|
3
3
|
import { createReadStream, existsSync, statSync } from "fs";
|
|
4
4
|
import { readFile } from "fs/promises";
|
|
5
5
|
import { dirname, join } from "path";
|
|
@@ -18,8 +18,8 @@ import util from "util";
|
|
|
18
18
|
import { Buffer as Buffer$1 } from "buffer";
|
|
19
19
|
import { bodyLimit } from "hono/body-limit";
|
|
20
20
|
import { stream } from "hono/streaming";
|
|
21
|
-
import "@mastra/core/request-context";
|
|
22
|
-
import { findMatchingCustomRoute } from "@mastra/server/auth";
|
|
21
|
+
import { RequestContext } from "@mastra/core/request-context";
|
|
22
|
+
import { coreAuthMiddleware, findMatchingCustomRoute, isCustomRoutePublic } from "@mastra/server/auth";
|
|
23
23
|
import { ViewerRegistry, handleInputMessage } from "@mastra/server/browser-stream";
|
|
24
24
|
import { InMemoryTaskStore } from "@mastra/server/a2a/store";
|
|
25
25
|
import { Hono } from "hono";
|
|
@@ -812,7 +812,7 @@ const buildOutgoingHttpHeaders = (headers, defaultContentType) => {
|
|
|
812
812
|
const outgoingEnded = Symbol("outgoingEnded");
|
|
813
813
|
const incomingDraining = Symbol("incomingDraining");
|
|
814
814
|
const DRAIN_TIMEOUT_MS = 500;
|
|
815
|
-
const MAX_DRAIN_BYTES =
|
|
815
|
+
const MAX_DRAIN_BYTES = 67108864;
|
|
816
816
|
const drainIncoming = (incoming) => {
|
|
817
817
|
const incomingWithDrainState = incoming;
|
|
818
818
|
if (incoming.destroyed || incomingWithDrainState[incomingDraining]) return;
|
|
@@ -1759,13 +1759,15 @@ var ERR_INVALID_ARG_TYPE = class extends TypeError {
|
|
|
1759
1759
|
}
|
|
1760
1760
|
if (other.length > 0) msg += " or ";
|
|
1761
1761
|
}
|
|
1762
|
-
if (other.length > 0)
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1762
|
+
if (other.length > 0) {
|
|
1763
|
+
if (other.length > 2) {
|
|
1764
|
+
const last = other.pop();
|
|
1765
|
+
msg += `one of ${other.join(", ")}, or ${last}`;
|
|
1766
|
+
} else if (other.length === 2) msg += `one of ${other[0]} or ${other[1]}`;
|
|
1767
|
+
else {
|
|
1768
|
+
if (other[0].toLowerCase() !== other[0]) msg += "an ";
|
|
1769
|
+
msg += `${other[0]}`;
|
|
1770
|
+
}
|
|
1769
1771
|
}
|
|
1770
1772
|
msg += `. Received ${determineSpecificType(actual)}`;
|
|
1771
1773
|
super(msg);
|
|
@@ -1966,11 +1968,13 @@ var FetchIncomingMessage = class extends Readable {
|
|
|
1966
1968
|
field = field.slice(1);
|
|
1967
1969
|
if (typeof dest[field] === "string") dest[field] += (flag === 0 ? ", " : "; ") + value;
|
|
1968
1970
|
else dest[field] = value;
|
|
1969
|
-
} else if (flag === 1)
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
else
|
|
1973
|
-
|
|
1971
|
+
} else if (flag === 1) {
|
|
1972
|
+
if (dest["set-cookie"] !== void 0) dest["set-cookie"].push(value);
|
|
1973
|
+
else dest["set-cookie"] = [value];
|
|
1974
|
+
} else if (this.joinDuplicateHeaders) {
|
|
1975
|
+
if (dest[field] === void 0) dest[field] = value;
|
|
1976
|
+
else dest[field] += ", " + value;
|
|
1977
|
+
} else if (dest[field] === void 0) dest[field] = value;
|
|
1974
1978
|
}
|
|
1975
1979
|
_addHeaderLineDistinct(field, value, dest) {
|
|
1976
1980
|
field = field.toLowerCase();
|
|
@@ -2051,7 +2055,6 @@ function matchKnownFields(field, lowercased = false) {
|
|
|
2051
2055
|
case 19:
|
|
2052
2056
|
if (field === "Proxy-Authorization" || field === "proxy-authorization") return "proxy-authorization";
|
|
2053
2057
|
if (field === "If-Unmodified-Since" || field === "if-unmodified-since") return "if-unmodified-since";
|
|
2054
|
-
break;
|
|
2055
2058
|
}
|
|
2056
2059
|
if (lowercased) return "\0" + field;
|
|
2057
2060
|
return matchKnownFields(field.toLowerCase(), true);
|
|
@@ -2100,7 +2103,7 @@ function utcDate() {
|
|
|
2100
2103
|
//#endregion
|
|
2101
2104
|
//#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
|
|
2102
2105
|
function getDefaultHighWaterMark(objectMode) {
|
|
2103
|
-
return objectMode ? 16 :
|
|
2106
|
+
return objectMode ? 16 : 65536;
|
|
2104
2107
|
}
|
|
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/http-common.js
|
|
@@ -2388,15 +2391,16 @@ var FetchOutgoingMessage = class extends Writable {
|
|
|
2388
2391
|
const entry = headers[key];
|
|
2389
2392
|
processHeader(this, state, entry[0], entry[1], false);
|
|
2390
2393
|
}
|
|
2391
|
-
else if (Array.isArray(headers))
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2394
|
+
else if (Array.isArray(headers)) {
|
|
2395
|
+
if (headers.length && Array.isArray(headers[0])) for (let i = 0; i < headers.length; i++) {
|
|
2396
|
+
const entry = headers[i];
|
|
2397
|
+
processHeader(this, state, entry[0], entry[1], true);
|
|
2398
|
+
}
|
|
2399
|
+
else {
|
|
2400
|
+
if (headers.length % 2 !== 0) throw new ERR_INVALID_ARG_VALUE("headers", headers);
|
|
2401
|
+
for (let n = 0; n < headers.length; n += 2) processHeader(this, state, headers[n], headers[n + 1], true);
|
|
2402
|
+
}
|
|
2403
|
+
} else for (const key in headers) if (headers.hasOwnProperty(key)) {
|
|
2400
2404
|
const _headers = headers;
|
|
2401
2405
|
processHeader(this, state, key, _headers[key], true);
|
|
2402
2406
|
}
|
|
@@ -2425,13 +2429,15 @@ var FetchOutgoingMessage = class extends Writable {
|
|
|
2425
2429
|
header += "Connection: close\r\n";
|
|
2426
2430
|
}
|
|
2427
2431
|
}
|
|
2428
|
-
if (!state.contLen && !state.te)
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2432
|
+
if (!state.contLen && !state.te) {
|
|
2433
|
+
if (!this._hasBody) this.chunkedEncoding = false;
|
|
2434
|
+
else if (!this.useChunkedEncodingByDefault) this._last = true;
|
|
2435
|
+
else if (!state.trailer && !this._removedContLen && typeof this._contentLength === "number") header += "Content-Length: " + this._contentLength + "\r\n";
|
|
2436
|
+
else if (!this._removedTE) {
|
|
2437
|
+
header += "Transfer-Encoding: chunked\r\n";
|
|
2438
|
+
this.chunkedEncoding = true;
|
|
2439
|
+
} else this._last = true;
|
|
2440
|
+
}
|
|
2435
2441
|
if (this.chunkedEncoding !== true && state.trailer) throw new ERR_HTTP_TRAILER_INVALID();
|
|
2436
2442
|
this._header = header + "\r\n";
|
|
2437
2443
|
this._headerSent = false;
|
|
@@ -2575,9 +2581,7 @@ var FetchOutgoingMessage = class extends Writable {
|
|
|
2575
2581
|
case "transfer-encoding":
|
|
2576
2582
|
this._removedTE = true;
|
|
2577
2583
|
break;
|
|
2578
|
-
case "date":
|
|
2579
|
-
this.sendDate = false;
|
|
2580
|
-
break;
|
|
2584
|
+
case "date": this.sendDate = false;
|
|
2581
2585
|
}
|
|
2582
2586
|
if (this[kOutHeaders] !== null) delete this[kOutHeaders][key];
|
|
2583
2587
|
}
|
|
@@ -2648,8 +2652,10 @@ var FetchOutgoingMessage = class extends Writable {
|
|
|
2648
2652
|
if (this._writtenDataBuffer != null) this._writtenDataBuffer.cork();
|
|
2649
2653
|
write_(this, chunk, encoding, null, true);
|
|
2650
2654
|
} else if (this.finished) {
|
|
2651
|
-
if (typeof callback === "function")
|
|
2652
|
-
|
|
2655
|
+
if (typeof callback === "function") {
|
|
2656
|
+
if (!this.writableFinished) this.on("finish", callback);
|
|
2657
|
+
else callback(new ERR_STREAM_ALREADY_FINISHED("end"));
|
|
2658
|
+
}
|
|
2653
2659
|
return this;
|
|
2654
2660
|
} else if (!this._header) {
|
|
2655
2661
|
if (this._writtenDataBuffer != null) this._writtenDataBuffer.cork();
|
|
@@ -2714,8 +2720,10 @@ var FetchOutgoingMessage = class extends Writable {
|
|
|
2714
2720
|
};
|
|
2715
2721
|
function processHeader(self, state, key, value, validate) {
|
|
2716
2722
|
if (validate) validateHeaderName(key);
|
|
2717
|
-
if (isContentDispositionField(key) && self._contentLength)
|
|
2718
|
-
|
|
2723
|
+
if (isContentDispositionField(key) && self._contentLength) {
|
|
2724
|
+
if (Array.isArray(value)) for (let i = 0; i < value.length; i++) value[i] = String(Buffer$1.from(String(value[i]), "latin1"));
|
|
2725
|
+
else value = String(Buffer$1.from(String(value), "latin1"));
|
|
2726
|
+
}
|
|
2719
2727
|
if (Array.isArray(value)) {
|
|
2720
2728
|
if ((value.length < 2 || !isCookieField(key)) && (!self[kUniqueHeaders] || !self[kUniqueHeaders].has(key.toLowerCase()))) {
|
|
2721
2729
|
for (let i = 0; i < value.length; i++) storeHeader(self, state, key, value[i], validate);
|
|
@@ -2765,9 +2773,7 @@ function matchHeader(self, state, field, value) {
|
|
|
2765
2773
|
case "trailer":
|
|
2766
2774
|
state[field] = true;
|
|
2767
2775
|
break;
|
|
2768
|
-
case "keep-alive":
|
|
2769
|
-
self._defaultKeepAlive = false;
|
|
2770
|
-
break;
|
|
2776
|
+
case "keep-alive": self._defaultKeepAlive = false;
|
|
2771
2777
|
}
|
|
2772
2778
|
}
|
|
2773
2779
|
function onError(msg, err, callback) {
|
|
@@ -2810,10 +2816,12 @@ function write_(msg, chunk, encoding, callback, fromEnd) {
|
|
|
2810
2816
|
}
|
|
2811
2817
|
msg._implicitHeader();
|
|
2812
2818
|
}
|
|
2813
|
-
if (!msg._hasBody)
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2819
|
+
if (!msg._hasBody) {
|
|
2820
|
+
if (msg[kRejectNonStandardBodyWrites]) throw new ERR_HTTP_BODY_NOT_ALLOWED();
|
|
2821
|
+
else {
|
|
2822
|
+
setTimeout(callback, 0);
|
|
2823
|
+
return true;
|
|
2824
|
+
}
|
|
2817
2825
|
}
|
|
2818
2826
|
if (!fromEnd && msg._writtenDataBuffer != null && !msg._writtenDataBuffer.writableCorked) {
|
|
2819
2827
|
msg._writtenDataBuffer.cork();
|
|
@@ -3011,8 +3019,10 @@ var FetchServerResponse = class FetchServerResponse extends FetchOutgoingMessage
|
|
|
3011
3019
|
}
|
|
3012
3020
|
data = data.slice(this.writtenHeaderBytes);
|
|
3013
3021
|
}
|
|
3014
|
-
if (typeof data === "string")
|
|
3015
|
-
|
|
3022
|
+
if (typeof data === "string") {
|
|
3023
|
+
if (encoding === void 0 || encoding === "utf8" || encoding === "utf-8") data = FetchServerResponse.encoder.encode(data);
|
|
3024
|
+
else data = Buffer$1.from(data, encoding ?? void 0);
|
|
3025
|
+
}
|
|
3016
3026
|
return data ?? Buffer$1.from([]);
|
|
3017
3027
|
}
|
|
3018
3028
|
_finish() {
|
|
@@ -3196,6 +3206,191 @@ function propagateClientDisconnect(fetchResponse, res) {
|
|
|
3196
3206
|
headers: fetchResponse.headers
|
|
3197
3207
|
});
|
|
3198
3208
|
}
|
|
3209
|
+
function createAuthMiddleware({ mastra, requiresAuth = true }) {
|
|
3210
|
+
return async (c, next) => {
|
|
3211
|
+
if (!requiresAuth) return next();
|
|
3212
|
+
const authConfig = mastra.getServer()?.auth;
|
|
3213
|
+
if (!authConfig) return next();
|
|
3214
|
+
const requestContext = c.get("requestContext") ?? new RequestContext();
|
|
3215
|
+
c.set("requestContext", requestContext);
|
|
3216
|
+
c.set("mastra", c.get("mastra") ?? mastra);
|
|
3217
|
+
const path = c.req.path;
|
|
3218
|
+
const method = c.req.method;
|
|
3219
|
+
const customRouteAuthConfig = new Map(c.get("customRouteAuthConfig") ?? []);
|
|
3220
|
+
if (!isCustomRoutePublic(path, method, customRouteAuthConfig)) customRouteAuthConfig.set(`${method}:${path}`, true);
|
|
3221
|
+
const authHeader = c.req.header("Authorization");
|
|
3222
|
+
let token = authHeader ? authHeader.replace("Bearer ", "") : null;
|
|
3223
|
+
if (!token) token = c.req.query("apiKey") || null;
|
|
3224
|
+
const result = await coreAuthMiddleware({
|
|
3225
|
+
path,
|
|
3226
|
+
method,
|
|
3227
|
+
getHeader: (name) => c.req.header(name),
|
|
3228
|
+
mastra,
|
|
3229
|
+
authConfig,
|
|
3230
|
+
customRouteAuthConfig,
|
|
3231
|
+
requestContext,
|
|
3232
|
+
rawRequest: c.req.raw,
|
|
3233
|
+
token,
|
|
3234
|
+
buildAuthorizeContext: () => c
|
|
3235
|
+
});
|
|
3236
|
+
for (const [key, value] of Object.entries(result.headers ?? {})) c.header(key, value, key.toLowerCase() === "set-cookie" ? { append: true } : void 0);
|
|
3237
|
+
if (result.action === "next") return next();
|
|
3238
|
+
return c.json(result.body, result.status);
|
|
3239
|
+
};
|
|
3240
|
+
}
|
|
3241
|
+
const TICKET_BYTES = 32;
|
|
3242
|
+
/**
|
|
3243
|
+
* How long an issued ticket stays valid. A ticket is minted immediately before
|
|
3244
|
+
* the socket is opened, so this only has to cover the round trip plus the
|
|
3245
|
+
* handshake — short enough that a ticket leaked from a log is useless by the
|
|
3246
|
+
* time anyone can act on it.
|
|
3247
|
+
*/
|
|
3248
|
+
const UPGRADE_TICKET_TTL_MS = 3e4;
|
|
3249
|
+
/**
|
|
3250
|
+
* Ceiling on tracked per-agent issuance counters, so the limiter can't grow
|
|
3251
|
+
* without bound as agent ids are invented. Counters are evicted oldest first.
|
|
3252
|
+
*/
|
|
3253
|
+
const MAX_TRACKED_AGENTS = 500;
|
|
3254
|
+
/** 256 bits of base64url, so the ticket can't be guessed or enumerated. */
|
|
3255
|
+
function createTicketValue() {
|
|
3256
|
+
const bytes = new Uint8Array(TICKET_BYTES);
|
|
3257
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
3258
|
+
return btoa(String.fromCharCode(...bytes)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
3259
|
+
}
|
|
3260
|
+
/**
|
|
3261
|
+
* Short-lived, single-use credentials for browser WebSocket upgrades.
|
|
3262
|
+
*
|
|
3263
|
+
* A browser cannot set an `Authorization` header on a WebSocket handshake, so a
|
|
3264
|
+
* deployment that authenticates with a header token would otherwise have to put
|
|
3265
|
+
* that reusable token in the handshake URL, where proxies and access logs can
|
|
3266
|
+
* retain it. Instead the client asks an authenticated HTTP route for a ticket,
|
|
3267
|
+
* and the ticket — worthless once spent, and scoped to one agent and thread —
|
|
3268
|
+
* travels in the URL instead.
|
|
3269
|
+
*
|
|
3270
|
+
* In-process, like the `ViewerRegistry` and the browser sessions it serves: a
|
|
3271
|
+
* screencast is bound to the process holding the browser, so a ticket store
|
|
3272
|
+
* shared across replicas would buy nothing. A ticket presented to a different
|
|
3273
|
+
* replica fails for the same reason the stream itself would.
|
|
3274
|
+
*
|
|
3275
|
+
* Issuance is bounded so the mint endpoint can't be turned into memory or CPU
|
|
3276
|
+
* exhaustion: tickets that are never spent live at most one TTL, a full store
|
|
3277
|
+
* rejects instead of growing, and each agent has a request allowance. Expiry is
|
|
3278
|
+
* swept from the front of the insertion-ordered map, so cleanup costs the
|
|
3279
|
+
* number of entries actually expired rather than a scan of every outstanding
|
|
3280
|
+
* ticket per request.
|
|
3281
|
+
*/
|
|
3282
|
+
var UpgradeTicketStore = class {
|
|
3283
|
+
#tickets = /* @__PURE__ */ new Map();
|
|
3284
|
+
#issuance = /* @__PURE__ */ new Map();
|
|
3285
|
+
#now;
|
|
3286
|
+
constructor(now = () => Date.now()) {
|
|
3287
|
+
this.#now = now;
|
|
3288
|
+
}
|
|
3289
|
+
/**
|
|
3290
|
+
* Issue a ticket bound to one agent and thread. Returns `{ ok: false }` when
|
|
3291
|
+
* the agent exceeded its allowance or the store is at capacity.
|
|
3292
|
+
*/
|
|
3293
|
+
issue(agentId, threadId, ttlMs = UPGRADE_TICKET_TTL_MS) {
|
|
3294
|
+
const now = this.#now();
|
|
3295
|
+
this.#prune(now);
|
|
3296
|
+
if (this.#tickets.size >= 500) return {
|
|
3297
|
+
ok: false,
|
|
3298
|
+
reason: "capacity"
|
|
3299
|
+
};
|
|
3300
|
+
const window = this.#issuance.get(agentId);
|
|
3301
|
+
if (!window || now - window.windowStart >= 6e4) this.#trackIssuance(agentId, {
|
|
3302
|
+
windowStart: now,
|
|
3303
|
+
count: 0
|
|
3304
|
+
});
|
|
3305
|
+
else if (window.count >= 30) return {
|
|
3306
|
+
ok: false,
|
|
3307
|
+
reason: "rate-limited"
|
|
3308
|
+
};
|
|
3309
|
+
this.#issuance.get(agentId).count += 1;
|
|
3310
|
+
const ticket = createTicketValue();
|
|
3311
|
+
this.#tickets.set(ticket, {
|
|
3312
|
+
agentId,
|
|
3313
|
+
threadId,
|
|
3314
|
+
expiresAt: now + ttlMs
|
|
3315
|
+
});
|
|
3316
|
+
return {
|
|
3317
|
+
ok: true,
|
|
3318
|
+
ticket,
|
|
3319
|
+
expiresIn: Math.ceil(ttlMs / 1e3)
|
|
3320
|
+
};
|
|
3321
|
+
}
|
|
3322
|
+
/**
|
|
3323
|
+
* Spend a ticket. Returns `true` only when the ticket is unexpired and was
|
|
3324
|
+
* issued for this exact agent and thread, in which case it is consumed and a
|
|
3325
|
+
* second presentation fails.
|
|
3326
|
+
*/
|
|
3327
|
+
consume(ticket, agentId, threadId) {
|
|
3328
|
+
const entry = this.#tickets.get(ticket);
|
|
3329
|
+
if (!entry) return false;
|
|
3330
|
+
if (entry.expiresAt <= this.#now()) return false;
|
|
3331
|
+
if (entry.agentId !== agentId) return false;
|
|
3332
|
+
if ((entry.threadId ?? void 0) !== (threadId ?? void 0)) return false;
|
|
3333
|
+
this.#tickets.delete(ticket);
|
|
3334
|
+
return true;
|
|
3335
|
+
}
|
|
3336
|
+
/**
|
|
3337
|
+
* Drop expired tickets from the front of the insertion-ordered map. Tickets
|
|
3338
|
+
* are inserted in issue order and share a TTL, so the entries after the first
|
|
3339
|
+
* live one are live too and the sweep can stop there.
|
|
3340
|
+
*/
|
|
3341
|
+
#prune(now) {
|
|
3342
|
+
for (const [ticket, entry] of this.#tickets) {
|
|
3343
|
+
if (entry.expiresAt > now) break;
|
|
3344
|
+
this.#tickets.delete(ticket);
|
|
3345
|
+
}
|
|
3346
|
+
}
|
|
3347
|
+
/** Record an issuance window, evicting the oldest counter when at the cap. */
|
|
3348
|
+
#trackIssuance(agentId, window) {
|
|
3349
|
+
this.#issuance.delete(agentId);
|
|
3350
|
+
this.#issuance.set(agentId, window);
|
|
3351
|
+
if (this.#issuance.size > MAX_TRACKED_AGENTS) {
|
|
3352
|
+
const oldest = this.#issuance.keys().next().value;
|
|
3353
|
+
if (oldest !== void 0) this.#issuance.delete(oldest);
|
|
3354
|
+
}
|
|
3355
|
+
}
|
|
3356
|
+
};
|
|
3357
|
+
const TICKET_BODY_MAX_BYTES = 4096;
|
|
3358
|
+
/**
|
|
3359
|
+
* Resolve an `allowedOrigins` value against the request's `Origin` header.
|
|
3360
|
+
*
|
|
3361
|
+
* Mirrors Hono's `cors.origin` semantics so the same config value means the same
|
|
3362
|
+
* thing on the upgrade as it does on the HTTP routes: `'*'` allows everything,
|
|
3363
|
+
* array entries match literally, and a callback is only an approval when it
|
|
3364
|
+
* returns the request's own origin (the value Hono would echo back) or `'*'`.
|
|
3365
|
+
*/
|
|
3366
|
+
async function isOriginAllowed(allowedOrigins, origin, c) {
|
|
3367
|
+
if (Array.isArray(allowedOrigins)) return allowedOrigins.includes(origin);
|
|
3368
|
+
if (typeof allowedOrigins === "function") {
|
|
3369
|
+
const allowed = await allowedOrigins(origin, c);
|
|
3370
|
+
return allowed === origin || allowed === "*";
|
|
3371
|
+
}
|
|
3372
|
+
return allowedOrigins === "*" || allowedOrigins === origin;
|
|
3373
|
+
}
|
|
3374
|
+
/**
|
|
3375
|
+
* Is the `Origin` header the server's own origin?
|
|
3376
|
+
*
|
|
3377
|
+
* A Studio served by this server connects back to the same host, and operators
|
|
3378
|
+
* don't add their own origin to a CORS allowlist because same-origin requests
|
|
3379
|
+
* never needed CORS. Comparing hosts (rather than scheme + host) keeps that
|
|
3380
|
+
* working behind TLS-terminating proxies, where the server sees `http` while the
|
|
3381
|
+
* browser sends `https`.
|
|
3382
|
+
*/
|
|
3383
|
+
function isSameOrigin(origin, requestHost) {
|
|
3384
|
+
if (!requestHost) return false;
|
|
3385
|
+
let originHost;
|
|
3386
|
+
try {
|
|
3387
|
+
originHost = new URL(origin).host;
|
|
3388
|
+
} catch {
|
|
3389
|
+
return false;
|
|
3390
|
+
}
|
|
3391
|
+
const host = (requestHost.split(",")[0] ?? "").trim();
|
|
3392
|
+
return originHost !== "" && originHost.toLowerCase() === host.toLowerCase();
|
|
3393
|
+
}
|
|
3199
3394
|
/**
|
|
3200
3395
|
* Set up WebSocket-based browser stream endpoint for real-time screencast viewing.
|
|
3201
3396
|
*
|
|
@@ -3205,6 +3400,17 @@ function propagateClientDisconnect(fetchResponse, res) {
|
|
|
3205
3400
|
* - Broadcasts frames to all connected viewers
|
|
3206
3401
|
* - Stops screencast when last viewer disconnects
|
|
3207
3402
|
*
|
|
3403
|
+
* All routes are authenticated with the server's auth configuration. Browsers
|
|
3404
|
+
* cannot attach an `Authorization` header to a WebSocket upgrade, so
|
|
3405
|
+
* session-cookie providers authenticate from the upgrade request's cookies.
|
|
3406
|
+
* Clients that authenticate with a header token instead request a short-lived,
|
|
3407
|
+
* single-use ticket from `POST ${apiPrefix}/agents/:agentId/browser/stream-ticket`
|
|
3408
|
+
* and pass it to the upgrade as `?ticket=`, which keeps the reusable credential
|
|
3409
|
+
* out of the URL. Non-browser clients can pass the token as the `apiKey` query
|
|
3410
|
+
* parameter — use a short-lived token, since a URL can be retained in proxy and
|
|
3411
|
+
* access logs, and prefer the `Authorization` header on the HTTP routes where the
|
|
3412
|
+
* client can set one.
|
|
3413
|
+
*
|
|
3208
3414
|
* **Note**: Requires `ws` package to be installed. If not available, returns null
|
|
3209
3415
|
* and logs a warning. Browser streaming will be disabled but everything else works.
|
|
3210
3416
|
*
|
|
@@ -3220,6 +3426,7 @@ function propagateClientDisconnect(fetchResponse, res) {
|
|
|
3220
3426
|
*
|
|
3221
3427
|
* const app = new Hono();
|
|
3222
3428
|
* const browserStream = await setupBrowserStream(app, {
|
|
3429
|
+
* mastra,
|
|
3223
3430
|
* getToolset: (agentId) => browserToolsets.get(agentId),
|
|
3224
3431
|
* });
|
|
3225
3432
|
*
|
|
@@ -3242,7 +3449,24 @@ async function setupBrowserStream(app, config) {
|
|
|
3242
3449
|
const registry = new ViewerRegistry();
|
|
3243
3450
|
const rawPrefix = config.apiPrefix ?? "/api";
|
|
3244
3451
|
const apiPrefix = (rawPrefix.endsWith("/") ? rawPrefix.slice(0, -1) : rawPrefix) || "/api";
|
|
3245
|
-
|
|
3452
|
+
const authenticate = createAuthMiddleware({ mastra: config.mastra });
|
|
3453
|
+
const upgradeTickets = new UpgradeTicketStore();
|
|
3454
|
+
const authorizeUpgrade = async (c, next) => {
|
|
3455
|
+
const ticket = c.req.query("ticket");
|
|
3456
|
+
if (!ticket) return authenticate(c, next);
|
|
3457
|
+
const agentId = c.req.param("agentId");
|
|
3458
|
+
if (!upgradeTickets.consume(ticket, agentId, c.req.query("threadId"))) return c.json({ error: "Invalid or expired upgrade ticket" }, 401);
|
|
3459
|
+
return next();
|
|
3460
|
+
};
|
|
3461
|
+
const allowedOrigins = config.allowedOrigins;
|
|
3462
|
+
const checkOrigin = async (c, next) => {
|
|
3463
|
+
const origin = c.req.header("origin");
|
|
3464
|
+
if (!allowedOrigins || !origin) return next();
|
|
3465
|
+
if (isSameOrigin(origin, c.req.header("x-forwarded-host") ?? c.req.header("host"))) return next();
|
|
3466
|
+
if (!await isOriginAllowed(allowedOrigins, origin, c)) return c.text("Forbidden", 403);
|
|
3467
|
+
return next();
|
|
3468
|
+
};
|
|
3469
|
+
app.get("/browser/:agentId/stream", checkOrigin, authorizeUpgrade, upgradeWebSocket((c) => {
|
|
3246
3470
|
const agentId = c.req.param("agentId");
|
|
3247
3471
|
const threadId = c.req.query("threadId");
|
|
3248
3472
|
const viewerKey = threadId ? `${agentId}:${threadId}` : agentId;
|
|
@@ -3264,7 +3488,29 @@ async function setupBrowserStream(app, config) {
|
|
|
3264
3488
|
}
|
|
3265
3489
|
};
|
|
3266
3490
|
}));
|
|
3267
|
-
|
|
3491
|
+
const ticketBodyLimit = bodyLimit({
|
|
3492
|
+
maxSize: TICKET_BODY_MAX_BYTES,
|
|
3493
|
+
onError: (c) => c.json({ error: "Request body too large" }, 413)
|
|
3494
|
+
});
|
|
3495
|
+
app.post(`${apiPrefix}/agents/:agentId/browser/stream-ticket`, authenticate, ticketBodyLimit, async (c) => {
|
|
3496
|
+
const agentId = c.req.param("agentId");
|
|
3497
|
+
if (!agentId) return c.json({ error: "Agent ID is required" }, 400);
|
|
3498
|
+
let threadId = c.req.query("threadId");
|
|
3499
|
+
try {
|
|
3500
|
+
const body = await c.req.json();
|
|
3501
|
+
if (!threadId && typeof body?.threadId === "string") threadId = body.threadId;
|
|
3502
|
+
} catch {}
|
|
3503
|
+
const issued = upgradeTickets.issue(agentId, threadId);
|
|
3504
|
+
if (!issued.ok) {
|
|
3505
|
+
const error = issued.reason === "capacity" ? "Too many outstanding browser stream upgrade tickets" : "Too many browser stream upgrade tickets requested";
|
|
3506
|
+
return c.json({ error }, 429);
|
|
3507
|
+
}
|
|
3508
|
+
return c.json({
|
|
3509
|
+
ticket: issued.ticket,
|
|
3510
|
+
expiresIn: issued.expiresIn
|
|
3511
|
+
});
|
|
3512
|
+
});
|
|
3513
|
+
app.get(`${apiPrefix}/agents/:agentId/browser/session`, authenticate, async (c) => {
|
|
3268
3514
|
const agentId = c.req.param("agentId");
|
|
3269
3515
|
if (!agentId) return c.json({ error: "Agent ID is required" }, 400);
|
|
3270
3516
|
const threadId = c.req.query("threadId");
|
|
@@ -3279,7 +3525,7 @@ async function setupBrowserStream(app, config) {
|
|
|
3279
3525
|
screencastAvailable: true
|
|
3280
3526
|
});
|
|
3281
3527
|
});
|
|
3282
|
-
app.post(`${apiPrefix}/agents/:agentId/browser/close`, async (c) => {
|
|
3528
|
+
app.post(`${apiPrefix}/agents/:agentId/browser/close`, authenticate, ticketBodyLimit, async (c) => {
|
|
3283
3529
|
const agentId = c.req.param("agentId");
|
|
3284
3530
|
if (!agentId) return c.json({ error: "Agent ID is required" }, 400);
|
|
3285
3531
|
const toolset = await config.getToolset(agentId);
|
|
@@ -3349,7 +3595,7 @@ const BODY_METHODS = /* @__PURE__ */ new Set([
|
|
|
3349
3595
|
"PATCH",
|
|
3350
3596
|
"DELETE"
|
|
3351
3597
|
]);
|
|
3352
|
-
var MastraServer$
|
|
3598
|
+
var MastraServer$2 = class extends MastraServer {
|
|
3353
3599
|
createContextMiddleware() {
|
|
3354
3600
|
return async (c, next) => {
|
|
3355
3601
|
if (this.hasCustomRouteHandler && BODY_METHODS.has(c.req.method) && c.req.raw.body) c.set(MASTRA_PRISTINE_REQUEST_KEY, c.req.raw.clone());
|
|
@@ -3891,7 +4137,7 @@ var MastraServer$1 = class extends MastraServer {
|
|
|
3891
4137
|
}
|
|
3892
4138
|
};
|
|
3893
4139
|
//#endregion
|
|
3894
|
-
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/hono-openapi/1.3.1/
|
|
4140
|
+
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/hono-openapi/1.3.1/158235e7235efea6160a30c3ca102ac021a6d2f9183c16a3ddab0c84f82188b4/node_modules/hono-openapi/dist/index.js
|
|
3895
4141
|
const uniqueSymbol = Symbol("openapi");
|
|
3896
4142
|
function describeRoute(spec) {
|
|
3897
4143
|
const middleware = async (_c, next) => {
|
|
@@ -4592,7 +4838,10 @@ function welcomeHtml(apiPrefix = "/api") {
|
|
|
4592
4838
|
const getStudioPath = () => {
|
|
4593
4839
|
if (process.env.MASTRA_STUDIO_PATH) return process.env.MASTRA_STUDIO_PATH;
|
|
4594
4840
|
let __dirname = ".";
|
|
4595
|
-
if (import.meta.url)
|
|
4841
|
+
if (import.meta.url) {
|
|
4842
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
4843
|
+
__dirname = dirname(__filename);
|
|
4844
|
+
}
|
|
4596
4845
|
return process.env.MASTRA_STUDIO_PATH || join(__dirname, "studio");
|
|
4597
4846
|
};
|
|
4598
4847
|
function isSchemaApiRoute(route) {
|
|
@@ -4678,10 +4927,10 @@ async function createHonoServer(mastra, options = { tools: {} }) {
|
|
|
4678
4927
|
return errorHandler(err, c, options.isDev);
|
|
4679
4928
|
});
|
|
4680
4929
|
const bodyLimitOptions = {
|
|
4681
|
-
maxSize: server?.bodySizeLimit ??
|
|
4930
|
+
maxSize: server?.bodySizeLimit ?? 4718592,
|
|
4682
4931
|
onError: () => ({ error: "Request body too large" })
|
|
4683
4932
|
};
|
|
4684
|
-
const honoServerAdapter = new MastraServer$
|
|
4933
|
+
const honoServerAdapter = new MastraServer$2({
|
|
4685
4934
|
app,
|
|
4686
4935
|
mastra,
|
|
4687
4936
|
tools: options.tools,
|
|
@@ -4696,7 +4945,10 @@ async function createHonoServer(mastra, options = { tools: {} }) {
|
|
|
4696
4945
|
honoServerAdapter.registerContextMiddleware();
|
|
4697
4946
|
const serverMiddleware = mastra.getServerMiddleware?.();
|
|
4698
4947
|
if (serverMiddleware && serverMiddleware.length > 0) for (const m of serverMiddleware) app.use(m.path, skipIfFrameworkPublic(m.handler));
|
|
4948
|
+
const browserStreamOrigins = server?.cors && typeof server.cors === "object" && "origin" in server.cors ? server.cors.origin : void 0;
|
|
4699
4949
|
const browserStreamSetup = options.browserStream === false ? null : await setupBrowserStream(app, {
|
|
4950
|
+
mastra,
|
|
4951
|
+
allowedOrigins: browserStreamOrigins,
|
|
4700
4952
|
getToolset: async (agentId) => {
|
|
4701
4953
|
const resolveBrowser = async (agent) => {
|
|
4702
4954
|
if (!agent) return void 0;
|
|
@@ -4723,14 +4975,15 @@ async function createHonoServer(mastra, options = { tools: {} }) {
|
|
|
4723
4975
|
hasSession: false,
|
|
4724
4976
|
screencastAvailable: false
|
|
4725
4977
|
}));
|
|
4726
|
-
if (server?.cors === false) app.use("*", timeout(server?.timeout ??
|
|
4978
|
+
if (server?.cors === false) app.use("*", timeout(server?.timeout ?? 18e4));
|
|
4727
4979
|
else {
|
|
4728
4980
|
const hasAuth = !!server?.auth;
|
|
4729
|
-
app.use("*", timeout(server?.timeout ??
|
|
4981
|
+
app.use("*", timeout(server?.timeout ?? 18e4), async (c, next) => {
|
|
4730
4982
|
const pathname = new URL(c.req.url).pathname;
|
|
4731
4983
|
const method = c.req.method === "OPTIONS" ? c.req.header("Access-Control-Request-Method") ?? c.req.method : c.req.method;
|
|
4732
4984
|
const routeCors = getRouteCorsConfig(processedRoutes, pathname, method);
|
|
4733
|
-
|
|
4985
|
+
const corsOptions = routeCors ? getCorsConfig(routeCors, false) : getCorsConfig(server?.cors, hasAuth);
|
|
4986
|
+
return cors(corsOptions)(c, next);
|
|
4734
4987
|
});
|
|
4735
4988
|
}
|
|
4736
4989
|
app.get("/health", describeRoute({
|
|
@@ -4813,7 +5066,8 @@ async function createHonoServer(mastra, options = { tools: {} }) {
|
|
|
4813
5066
|
if (requestPath.includes(".") && !requestPath.endsWith(".html")) return await next();
|
|
4814
5067
|
const isStudioRoute = studioBasePath === "" || requestPath === studioBasePath || requestPath.startsWith(`${studioBasePath}/`);
|
|
4815
5068
|
if (options?.studio && isStudioRoute) {
|
|
4816
|
-
|
|
5069
|
+
const studioPath = getStudioPath();
|
|
5070
|
+
let indexHtml = await readFile(join(studioPath, "index.html"), "utf-8");
|
|
4817
5071
|
const port = serverOptions?.port ?? (Number(process.env.PORT) || 4111);
|
|
4818
5072
|
const hideCloudCta = process.env.MASTRA_HIDE_CLOUD_CTA === "true";
|
|
4819
5073
|
const host = serverOptions?.host ?? process.env.MASTRA_HOST ?? "localhost";
|