@mastra/hono 0.0.0-trace-timeline-update-20251121114225 → 0.0.2-beta.1
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 +51 -4
- package/dist/auth-middleware.d.ts +11 -0
- package/dist/auth-middleware.d.ts.map +1 -0
- package/dist/index.cjs +164 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +165 -36
- package/dist/index.js.map +1 -1
- package/package.json +11 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
# @mastra/pg
|
|
2
2
|
|
|
3
|
-
## 0.0.
|
|
3
|
+
## 0.0.2-beta.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Unified MastraServer API with MCP transport routes ([#10644](https://github.com/mastra-ai/mastra/pull/10644))
|
|
8
|
+
|
|
9
|
+
**Breaking Changes:**
|
|
10
|
+
- Renamed `HonoServerAdapter` to `MastraServer` in `@mastra/hono`
|
|
11
|
+
- Renamed `ExpressServerAdapter` to `MastraServer` in `@mastra/express`
|
|
12
|
+
- Configuration now passed to constructor instead of separate method calls
|
|
13
|
+
- Renamed base class from `ServerAdapter` to `MastraServerBase` in `@mastra/server`
|
|
14
|
+
|
|
15
|
+
**New Features:**
|
|
16
|
+
- Added MCP transport routes (HTTP and SSE) to server adapters
|
|
17
|
+
- MCP endpoints available at `/api/mcp/:serverId/mcp` (HTTP) and `/api/mcp/:serverId/sse` (SSE)
|
|
18
|
+
- Added `express.json()` middleware compatibility for MCP routes
|
|
19
|
+
- Moved authentication helpers from deployer to `@mastra/server/auth`
|
|
20
|
+
|
|
21
|
+
**Testing:**
|
|
22
|
+
- Added shared MCP route and transport test suites in `@internal/server-adapter-test-utils`
|
|
23
|
+
- Added comprehensive MCP endpoint tests for both Hono and Express adapters
|
|
24
|
+
- Added GitHub Actions workflow for server adapter CI testing
|
|
25
|
+
|
|
26
|
+
- Allow direct access to server app handle directly from Mastra instance. ([#10598](https://github.com/mastra-ai/mastra/pull/10598))
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
// Before: HTTP request to localhost
|
|
30
|
+
const response = await fetch(`http://localhost:5000/api/tools`);
|
|
31
|
+
|
|
32
|
+
// After: Direct call via app.fetch()
|
|
33
|
+
const app = mastra.getServerApp<Hono>();
|
|
34
|
+
const response = await app.fetch(new Request('http://internal/api/tools'));
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
- Added `mastra.getServerApp<T>()` to access the underlying Hono/Express app
|
|
38
|
+
- Added `mastra.getMastraServer()` and `mastra.setMastraServer()` for adapter access
|
|
39
|
+
- Added `MastraServerBase` class in `@mastra/core/server` for adapter implementations
|
|
40
|
+
- Server adapters now auto-register with Mastra in their constructor
|
|
41
|
+
|
|
42
|
+
- Add stream data redaction to prevent sensitive information leaks in agent stream API responses. ([#10705](https://github.com/mastra-ai/mastra/pull/10705))
|
|
43
|
+
|
|
44
|
+
The `stream` API endpoint now automatically redacts `request` data from stream chunks (`step-start`, `step-finish`, `finish`) which could contain system prompts, tool definitions, and API keys. Redaction is enabled by default and can be disabled for debugging/internal services via `streamOptions.redact`.
|
|
45
|
+
|
|
46
|
+
- Updated dependencies [[`ac0d2f4`](https://github.com/mastra-ai/mastra/commit/ac0d2f4ff8831f72c1c66c2be809706d17f65789), [`1a0d3fc`](https://github.com/mastra-ai/mastra/commit/1a0d3fc811482c9c376cdf79ee615c23bae9b2d6), [`85a628b`](https://github.com/mastra-ai/mastra/commit/85a628b1224a8f64cd82ea7f033774bf22df7a7e), [`c237233`](https://github.com/mastra-ai/mastra/commit/c23723399ccedf7f5744b3f40997b79246bfbe64), [`15f9e21`](https://github.com/mastra-ai/mastra/commit/15f9e216177201ea6e3f6d0bfb063fcc0953444f), [`ff94dea`](https://github.com/mastra-ai/mastra/commit/ff94dea935f4e34545c63bcb6c29804732698809), [`5b2ff46`](https://github.com/mastra-ai/mastra/commit/5b2ff4651df70c146523a7fca773f8eb0a2272f8), [`db41688`](https://github.com/mastra-ai/mastra/commit/db4168806d007417e2e60b4f68656dca4e5f40c9), [`5ca599d`](https://github.com/mastra-ai/mastra/commit/5ca599d0bb59a1595f19f58473fcd67cc71cef58), [`bff1145`](https://github.com/mastra-ai/mastra/commit/bff114556b3cbadad9b2768488708f8ad0e91475), [`5c8ca24`](https://github.com/mastra-ai/mastra/commit/5c8ca247094e0cc2cdbd7137822fb47241f86e77), [`e191844`](https://github.com/mastra-ai/mastra/commit/e1918444ca3f80e82feef1dad506cd4ec6e2875f), [`22553f1`](https://github.com/mastra-ai/mastra/commit/22553f11c63ee5e966a9c034a349822249584691), [`7237163`](https://github.com/mastra-ai/mastra/commit/72371635dbf96a87df4b073cc48fc655afbdce3d), [`2500740`](https://github.com/mastra-ai/mastra/commit/2500740ea23da067d6e50ec71c625ab3ce275e64), [`873ecbb`](https://github.com/mastra-ai/mastra/commit/873ecbb517586aa17d2f1e99283755b3ebb2863f), [`4f9bbe5`](https://github.com/mastra-ai/mastra/commit/4f9bbe5968f42c86f4930b8193de3c3c17e5bd36), [`02e51fe`](https://github.com/mastra-ai/mastra/commit/02e51feddb3d4155cfbcc42624fd0d0970d032c0), [`8f3fa3a`](https://github.com/mastra-ai/mastra/commit/8f3fa3a652bb77da092f913ec51ae46e3a7e27dc), [`cd29ad2`](https://github.com/mastra-ai/mastra/commit/cd29ad23a255534e8191f249593849ed29160886), [`bdf4d8c`](https://github.com/mastra-ai/mastra/commit/bdf4d8cdc656d8a2c21d81834bfa3bfa70f56c16), [`854e3da`](https://github.com/mastra-ai/mastra/commit/854e3dad5daac17a91a20986399d3a51f54bf68b), [`ce18d38`](https://github.com/mastra-ai/mastra/commit/ce18d38678c65870350d123955014a8432075fd9), [`cccf9c8`](https://github.com/mastra-ai/mastra/commit/cccf9c8b2d2dfc1a5e63919395b83d78c89682a0), [`5a9bafc`](https://github.com/mastra-ai/mastra/commit/5a9bafcaaa859898e954456e781a1552dc0ad4f1), [`61a5705`](https://github.com/mastra-ai/mastra/commit/61a570551278b6743e64243b3ce7d73de915ca8a), [`db70a48`](https://github.com/mastra-ai/mastra/commit/db70a48aeeeeb8e5f92007e8ede52c364ce15287), [`f0fdc14`](https://github.com/mastra-ai/mastra/commit/f0fdc14ee233d619266b3d2bbdeea7d25cfc6d13), [`db18bc9`](https://github.com/mastra-ai/mastra/commit/db18bc9c3825e2c1a0ad9a183cc9935f6691bfa1), [`9b37b56`](https://github.com/mastra-ai/mastra/commit/9b37b565e1f2a76c24f728945cc740c2b09be9da), [`41a23c3`](https://github.com/mastra-ai/mastra/commit/41a23c32f9877d71810f37e24930515df2ff7a0f), [`5d171ad`](https://github.com/mastra-ai/mastra/commit/5d171ad9ef340387276b77c2bb3e83e83332d729), [`f03ae60`](https://github.com/mastra-ai/mastra/commit/f03ae60500fe350c9d828621006cdafe1975fdd8), [`d1e74a0`](https://github.com/mastra-ai/mastra/commit/d1e74a0a293866dece31022047f5dbab65a304d0), [`39e7869`](https://github.com/mastra-ai/mastra/commit/39e7869bc7d0ee391077ce291474d8a84eedccff), [`e849603`](https://github.com/mastra-ai/mastra/commit/e849603a596269069f58a438b98449ea2770493d), [`5761926`](https://github.com/mastra-ai/mastra/commit/57619260c4a2cdd598763abbacd90de594c6bc76), [`c900fdd`](https://github.com/mastra-ai/mastra/commit/c900fdd504c41348efdffb205cfe80d48c38fa33), [`604a79f`](https://github.com/mastra-ai/mastra/commit/604a79fecf276e26a54a3fe01bb94e65315d2e0e), [`60e6e0f`](https://github.com/mastra-ai/mastra/commit/60e6e0f2913bbb467c64a0013b50509cf5efeb38), [`887f0b4`](https://github.com/mastra-ai/mastra/commit/887f0b4746cdbd7cb7d6b17ac9f82aeb58037ea5), [`2562143`](https://github.com/mastra-ai/mastra/commit/256214336b4faa78646c9c1776612393790d8784), [`ef11a61`](https://github.com/mastra-ai/mastra/commit/ef11a61920fa0ed08a5b7ceedd192875af119749)]:
|
|
47
|
+
- @mastra/core@1.0.0-beta.6
|
|
48
|
+
- @mastra/server@1.0.0-beta.6
|
|
49
|
+
|
|
50
|
+
## 0.0.2-beta.0
|
|
4
51
|
|
|
5
52
|
### Patch Changes
|
|
6
53
|
|
|
@@ -12,9 +59,9 @@
|
|
|
12
59
|
These packages support mastra server routes on express and hono respectively.
|
|
13
60
|
Better abstractions will be built on top of these packages in the near future, enabling users to easily attach mastra routes to any existing server framework.
|
|
14
61
|
|
|
15
|
-
- Updated dependencies [[`2319326`](https://github.com/mastra-ai/mastra/commit/2319326f8c64e503a09bbcf14be2dd65405445e0), [`39c9743`](https://github.com/mastra-ai/mastra/commit/39c97432d084294f8ba85fbf3ef28098ff21459e), [`f743dbb`](https://github.com/mastra-ai/mastra/commit/f743dbb8b40d1627b5c10c0e6fc154f4ebb6e394), [`3852192`](https://github.com/mastra-ai/mastra/commit/3852192c81b2a4f1f883f17d80ce50e0c60dba55), [`fec5129`](https://github.com/mastra-ai/mastra/commit/fec5129de7fc64423ea03661a56cef31dc747a0d), [`60937c1`](https://github.com/mastra-ai/mastra/commit/60937c14d7ff287b0acd16deb15f5e96516d7880), [`0491e7c`](https://github.com/mastra-ai/mastra/commit/0491e7c9b714cb0ba22187ee062147ec2dd7c712), [`f6f4903`](https://github.com/mastra-ai/mastra/commit/f6f4903397314f73362061dc5a3e8e7c61ea34aa), [`0e8ed46`](https://github.com/mastra-ai/mastra/commit/0e8ed467c54d6901a6a365f270ec15d6faadb36c), [`6c049d9`](https://github.com/mastra-ai/mastra/commit/6c049d94063fdcbd5b81c4912a2bf82a92c9cc0b), [`910db9e`](https://github.com/mastra-ai/mastra/commit/910db9e0312888495eb5617b567f247d03303814), [`2f897df`](https://github.com/mastra-ai/mastra/commit/2f897df208508f46f51b7625e5dd20c37f93e0e3), [`d3e89dd`](https://github.com/mastra-ai/mastra/commit/d3e89dd4fc31ae2804c4c7bd3e98113d069cf780), [`d629361`](https://github.com/mastra-ai/mastra/commit/d629361a60f6565b5bfb11976fdaf7308af858e2), [`08c31c1`](https://github.com/mastra-ai/mastra/commit/08c31c188ebccd598acaf55e888b6397d01f7eae), [`f0f8f12`](https://github.com/mastra-ai/mastra/commit/f0f8f125c308f2d0fd36942ef652fd852df7522f), [`3443770`](https://github.com/mastra-ai/mastra/commit/3443770662df8eb24c9df3589b2792d78cfcb811), [`f0a07e0`](https://github.com/mastra-ai/mastra/commit/f0a07e0111b3307c5fabfa4094c5c2cfb734fbe6), [`aaa40e7`](https://github.com/mastra-ai/mastra/commit/aaa40e788628b319baa8e889407d11ad626547fa), [`1521d71`](https://github.com/mastra-ai/mastra/commit/1521d716e5daedc74690c983fbd961123c56756b), [`9e1911d`](https://github.com/mastra-ai/mastra/commit/9e1911db2b4db85e0e768c3f15e0d61e319869f6), [`ebac155`](https://github.com/mastra-ai/mastra/commit/ebac15564a590117db7078233f927a7e28a85106), [`dd1c38d`](https://github.com/mastra-ai/mastra/commit/dd1c38d1b75f1b695c27b40d8d9d6ed00d5e0f6f), [`5948e6a`](https://github.com/mastra-ai/mastra/commit/5948e6a5146c83666ba3f294b2be576c82a513fb), [`8940859`](https://github.com/mastra-ai/mastra/commit/89408593658199b4ad67f7b65e888f344e64a442), [`ffd8f1b`](https://github.com/mastra-ai/mastra/commit/ffd8f1b904181c68fcbf5a1974e2b96a9303b042), [`e629310`](https://github.com/mastra-ai/mastra/commit/e629310f1a73fa236d49ec7a1d1cceb6229dc7cc), [`844ea5d`](https://github.com/mastra-ai/mastra/commit/844ea5dc0c248961e7bf73629ae7dcff503e853c), [`5df9cce`](https://github.com/mastra-ai/mastra/commit/5df9cce1a753438413f64c11eeef8f845745c2a8), [`4c6b492`](https://github.com/mastra-ai/mastra/commit/4c6b492c4dd591c6a592520c1f6855d6e936d71f), [`dff01d8`](https://github.com/mastra-ai/mastra/commit/dff01d81ce1f4e4087cfac20fa868e6db138dd14), [`9d819d5`](https://github.com/mastra-ai/mastra/commit/9d819d54b61481639f4008e4694791bddf187edd), [`b7de533`](https://github.com/mastra-ai/mastra/commit/b7de53361667eb51fefd89fcaed924f3c57cee8d), [`f15fb34`](https://github.com/mastra-ai/mastra/commit/f15fb347b76581ef91a16770bc21e2d50dbe3864), [`fd3d338`](https://github.com/mastra-ai/mastra/commit/fd3d338a2c362174ed5b383f1f011ad9fb0302aa), [`71c8d6c`](https://github.com/mastra-ai/mastra/commit/71c8d6c161253207b2b9588bdadb7eed604f7253), [`6179a9b`](https://github.com/mastra-ai/mastra/commit/6179a9ba36ffac326de3cc3c43cdc8028d37c251), [`c30400a`](https://github.com/mastra-ai/mastra/commit/c30400a49b994b1b97256fe785eb6c906fc2b232), [`00f4921`](https://github.com/mastra-ai/mastra/commit/00f4921dd2c91a1e5446799599ef7116a8214a1a), [`70189fc`](https://github.com/mastra-ai/mastra/commit/70189fc9611c3be54e5e655910b672b21ddefb94), [`ca8041c`](https://github.com/mastra-ai/mastra/commit/ca8041cce0379fda22ed293a565bcb5b6ddca68a), [`7051bf3`](https://github.com/mastra-ai/mastra/commit/7051bf38b3b122a069008f861f7bfc004a6d9f6e), [`a8f1494`](https://github.com/mastra-ai/mastra/commit/a8f1494f4bbdc2770bcf327d4c7d869e332183f1), [`69e0a87`](https://github.com/mastra-ai/mastra/commit/69e0a878896a2da9494945d86e056a5f8f05b851), [`352a5d6`](https://github.com/mastra-ai/mastra/commit/352a5d625cfe09849b21e8f52a24c9f0366759d5), [`0793497`](https://github.com/mastra-ai/mastra/commit/079349753620c40246ffd673e3f9d7d9820beff3), [`01f8878`](https://github.com/mastra-ai/mastra/commit/01f88783de25e4de048c1c8aace43e26373c6ea5), [`5df9cce`](https://github.com/mastra-ai/mastra/commit/5df9cce1a753438413f64c11eeef8f845745c2a8), [`4c77209`](https://github.com/mastra-ai/mastra/commit/4c77209e6c11678808b365d545845918c40045c8), [`a854ede`](https://github.com/mastra-ai/mastra/commit/a854ede62bf5ac0945a624ac48913dd69c73aabf), [`c576fc0`](https://github.com/mastra-ai/mastra/commit/c576fc0b100b2085afded91a37c97a0ea0ec09c7), [`8e85939`](https://github.com/mastra-ai/mastra/commit/8e859393c1cda6ff3d11618ac1150ca6f68175b6), [`3defc80`](https://github.com/mastra-ai/mastra/commit/3defc80cf2b88a1b7fc1cc4ddcb91e982a614609), [`00123ba`](https://github.com/mastra-ai/mastra/commit/00123ba96dc9e5cd0b110420ebdba56d8f237b25), [`16153fe`](https://github.com/mastra-ai/mastra/commit/16153fe7eb13c99401f48e6ca32707c965ee28b9), [`9f4a683`](https://github.com/mastra-ai/mastra/commit/9f4a6833e88b52574665c028fd5508ad5c2f6004), [`bc94344`](https://github.com/mastra-ai/mastra/commit/bc943444a1342d8a662151b7bce1df7dae32f59c), [`57d157f`](https://github.com/mastra-ai/mastra/commit/57d157f0b163a95c3e6c9eae31bdb11d1bfc64f9), [`903f67d`](https://github.com/mastra-ai/mastra/commit/903f67d184504a273893818c02b961f5423a79ad), [`d827d08`](https://github.com/mastra-ai/mastra/commit/d827d0808ffe1f3553a84e975806cc989b9735dd), [`2a90c55`](https://github.com/mastra-ai/mastra/commit/2a90c55a86a9210697d5adaab5ee94584b079adc), [`4c6b492`](https://github.com/mastra-ai/mastra/commit/4c6b492c4dd591c6a592520c1f6855d6e936d71f), [`eb09742`](https://github.com/mastra-ai/mastra/commit/eb09742197f66c4c38154c3beec78313e69760b2), [`ebac155`](https://github.com/mastra-ai/mastra/commit/ebac15564a590117db7078233f927a7e28a85106), [`23c10a1`](https://github.com/mastra-ai/mastra/commit/23c10a1efdd9a693c405511ab2dc8a1236603162), [`96d35f6`](https://github.com/mastra-ai/mastra/commit/96d35f61376bc2b1bf148648a2c1985bd51bef55), [`5cbe88a`](https://github.com/mastra-ai/mastra/commit/5cbe88aefbd9f933bca669fd371ea36bf939ac6d), [`a1bd7b8`](https://github.com/mastra-ai/mastra/commit/a1bd7b8571db16b94eb01588f451a74758c96d65), [`d78b38d`](https://github.com/mastra-ai/mastra/commit/d78b38d898fce285260d3bbb4befade54331617f), [`a0a5b4b`](https://github.com/mastra-ai/mastra/commit/a0a5b4bbebe6c701ebbadf744873aa0d5ca01371), [`0633100`](https://github.com/mastra-ai/mastra/commit/0633100a911ad22f5256471bdf753da21c104742), [`c710c16`](https://github.com/mastra-ai/mastra/commit/c710c1652dccfdc4111c8412bca7a6bb1d48b441), [`354ad0b`](https://github.com/mastra-ai/mastra/commit/354ad0b7b1b8183ac567f236a884fc7ede6d7138), [`cfae733`](https://github.com/mastra-ai/mastra/commit/cfae73394f4920635e6c919c8e95ff9a0788e2e5), [`e3dfda7`](https://github.com/mastra-ai/mastra/commit/e3dfda7b11bf3b8c4bb55637028befb5f387fc74), [`69ea758`](https://github.com/mastra-ai/mastra/commit/69ea758358edd7117f191c2e69c8bb5fc79e7a1a), [`651e772`](https://github.com/mastra-ai/mastra/commit/651e772eb1475fb13e126d3fcc01751297a88214), [`993ad98`](https://github.com/mastra-ai/mastra/commit/993ad98d7ad3bebda9ecef5fec5c94349a0d04bc), [`676ccc7`](https://github.com/mastra-ai/mastra/commit/676ccc7fe92468d2d45d39c31a87825c89fd1ea0), [`3ff2c17`](https://github.com/mastra-ai/mastra/commit/3ff2c17a58e312fad5ea37377262c12d92ca0908), [`844ea5d`](https://github.com/mastra-ai/mastra/commit/844ea5dc0c248961e7bf73629ae7dcff503e853c), [`398fde3`](https://github.com/mastra-ai/mastra/commit/398fde3f39e707cda79372cdae8f9870e3b57c8d), [`c10398d`](https://github.com/mastra-ai/mastra/commit/c10398d5b88f1d4af556f4267ff06f1d11e89179), [`f0f8f12`](https://github.com/mastra-ai/mastra/commit/f0f8f125c308f2d0fd36942ef652fd852df7522f), [`0d7618b`](https://github.com/mastra-ai/mastra/commit/0d7618bc650bf2800934b243eca5648f4aeed9c2), [`7b763e5`](https://github.com/mastra-ai/mastra/commit/7b763e52fc3eaf699c2a99f2adf418dd46e4e9a5), [`d36cfbb`](https://github.com/mastra-ai/mastra/commit/d36cfbbb6565ba5f827883cc9bb648eb14befdc1), [`c63fbba`](https://github.com/mastra-ai/mastra/commit/c63fbba1afdd61a01a994b7a69e52c9881baeaeb), [`3697853`](https://github.com/mastra-ai/mastra/commit/3697853deeb72017d90e0f38a93c1e29221aeca0), [`c23200d`](https://github.com/mastra-ai/mastra/commit/c23200ddfd60830effb39329674ba4ca93be6aac), [`b2e45ec`](https://github.com/mastra-ai/mastra/commit/b2e45eca727a8db01a81ba93f1a5219c7183c839), [`d6d49f7`](https://github.com/mastra-ai/mastra/commit/d6d49f7b8714fa19a52ff9c7cf7fb7e73751901e), [`00c2387`](https://github.com/mastra-ai/mastra/commit/00c2387f5f04a365316f851e58666ac43f8c4edf), [`a534e95`](https://github.com/mastra-ai/mastra/commit/a534e9591f83b3cc1ebff99c67edf4cda7bf81d3), [`9d0e7fe`](https://github.com/mastra-ai/mastra/commit/9d0e7feca8ed98de959f53476ee1456073673348), [`53d927c`](https://github.com/mastra-ai/mastra/commit/53d927cc6f03bff33655b7e2b788da445a08731d), [`ad6250d`](https://github.com/mastra-ai/mastra/commit/ad6250dbdaad927e29f74a27b83f6c468b50a705), [`3f2faf2`](https://github.com/mastra-ai/mastra/commit/3f2faf2e2d685d6c053cc5af1bf9fedf267b2ce5), [`22f64bc`](https://github.com/mastra-ai/mastra/commit/22f64bc1d37149480b58bf2fefe35b79a1e3e7d5), [`363284b`](https://github.com/mastra-ai/mastra/commit/363284bb974e850f06f40f89a28c79d9f432d7e4), [`3a73998`](https://github.com/mastra-ai/mastra/commit/3a73998fa4ebeb7f3dc9301afe78095fc63e7999), [`83d5942`](https://github.com/mastra-ai/mastra/commit/83d5942669ce7bba4a6ca4fd4da697a10eb5ebdc), [`b7959e6`](https://github.com/mastra-ai/mastra/commit/b7959e6e25a46b480f9ea2217c4c6c588c423791), [`bda6370`](https://github.com/mastra-ai/mastra/commit/bda637009360649aaf579919e7873e33553c273e), [`c218bd3`](https://github.com/mastra-ai/mastra/commit/c218bd3759e32423735b04843a09404572631014), [`d7acd8e`](https://github.com/mastra-ai/mastra/commit/d7acd8e987b5d7eff4fd98b0906c17c06a2e83d5), [`c7f1f7d`](https://github.com/mastra-ai/mastra/commit/c7f1f7d24f61f247f018cc2d1f33bf63212959a7), [`0bddc6d`](https://github.com/mastra-ai/mastra/commit/0bddc6d8dbd6f6008c0cba2e4960a2da75a55af1), [`735d8c1`](https://github.com/mastra-ai/mastra/commit/735d8c1c0d19fbc09e6f8b66cf41bc7655993838), [`acf322e`](https://github.com/mastra-ai/mastra/commit/acf322e0f1fd0189684cf529d91c694bea918a45), [`5d7e4dd`](https://github.com/mastra-ai/mastra/commit/5d7e4dd802adcc57d3ac666c2eee044f50c7cee0), [`e16d553`](https://github.com/mastra-ai/mastra/commit/e16d55338403c7553531cc568125c63d53653dff), [`c942802`](https://github.com/mastra-ai/mastra/commit/c942802a477a925b01859a7b8688d4355715caaa), [`a0c8c1b`](https://github.com/mastra-ai/mastra/commit/a0c8c1b87d4fee252aebda73e8637fbe01d761c9), [`cc34739`](https://github.com/mastra-ai/mastra/commit/cc34739c34b6266a91bea561119240a7acf47887), [`c218bd3`](https://github.com/mastra-ai/mastra/commit/c218bd3759e32423735b04843a09404572631014), [`2c4438b`](https://github.com/mastra-ai/mastra/commit/2c4438b87817ab7eed818c7990fef010475af1a3), [`35edc49`](https://github.com/mastra-ai/mastra/commit/35edc49ac0556db609189641d6341e76771b81fc), [`4d59f58`](https://github.com/mastra-ai/mastra/commit/4d59f58de2d90d6e2810a19d4518e38ddddb9038), [`2b8893c`](https://github.com/mastra-ai/mastra/commit/2b8893cb108ef9acb72ee7835cd625610d2c1a4a), [`8e5c75b`](https://github.com/mastra-ai/mastra/commit/8e5c75bdb1d08a42d45309a4c72def4b6890230f), [`e1bb9c9`](https://github.com/mastra-ai/mastra/commit/e1bb9c94b4eb68b019ae275981be3feb769b5365), [`351a11f`](https://github.com/mastra-ai/mastra/commit/351a11fcaf2ed1008977fa9b9a489fc422e51cd4), [`e59e0d3`](https://github.com/mastra-ai/mastra/commit/e59e0d32afb5fcf2c9f3c00c8f81f6c21d3a63fa), [`465ac05`](https://github.com/mastra-ai/mastra/commit/465ac0526a91d175542091c675181f1a96c98c46), [`fa8409b`](https://github.com/mastra-ai/mastra/commit/fa8409bc39cfd8ba6643b9db5269b90b22e2a2f7), [`e7266a2`](https://github.com/mastra-ai/mastra/commit/e7266a278db02035c97a5e9cd9d1669a6b7a535d), [`173c535`](https://github.com/mastra-ai/mastra/commit/173c535c0645b0da404fe09f003778f0b0d4e019)]:
|
|
16
|
-
- @mastra/core@
|
|
17
|
-
- @mastra/server@
|
|
62
|
+
- Updated dependencies [[`21a15de`](https://github.com/mastra-ai/mastra/commit/21a15de369fe82aac26bb642ed7be73505475e8b), [`d3e89dd`](https://github.com/mastra-ai/mastra/commit/d3e89dd4fc31ae2804c4c7bd3e98113d069cf780), [`feb7ee4`](https://github.com/mastra-ai/mastra/commit/feb7ee4d09a75edb46c6669a3beaceec78811747), [`b0e2ea5`](https://github.com/mastra-ai/mastra/commit/b0e2ea5b52c40fae438b9e2f7baee6f0f89c5442), [`c456e01`](https://github.com/mastra-ai/mastra/commit/c456e0149e3c176afcefdbd9bb1d2c5917723725), [`ab035c2`](https://github.com/mastra-ai/mastra/commit/ab035c2ef6d8cc7bb25f06f1a38508bd9e6f126b), [`1a46a56`](https://github.com/mastra-ai/mastra/commit/1a46a566f45a3fcbadc1cf36bf86d351f264bfa3), [`3cf540b`](https://github.com/mastra-ai/mastra/commit/3cf540b9fbfea8f4fc8d3a2319a4e6c0b0cbfd52), [`1c6ce51`](https://github.com/mastra-ai/mastra/commit/1c6ce51f875915ab57fd36873623013699a2a65d), [`898a972`](https://github.com/mastra-ai/mastra/commit/898a9727d286c2510d6b702dfd367e6aaf5c6b0f), [`a97003a`](https://github.com/mastra-ai/mastra/commit/a97003aa1cf2f4022a41912324a1e77263b326b8), [`ccc141e`](https://github.com/mastra-ai/mastra/commit/ccc141ed27da0abc3a3fc28e9e5128152e8e37f4), [`fe3b897`](https://github.com/mastra-ai/mastra/commit/fe3b897c2ccbcd2b10e81b099438c7337feddf89), [`00123ba`](https://github.com/mastra-ai/mastra/commit/00123ba96dc9e5cd0b110420ebdba56d8f237b25), [`29c4309`](https://github.com/mastra-ai/mastra/commit/29c4309f818b24304c041bcb4a8f19b5f13f6b62), [`16785ce`](https://github.com/mastra-ai/mastra/commit/16785ced928f6f22638f4488cf8a125d99211799), [`de8239b`](https://github.com/mastra-ai/mastra/commit/de8239bdcb1d8c0cfa06da21f1569912a66bbc8a), [`b5e6cd7`](https://github.com/mastra-ai/mastra/commit/b5e6cd77fc8c8e64e0494c1d06cee3d84e795d1e), [`3759cb0`](https://github.com/mastra-ai/mastra/commit/3759cb064935b5f74c65ac2f52a1145f7352899d), [`651e772`](https://github.com/mastra-ai/mastra/commit/651e772eb1475fb13e126d3fcc01751297a88214), [`b61b93f`](https://github.com/mastra-ai/mastra/commit/b61b93f9e058b11dd2eec169853175d31dbdd567), [`bae33d9`](https://github.com/mastra-ai/mastra/commit/bae33d91a63fbb64d1e80519e1fc1acaed1e9013), [`c63fbba`](https://github.com/mastra-ai/mastra/commit/c63fbba1afdd61a01a994b7a69e52c9881baeaeb), [`c0b731f`](https://github.com/mastra-ai/mastra/commit/c0b731fb27d712dc8582e846df5c0332a6a0c5ba), [`43ca8f2`](https://github.com/mastra-ai/mastra/commit/43ca8f2c7334851cc7b4d3d2f037d8784bfbdd5f), [`2ca67cc`](https://github.com/mastra-ai/mastra/commit/2ca67cc3bb1f6a617353fdcab197d9efebe60d6f), [`9e67002`](https://github.com/mastra-ai/mastra/commit/9e67002b52c9be19936c420a489dbee9c5fd6a78), [`35edc49`](https://github.com/mastra-ai/mastra/commit/35edc49ac0556db609189641d6341e76771b81fc)]:
|
|
63
|
+
- @mastra/core@1.0.0-beta.5
|
|
64
|
+
- @mastra/server@1.0.0-beta.5
|
|
18
65
|
|
|
19
66
|
## 0.17.5
|
|
20
67
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ContextWithMastra } from '@mastra/core/server';
|
|
2
|
+
import type { Next } from 'hono';
|
|
3
|
+
export declare const authenticationMiddleware: (c: ContextWithMastra, next: Next) => Promise<void | (Response & import("hono").TypedResponse<{
|
|
4
|
+
error: string;
|
|
5
|
+
}, 401, "json">)>;
|
|
6
|
+
export declare const authorizationMiddleware: (c: ContextWithMastra, next: Next) => Promise<void | (Response & import("hono").TypedResponse<{
|
|
7
|
+
error: string;
|
|
8
|
+
}, 403, "json">) | (Response & import("hono").TypedResponse<{
|
|
9
|
+
error: string;
|
|
10
|
+
}, 500, "json">)>;
|
|
11
|
+
//# sourceMappingURL=auth-middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-middleware.d.ts","sourceRoot":"","sources":["../src/auth-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAQ7D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAEjC,eAAO,MAAM,wBAAwB,GAAU,GAAG,iBAAiB,EAAE,MAAM,IAAI;;iBAgE9E,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAU,GAAG,iBAAiB,EAAE,MAAM,IAAI;;;;iBAkF7E,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var store = require('@mastra/server/a2a/store');
|
|
4
3
|
var serverAdapter = require('@mastra/server/server-adapter');
|
|
4
|
+
var fetchToNode = require('fetch-to-node');
|
|
5
|
+
var auth = require('@mastra/server/auth');
|
|
5
6
|
|
|
6
7
|
// src/index.ts
|
|
7
8
|
|
|
8
|
-
// ../../node_modules/.pnpm/hono@4.10.
|
|
9
|
+
// ../../node_modules/.pnpm/hono@4.10.6/node_modules/hono/dist/http-exception.js
|
|
9
10
|
var HTTPException = class extends Error {
|
|
10
11
|
res;
|
|
11
12
|
status;
|
|
@@ -28,7 +29,7 @@ var HTTPException = class extends Error {
|
|
|
28
29
|
}
|
|
29
30
|
};
|
|
30
31
|
|
|
31
|
-
// ../../node_modules/.pnpm/hono@4.10.
|
|
32
|
+
// ../../node_modules/.pnpm/hono@4.10.6/node_modules/hono/dist/middleware/body-limit/index.js
|
|
32
33
|
var ERROR_MESSAGE = "Payload Too Large";
|
|
33
34
|
var BodyLimitError = class extends Error {
|
|
34
35
|
constructor(message) {
|
|
@@ -85,7 +86,7 @@ var bodyLimit = (options) => {
|
|
|
85
86
|
};
|
|
86
87
|
};
|
|
87
88
|
|
|
88
|
-
// ../../node_modules/.pnpm/hono@4.10.
|
|
89
|
+
// ../../node_modules/.pnpm/hono@4.10.6/node_modules/hono/dist/utils/stream.js
|
|
89
90
|
var StreamingApi = class {
|
|
90
91
|
writer;
|
|
91
92
|
encoder;
|
|
@@ -152,7 +153,7 @@ var StreamingApi = class {
|
|
|
152
153
|
}
|
|
153
154
|
};
|
|
154
155
|
|
|
155
|
-
// ../../node_modules/.pnpm/hono@4.10.
|
|
156
|
+
// ../../node_modules/.pnpm/hono@4.10.6/node_modules/hono/dist/helper/streaming/utils.js
|
|
156
157
|
var isOldBunVersion = () => {
|
|
157
158
|
const version = typeof Bun !== "undefined" ? Bun.version : void 0;
|
|
158
159
|
if (version === void 0) {
|
|
@@ -163,7 +164,7 @@ var isOldBunVersion = () => {
|
|
|
163
164
|
return result;
|
|
164
165
|
};
|
|
165
166
|
|
|
166
|
-
// ../../node_modules/.pnpm/hono@4.10.
|
|
167
|
+
// ../../node_modules/.pnpm/hono@4.10.6/node_modules/hono/dist/helper/streaming/stream.js
|
|
167
168
|
var contextStash = /* @__PURE__ */ new WeakMap();
|
|
168
169
|
var stream = (c, cb, onError) => {
|
|
169
170
|
const { readable, writable } = new TransformStream();
|
|
@@ -191,28 +192,112 @@ var stream = (c, cb, onError) => {
|
|
|
191
192
|
})();
|
|
192
193
|
return c.newResponse(stream2.responseReadable);
|
|
193
194
|
};
|
|
195
|
+
var authenticationMiddleware = async (c, next) => {
|
|
196
|
+
const mastra = c.get("mastra");
|
|
197
|
+
const authConfig = mastra.getServer()?.auth;
|
|
198
|
+
const customRouteAuthConfig = c.get("customRouteAuthConfig");
|
|
199
|
+
if (!authConfig) {
|
|
200
|
+
return next();
|
|
201
|
+
}
|
|
202
|
+
const path = c.req.path;
|
|
203
|
+
const method = c.req.method;
|
|
204
|
+
const getHeader = (name) => c.req.header(name);
|
|
205
|
+
if (auth.isDevPlaygroundRequest(path, method, getHeader, authConfig)) {
|
|
206
|
+
return next();
|
|
207
|
+
}
|
|
208
|
+
if (!auth.isProtectedPath(c.req.path, c.req.method, authConfig, customRouteAuthConfig)) {
|
|
209
|
+
return next();
|
|
210
|
+
}
|
|
211
|
+
if (auth.canAccessPublicly(c.req.path, c.req.method, authConfig)) {
|
|
212
|
+
return next();
|
|
213
|
+
}
|
|
214
|
+
const authHeader = c.req.header("Authorization");
|
|
215
|
+
let token = authHeader ? authHeader.replace("Bearer ", "") : null;
|
|
216
|
+
if (!token && c.req.query("apiKey")) {
|
|
217
|
+
token = c.req.query("apiKey") || null;
|
|
218
|
+
}
|
|
219
|
+
if (!token) {
|
|
220
|
+
return c.json({ error: "Authentication required" }, 401);
|
|
221
|
+
}
|
|
222
|
+
try {
|
|
223
|
+
let user;
|
|
224
|
+
if (typeof authConfig.authenticateToken === "function") {
|
|
225
|
+
user = await authConfig.authenticateToken(token, c.req);
|
|
226
|
+
} else {
|
|
227
|
+
throw new Error("No token verification method configured");
|
|
228
|
+
}
|
|
229
|
+
if (!user) {
|
|
230
|
+
return c.json({ error: "Invalid or expired token" }, 401);
|
|
231
|
+
}
|
|
232
|
+
c.get("requestContext").set("user", user);
|
|
233
|
+
return next();
|
|
234
|
+
} catch (err) {
|
|
235
|
+
console.error(err);
|
|
236
|
+
return c.json({ error: "Invalid or expired token" }, 401);
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
var authorizationMiddleware = async (c, next) => {
|
|
240
|
+
const mastra = c.get("mastra");
|
|
241
|
+
const authConfig = mastra.getServer()?.auth;
|
|
242
|
+
const customRouteAuthConfig = c.get("customRouteAuthConfig");
|
|
243
|
+
if (!authConfig) {
|
|
244
|
+
return next();
|
|
245
|
+
}
|
|
246
|
+
const path = c.req.path;
|
|
247
|
+
const method = c.req.method;
|
|
248
|
+
const getHeader = (name) => c.req.header(name);
|
|
249
|
+
if (auth.isDevPlaygroundRequest(path, method, getHeader, authConfig)) {
|
|
250
|
+
return next();
|
|
251
|
+
}
|
|
252
|
+
if (!auth.isProtectedPath(c.req.path, c.req.method, authConfig, customRouteAuthConfig)) {
|
|
253
|
+
return next();
|
|
254
|
+
}
|
|
255
|
+
if (auth.canAccessPublicly(path, method, authConfig)) {
|
|
256
|
+
return next();
|
|
257
|
+
}
|
|
258
|
+
const user = c.get("requestContext").get("user");
|
|
259
|
+
if ("authorizeUser" in authConfig && typeof authConfig.authorizeUser === "function") {
|
|
260
|
+
try {
|
|
261
|
+
const isAuthorized = await authConfig.authorizeUser(user, c.req);
|
|
262
|
+
if (isAuthorized) {
|
|
263
|
+
return next();
|
|
264
|
+
}
|
|
265
|
+
return c.json({ error: "Access denied" }, 403);
|
|
266
|
+
} catch (err) {
|
|
267
|
+
console.error(err);
|
|
268
|
+
return c.json({ error: "Authorization error" }, 500);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if ("authorize" in authConfig && typeof authConfig.authorize === "function") {
|
|
272
|
+
try {
|
|
273
|
+
const isAuthorized = await authConfig.authorize(path, method, user, c);
|
|
274
|
+
if (isAuthorized) {
|
|
275
|
+
return next();
|
|
276
|
+
}
|
|
277
|
+
return c.json({ error: "Access denied" }, 403);
|
|
278
|
+
} catch (err) {
|
|
279
|
+
console.error(err);
|
|
280
|
+
return c.json({ error: "Authorization error" }, 500);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if ("rules" in authConfig && authConfig.rules && authConfig.rules.length > 0) {
|
|
284
|
+
const isAuthorized = await auth.checkRules(authConfig.rules, path, method, user);
|
|
285
|
+
if (isAuthorized) {
|
|
286
|
+
return next();
|
|
287
|
+
}
|
|
288
|
+
return c.json({ error: "Access denied" }, 403);
|
|
289
|
+
}
|
|
290
|
+
if (auth.defaultAuthConfig.rules && auth.defaultAuthConfig.rules.length > 0) {
|
|
291
|
+
const isAuthorized = await auth.checkRules(auth.defaultAuthConfig.rules, path, method, user);
|
|
292
|
+
if (isAuthorized) {
|
|
293
|
+
return next();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return c.json({ error: "Access denied" }, 403);
|
|
297
|
+
};
|
|
194
298
|
|
|
195
299
|
// src/index.ts
|
|
196
|
-
var
|
|
197
|
-
taskStore;
|
|
198
|
-
customRouteAuthConfig;
|
|
199
|
-
playground;
|
|
200
|
-
isDev;
|
|
201
|
-
constructor({
|
|
202
|
-
mastra,
|
|
203
|
-
tools,
|
|
204
|
-
taskStore,
|
|
205
|
-
customRouteAuthConfig,
|
|
206
|
-
playground,
|
|
207
|
-
isDev,
|
|
208
|
-
bodyLimitOptions
|
|
209
|
-
}) {
|
|
210
|
-
super({ mastra, bodyLimitOptions, tools });
|
|
211
|
-
this.taskStore = taskStore || new store.InMemoryTaskStore();
|
|
212
|
-
this.customRouteAuthConfig = customRouteAuthConfig;
|
|
213
|
-
this.playground = playground;
|
|
214
|
-
this.isDev = isDev;
|
|
215
|
-
}
|
|
300
|
+
var MastraServer = class extends serverAdapter.MastraServer {
|
|
216
301
|
createContextMiddleware() {
|
|
217
302
|
return async (c, next) => {
|
|
218
303
|
let bodyRequestContext;
|
|
@@ -254,8 +339,8 @@ var HonoServerAdapter = class extends serverAdapter.MastraServerAdapter {
|
|
|
254
339
|
c.set("taskStore", this.taskStore);
|
|
255
340
|
c.set("playground", this.playground === true);
|
|
256
341
|
c.set("isDev", this.isDev === true);
|
|
257
|
-
c.set("customRouteAuthConfig", this.customRouteAuthConfig);
|
|
258
342
|
c.set("abortSignal", c.req.raw.signal);
|
|
343
|
+
c.set("customRouteAuthConfig", this.customRouteAuthConfig);
|
|
259
344
|
return next();
|
|
260
345
|
};
|
|
261
346
|
}
|
|
@@ -276,12 +361,14 @@ var HonoServerAdapter = class extends serverAdapter.MastraServerAdapter {
|
|
|
276
361
|
const { done, value } = await reader.read();
|
|
277
362
|
if (done) break;
|
|
278
363
|
if (value) {
|
|
364
|
+
const shouldRedact = this.streamOptions?.redact ?? true;
|
|
365
|
+
const outputValue = shouldRedact ? serverAdapter.redactStreamChunk(value) : value;
|
|
279
366
|
if (streamFormat === "sse") {
|
|
280
|
-
await stream2.write(`data: ${JSON.stringify(
|
|
367
|
+
await stream2.write(`data: ${JSON.stringify(outputValue)}
|
|
281
368
|
|
|
282
369
|
`);
|
|
283
370
|
} else {
|
|
284
|
-
await stream2.write(JSON.stringify(
|
|
371
|
+
await stream2.write(JSON.stringify(outputValue) + "");
|
|
285
372
|
}
|
|
286
373
|
}
|
|
287
374
|
}
|
|
@@ -317,6 +404,43 @@ var HonoServerAdapter = class extends serverAdapter.MastraServerAdapter {
|
|
|
317
404
|
} else if (route.responseType === "datastream-response") {
|
|
318
405
|
const fetchResponse = result;
|
|
319
406
|
return fetchResponse;
|
|
407
|
+
} else if (route.responseType === "mcp-http") {
|
|
408
|
+
const { server, httpPath } = result;
|
|
409
|
+
const { req, res } = fetchToNode.toReqRes(response.req.raw);
|
|
410
|
+
try {
|
|
411
|
+
await server.startHTTP({
|
|
412
|
+
url: new URL(response.req.url),
|
|
413
|
+
httpPath,
|
|
414
|
+
req,
|
|
415
|
+
res
|
|
416
|
+
});
|
|
417
|
+
return await fetchToNode.toFetchResponse(res);
|
|
418
|
+
} catch {
|
|
419
|
+
if (!res.headersSent) {
|
|
420
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
421
|
+
res.end(
|
|
422
|
+
JSON.stringify({
|
|
423
|
+
jsonrpc: "2.0",
|
|
424
|
+
error: { code: -32603, message: "Internal server error" },
|
|
425
|
+
id: null
|
|
426
|
+
})
|
|
427
|
+
);
|
|
428
|
+
return await fetchToNode.toFetchResponse(res);
|
|
429
|
+
}
|
|
430
|
+
return await fetchToNode.toFetchResponse(res);
|
|
431
|
+
}
|
|
432
|
+
} else if (route.responseType === "mcp-sse") {
|
|
433
|
+
const { server, ssePath, messagePath } = result;
|
|
434
|
+
try {
|
|
435
|
+
return await server.startHonoSSE({
|
|
436
|
+
url: new URL(response.req.url),
|
|
437
|
+
ssePath,
|
|
438
|
+
messagePath,
|
|
439
|
+
context: response
|
|
440
|
+
});
|
|
441
|
+
} catch {
|
|
442
|
+
return response.json({ error: "Error handling MCP SSE request" }, 500);
|
|
443
|
+
}
|
|
320
444
|
} else {
|
|
321
445
|
return response.status(500);
|
|
322
446
|
}
|
|
@@ -356,7 +480,7 @@ var HonoServerAdapter = class extends serverAdapter.MastraServerAdapter {
|
|
|
356
480
|
try {
|
|
357
481
|
params.body = await this.parseBody(route, params.body);
|
|
358
482
|
} catch (error) {
|
|
359
|
-
console.error("Error parsing body", error);
|
|
483
|
+
console.error("Error parsing body:", error instanceof Error ? error.message : String(error));
|
|
360
484
|
return c.json(
|
|
361
485
|
{
|
|
362
486
|
error: "Invalid request body",
|
|
@@ -396,14 +520,19 @@ var HonoServerAdapter = class extends serverAdapter.MastraServerAdapter {
|
|
|
396
520
|
}
|
|
397
521
|
);
|
|
398
522
|
}
|
|
399
|
-
registerContextMiddleware(
|
|
400
|
-
app.use("*", this.createContextMiddleware());
|
|
523
|
+
registerContextMiddleware() {
|
|
524
|
+
this.app.use("*", this.createContextMiddleware());
|
|
401
525
|
}
|
|
402
|
-
|
|
403
|
-
|
|
526
|
+
registerAuthMiddleware() {
|
|
527
|
+
const authConfig = this.mastra.getServer()?.auth;
|
|
528
|
+
if (!authConfig) {
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
this.app.use("*", authenticationMiddleware);
|
|
532
|
+
this.app.use("*", authorizationMiddleware);
|
|
404
533
|
}
|
|
405
534
|
};
|
|
406
535
|
|
|
407
|
-
exports.
|
|
536
|
+
exports.MastraServer = MastraServer;
|
|
408
537
|
//# sourceMappingURL=index.cjs.map
|
|
409
538
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../node_modules/.pnpm/hono@4.10.4/node_modules/hono/dist/http-exception.js","../../../node_modules/.pnpm/hono@4.10.4/node_modules/hono/dist/middleware/body-limit/index.js","../../../node_modules/.pnpm/hono@4.10.4/node_modules/hono/dist/utils/stream.js","../../../node_modules/.pnpm/hono@4.10.4/node_modules/hono/dist/helper/streaming/utils.js","../../../node_modules/.pnpm/hono@4.10.4/node_modules/hono/dist/helper/streaming/stream.js","../src/index.ts"],"names":["MastraServerAdapter","InMemoryTaskStore","stream"],"mappings":";;;;;;;;AACA,IAAI,aAAA,GAAgB,cAAc,KAAA,CAAM;AAAA,EACtC,GAAA;AAAA,EACA,MAAA;AAAA,EACA,WAAA,CAAY,MAAA,GAAS,GAAA,EAAK,OAAA,EAAS;AACjC,IAAA,KAAA,CAAM,SAAS,OAAA,EAAS,EAAE,KAAA,EAAO,OAAA,EAAS,OAAO,CAAA;AACjD,IAAA,IAAA,CAAK,MAAM,OAAA,EAAS,GAAA;AACpB,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AAAA,EAChB;AAAA,EACA,WAAA,GAAc;AACZ,IAAA,IAAI,KAAK,GAAA,EAAK;AACZ,MAAA,MAAM,WAAA,GAAc,IAAI,QAAA,CAAS,IAAA,CAAK,IAAI,IAAA,EAAM;AAAA,QAC9C,QAAQ,IAAA,CAAK,MAAA;AAAA,QACb,OAAA,EAAS,KAAK,GAAA,CAAI;AAAA,OACnB,CAAA;AACD,MAAA,OAAO,WAAA;AAAA,IACT;AACA,IAAA,OAAO,IAAI,QAAA,CAAS,IAAA,CAAK,OAAA,EAAS;AAAA,MAChC,QAAQ,IAAA,CAAK;AAAA,KACd,CAAA;AAAA,EACH;AACF,CAAA;;;ACnBA,IAAI,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AO;AACrB,cAAA,MAAM,SAAU,KAAA,CAAc,MAAA;AAC9B,cAAA,OAAO,CAAA,CAAE,IAAA,CAAK,EAAE,KAAA,EAAO,KAAA,YAAiB,QAAQ,KAAA,CAAM,OAAA,GAAU,eAAA,EAAgB,EAAG,MAAM,CAAA;AAAA,YAC3F;AAEA,YAAA,IAAI,SAAA,IAAa,KAAA,IAAS,KAAA,CAAM,OAAA,IAAW,OAAO,MAAM,OAAA,KAAY,QAAA,IAAY,QAAA,IAAY,KAAA,CAAM,OAAA,EAAS;AACzG,cAAA,MAAM,MAAA,GAAU,MAAM,OAAA,CAAgB,MAAA;AACtC,cAAA,OAAO,CAAA,CAAE,IAAA,CAAK,EAAE,KAAA,EAAO,KAAA,YAAiB,QAAQ,KAAA,CAAM,OAAA,GAAU,eAAA,EAAgB,EAAG,MAAM,CAAA;AAAA,YAC3F;AAAA,UACF;AACA,UAAA,OAAO,CAAA,CAAE,IAAA,CAAK,EAAE,KAAA,EAAO,KAAA,YAAiB,QAAQ,KAAA,CAAM,OAAA,GAAU,eAAA,EAAgB,EAAG,GAAG,CAAA;AAAA,QACxF;AAAA,MACF;AAAA,KACF;AAAA,EACF;AAAA,EAEA,0BAA+C,GAAA,EAA8B;AAC3E,IAAA,GAAA,CAAI,GAAA,CAAI,GAAA,EAAK,IAAA,CAAK,uBAAA,EAAyB,CAAA;AAAA,EAC7C;AAAA,EAEA,MAAM,cAAA,CACJ,GAAA,EACA,EAAE,MAAA,EAAQ,aAAY,EACP;AAEf,IAAA,MAAM,MAAM,cAAA,CAAe,GAAA,EAAY,EAAE,MAAA,EAAQ,aAAa,CAAA;AAAA,EAChE;AACF","file":"index.cjs","sourcesContent":["// src/http-exception.ts\nvar HTTPException = class extends Error {\n res;\n status;\n constructor(status = 500, options) {\n super(options?.message, { cause: options?.cause });\n this.res = options?.res;\n this.status = status;\n }\n getResponse() {\n if (this.res) {\n const newResponse = new Response(this.res.body, {\n status: this.status,\n headers: this.res.headers\n });\n return newResponse;\n }\n return new Response(this.message, {\n status: this.status\n });\n }\n};\nexport {\n HTTPException\n};\n","// src/middleware/body-limit/index.ts\nimport { HTTPException } from \"../../http-exception.js\";\nvar ERROR_MESSAGE = \"Payload Too Large\";\nvar BodyLimitError = class extends Error {\n constructor(message) {\n super(message);\n this.name = \"BodyLimitError\";\n }\n};\nvar bodyLimit = (options) => {\n const onError = options.onError || (() => {\n const res = new Response(ERROR_MESSAGE, {\n status: 413\n });\n throw new HTTPException(413, { res });\n });\n const maxSize = options.maxSize;\n return async function bodyLimit2(c, next) {\n if (!c.req.raw.body) {\n return next();\n }\n const hasTransferEncoding = c.req.raw.headers.has(\"transfer-encoding\");\n const hasContentLength = c.req.raw.headers.has(\"content-length\");\n if (hasTransferEncoding && hasContentLength) {\n }\n if (hasContentLength && !hasTransferEncoding) {\n const contentLength = parseInt(c.req.raw.headers.get(\"content-length\") || \"0\", 10);\n return contentLength > maxSize ? onError(c) : next();\n }\n let size = 0;\n const rawReader = c.req.raw.body.getReader();\n const reader = new ReadableStream({\n async start(controller) {\n try {\n for (; ; ) {\n const { done, value } = await rawReader.read();\n if (done) {\n break;\n }\n size += value.length;\n if (size > maxSize) {\n controller.error(new BodyLimitError(ERROR_MESSAGE));\n break;\n }\n controller.enqueue(value);\n }\n } finally {\n controller.close();\n }\n }\n });\n const requestInit = { body: reader, duplex: \"half\" };\n c.req.raw = new Request(c.req.raw, requestInit);\n await next();\n if (c.error instanceof BodyLimitError) {\n c.res = await onError(c);\n }\n };\n};\nexport {\n bodyLimit\n};\n","// src/utils/stream.ts\nvar StreamingApi = class {\n writer;\n encoder;\n writable;\n abortSubscribers = [];\n responseReadable;\n aborted = false;\n closed = false;\n constructor(writable, _readable) {\n this.writable = writable;\n this.writer = writable.getWriter();\n this.encoder = new TextEncoder();\n const reader = _readable.getReader();\n this.abortSubscribers.push(async () => {\n await reader.cancel();\n });\n this.responseReadable = new ReadableStream({\n async pull(controller) {\n const { done, value } = await reader.read();\n done ? controller.close() : controller.enqueue(value);\n },\n cancel: () => {\n this.abort();\n }\n });\n }\n async write(input) {\n try {\n if (typeof input === \"string\") {\n input = this.encoder.encode(input);\n }\n await this.writer.write(input);\n } catch {\n }\n return this;\n }\n async writeln(input) {\n await this.write(input + \"\\n\");\n return this;\n }\n sleep(ms) {\n return new Promise((res) => setTimeout(res, ms));\n }\n async close() {\n try {\n await this.writer.close();\n } catch {\n }\n this.closed = true;\n }\n async pipe(body) {\n this.writer.releaseLock();\n await body.pipeTo(this.writable, { preventClose: true });\n this.writer = this.writable.getWriter();\n }\n onAbort(listener) {\n this.abortSubscribers.push(listener);\n }\n abort() {\n if (!this.aborted) {\n this.aborted = true;\n this.abortSubscribers.forEach((subscriber) => subscriber());\n }\n }\n};\nexport {\n StreamingApi\n};\n","// src/helper/streaming/utils.ts\nvar isOldBunVersion = () => {\n const version = typeof Bun !== \"undefined\" ? Bun.version : void 0;\n if (version === void 0) {\n return false;\n }\n const result = version.startsWith(\"1.1\") || version.startsWith(\"1.0\") || version.startsWith(\"0.\");\n isOldBunVersion = () => result;\n return result;\n};\nexport {\n isOldBunVersion\n};\n","// src/helper/streaming/stream.ts\nimport { StreamingApi } from \"../../utils/stream.js\";\nimport { isOldBunVersion } from \"./utils.js\";\nvar contextStash = /* @__PURE__ */ new WeakMap();\nvar stream = (c, cb, onError) => {\n const { readable, writable } = new TransformStream();\n const stream2 = new StreamingApi(writable, readable);\n if (isOldBunVersion()) {\n c.req.raw.signal.addEventListener(\"abort\", () => {\n if (!stream2.closed) {\n stream2.abort();\n }\n });\n }\n contextStash.set(stream2.responseReadable, c);\n (async () => {\n try {\n await cb(stream2);\n } catch (e) {\n if (e === void 0) {\n } else if (e instanceof Error && onError) {\n await onError(e, stream2);\n } else {\n console.error(e);\n }\n } finally {\n stream2.close();\n }\n })();\n return c.newResponse(stream2.responseReadable);\n};\nexport {\n stream\n};\n","import type { Mastra } from '@mastra/core/mastra';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport type { Tool } from '@mastra/core/tools';\nimport { InMemoryTaskStore } from '@mastra/server/a2a/store';\nimport { MastraServerAdapter } from '@mastra/server/server-adapter';\nimport type { BodyLimitOptions, ServerRoute } from '@mastra/server/server-adapter';\nimport type { Context, Env, Hono, HonoRequest, MiddlewareHandler } from 'hono';\nimport { bodyLimit } from 'hono/body-limit';\nimport { stream } from 'hono/streaming';\n\n// Export type definitions for Hono app configuration\nexport type HonoVariables = {\n mastra: Mastra;\n requestContext: RequestContext;\n tools: Record<string, Tool>;\n abortSignal: AbortSignal;\n taskStore: InMemoryTaskStore;\n customRouteAuthConfig?: Map<string, boolean>;\n playground?: boolean;\n isDev?: boolean;\n};\n\nexport type HonoBindings = {};\n\nexport class HonoServerAdapter extends MastraServerAdapter<Hono<any, any, any>, HonoRequest, Context> {\n private taskStore: InMemoryTaskStore;\n private customRouteAuthConfig?: Map<string, boolean>;\n private playground?: boolean;\n private isDev?: boolean;\n\n constructor({\n mastra,\n tools,\n taskStore,\n customRouteAuthConfig,\n playground,\n isDev,\n bodyLimitOptions,\n }: {\n mastra: Mastra;\n tools?: Record<string, Tool>;\n taskStore?: InMemoryTaskStore;\n customRouteAuthConfig?: Map<string, boolean>;\n playground?: boolean;\n isDev?: boolean;\n bodyLimitOptions?: BodyLimitOptions;\n }) {\n super({ mastra, bodyLimitOptions, tools });\n this.taskStore = taskStore || new InMemoryTaskStore();\n this.customRouteAuthConfig = customRouteAuthConfig;\n this.playground = playground;\n this.isDev = isDev;\n }\n\n createContextMiddleware(): MiddlewareHandler {\n return async (c, next) => {\n // Parse request context from request body and add to context\n\n let bodyRequestContext: Record<string, any> | undefined;\n let paramsRequestContext: Record<string, any> | undefined;\n\n // Parse request context from request body (POST/PUT)\n if (c.req.method === 'POST' || c.req.method === 'PUT') {\n const contentType = c.req.header('content-type');\n if (contentType?.includes('application/json')) {\n try {\n const clonedReq = c.req.raw.clone();\n const body = (await clonedReq.json()) as { requestContext?: Record<string, any> };\n if (body.requestContext) {\n bodyRequestContext = body.requestContext;\n }\n } catch {\n // Body parsing failed, continue without body\n }\n }\n }\n\n // Parse request context from query params (GET)\n if (c.req.method === 'GET') {\n try {\n const encodedRequestContext = c.req.query('requestContext');\n if (encodedRequestContext) {\n // Try JSON first\n try {\n paramsRequestContext = JSON.parse(encodedRequestContext);\n } catch {\n // Fallback to base64(JSON)\n try {\n const json = Buffer.from(encodedRequestContext, 'base64').toString('utf-8');\n paramsRequestContext = JSON.parse(json);\n } catch {\n // ignore if still invalid\n }\n }\n }\n } catch {\n // ignore query parsing errors\n }\n }\n\n const requestContext = this.mergeRequestContext({ paramsRequestContext, bodyRequestContext });\n\n // Add relevant contexts to hono context\n c.set('requestContext', requestContext);\n c.set('mastra', this.mastra);\n c.set('tools', this.tools || {});\n c.set('taskStore', this.taskStore);\n c.set('playground', this.playground === true);\n c.set('isDev', this.isDev === true);\n c.set('customRouteAuthConfig', this.customRouteAuthConfig);\n c.set('abortSignal', c.req.raw.signal);\n\n return next();\n };\n }\n async stream(route: ServerRoute, res: Context, result: { fullStream: ReadableStream }): Promise<any> {\n res.header('Content-Type', 'text/plain');\n res.header('Transfer-Encoding', 'chunked');\n\n const streamFormat = route.streamFormat || 'stream';\n\n return stream(\n res,\n async stream => {\n const readableStream = result instanceof ReadableStream ? result : result.fullStream;\n const reader = readableStream.getReader();\n\n stream.onAbort(() => {\n void reader.cancel('request aborted');\n });\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n if (value) {\n if (streamFormat === 'sse') {\n await stream.write(`data: ${JSON.stringify(value)}\\n\\n`);\n } else {\n await stream.write(JSON.stringify(value) + '\\x1E');\n }\n }\n }\n\n await stream.write('data: [DONE]\\n\\n');\n } catch (error) {\n console.error(error);\n } finally {\n await stream.close();\n }\n },\n async err => {\n console.error(err);\n },\n );\n }\n\n async getParams(\n route: ServerRoute,\n request: HonoRequest,\n ): Promise<{ urlParams: Record<string, string>; queryParams: Record<string, string>; body: unknown }> {\n const urlParams = request.param();\n const queryParams = request.query();\n let body: unknown;\n if (route.method === 'POST' || route.method === 'PUT' || route.method === 'PATCH') {\n try {\n body = await request.json();\n } catch {}\n }\n return { urlParams, queryParams: queryParams as Record<string, string>, body };\n }\n\n async sendResponse(route: ServerRoute, response: Context, result: unknown): Promise<any> {\n if (route.responseType === 'json') {\n return response.json(result as any, 200);\n } else if (route.responseType === 'stream') {\n return this.stream(route, response, result as { fullStream: ReadableStream });\n } else if (route.responseType === 'datastream-response') {\n const fetchResponse = result as globalThis.Response;\n return fetchResponse;\n } else {\n return response.status(500);\n }\n }\n\n async registerRoute<E extends Env = any>(\n app: Hono<E, any, any>,\n route: ServerRoute,\n { prefix }: { prefix?: string },\n ): Promise<void> {\n // Determine if body limits should be applied\n const shouldApplyBodyLimit = this.bodyLimitOptions && ['POST', 'PUT', 'PATCH'].includes(route.method.toUpperCase());\n\n // Get the body size limit for this route (route-specific or default)\n const maxSize = route.maxBodySize ?? this.bodyLimitOptions?.maxSize;\n\n // Build middleware array\n const middlewares: MiddlewareHandler[] = [];\n\n if (shouldApplyBodyLimit && maxSize && this.bodyLimitOptions) {\n middlewares.push(\n bodyLimit({\n maxSize,\n onError: this.bodyLimitOptions.onError as any,\n }),\n );\n }\n\n app[route.method.toLowerCase() as 'get' | 'post' | 'put' | 'delete' | 'patch' | 'all'](\n `${prefix}${route.path}`,\n ...middlewares,\n async (c: Context) => {\n const params = await this.getParams(route, c.req);\n\n if (params.queryParams) {\n try {\n params.queryParams = await this.parseQueryParams(route, params.queryParams as Record<string, string>);\n } catch (error) {\n console.error('Error parsing query params', error);\n // Zod validation errors should return 400 Bad Request, not 500\n return c.json(\n {\n error: 'Invalid query parameters',\n details: error instanceof Error ? error.message : 'Unknown error',\n },\n 400,\n );\n }\n }\n\n if (params.body) {\n try {\n params.body = await this.parseBody(route, params.body);\n } catch (error) {\n console.error('Error parsing body', error);\n // Zod validation errors should return 400 Bad Request, not 500\n return c.json(\n {\n error: 'Invalid request body',\n details: error instanceof Error ? error.message : 'Unknown error',\n },\n 400,\n );\n }\n }\n\n const handlerParams = {\n ...params.urlParams,\n ...params.queryParams,\n ...(typeof params.body === 'object' ? params.body : {}),\n requestContext: c.get('requestContext'),\n mastra: this.mastra,\n tools: c.get('tools'),\n taskStore: c.get('taskStore'),\n abortSignal: c.get('abortSignal'),\n };\n\n try {\n const result = await route.handler(handlerParams);\n return this.sendResponse(route, c, result);\n } catch (error) {\n console.error('Error calling handler', error);\n // Check if it's an HTTPException or MastraError with a status code\n if (error && typeof error === 'object') {\n // Check for direct status property (HTTPException)\n if ('status' in error) {\n const status = (error as any).status;\n return c.json({ error: error instanceof Error ? error.message : 'Unknown error' }, status);\n }\n // Check for MastraError with status in details\n if ('details' in error && error.details && typeof error.details === 'object' && 'status' in error.details) {\n const status = (error.details as any).status;\n return c.json({ error: error instanceof Error ? error.message : 'Unknown error' }, status);\n }\n }\n return c.json({ error: error instanceof Error ? error.message : 'Unknown error' }, 500);\n }\n },\n );\n }\n\n registerContextMiddleware<E extends Env = any>(app: Hono<E, any, any>): void {\n app.use('*', this.createContextMiddleware());\n }\n\n async registerRoutes<E extends Env = any>(\n app: Hono<E, any, any>,\n { prefix, openapiPath }: { prefix?: string; openapiPath?: string },\n ): Promise<void> {\n // Cast to base type for super call - safe because registerRoute is generic\n await super.registerRoutes(app as any, { prefix, openapiPath });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../node_modules/.pnpm/hono@4.10.6/node_modules/hono/dist/http-exception.js","../../../node_modules/.pnpm/hono@4.10.6/node_modules/hono/dist/middleware/body-limit/index.js","../../../node_modules/.pnpm/hono@4.10.6/node_modules/hono/dist/utils/stream.js","../../../node_modules/.pnpm/hono@4.10.6/node_modules/hono/dist/helper/streaming/utils.js","../../../node_modules/.pnpm/hono@4.10.6/node_modules/hono/dist/helper/streaming/stream.js","../src/auth-middleware.ts","../src/index.ts"],"names":["isDevPlaygroundRequest","isProtectedPath","canAccessPublicly","checkRules","defaultAuthConfig","MastraServerBase","stream","redactStreamChunk","to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AM,CAAA;AAAA,YAC3F;AAAA,UACF;AACA,UAAA,OAAO,CAAA,CAAE,IAAA,CAAK,EAAE,KAAA,EAAO,KAAA,YAAiB,QAAQ,KAAA,CAAM,OAAA,GAAU,eAAA,EAAgB,EAAG,GAAG,CAAA;AAAA,QACxF;AAAA,MACF;AAAA,KACF;AAAA,EACF;AAAA,EAEA,yBAAA,GAAkC;AAChC,IAAA,IAAA,CAAK,GAAA,CAAI,GAAA,CAAI,GAAA,EAAK,IAAA,CAAK,yBAAyB,CAAA;AAAA,EAClD;AAAA,EAEA,sBAAA,GAA+B;AAC7B,IAAA,MAAM,UAAA,GAAa,IAAA,CAAK,MAAA,CAAO,SAAA,EAAU,EAAG,IAAA;AAC5C,IAAA,IAAI,CAAC,UAAA,EAAY;AAEf,MAAA;AAAA,IACF;AAEA,IAAA,IAAA,CAAK,GAAA,CAAI,GAAA,CAAI,GAAA,EAAK,wBAAwB,CAAA;AAC1C,IAAA,IAAA,CAAK,GAAA,CAAI,GAAA,CAAI,GAAA,EAAK,uBAAuB,CAAA;AAAA,EAC3C;AACF","file":"index.cjs","sourcesContent":["// src/http-exception.ts\nvar HTTPException = class extends Error {\n res;\n status;\n constructor(status = 500, options) {\n super(options?.message, { cause: options?.cause });\n this.res = options?.res;\n this.status = status;\n }\n getResponse() {\n if (this.res) {\n const newResponse = new Response(this.res.body, {\n status: this.status,\n headers: this.res.headers\n });\n return newResponse;\n }\n return new Response(this.message, {\n status: this.status\n });\n }\n};\nexport {\n HTTPException\n};\n","// src/middleware/body-limit/index.ts\nimport { HTTPException } from \"../../http-exception.js\";\nvar ERROR_MESSAGE = \"Payload Too Large\";\nvar BodyLimitError = class extends Error {\n constructor(message) {\n super(message);\n this.name = \"BodyLimitError\";\n }\n};\nvar bodyLimit = (options) => {\n const onError = options.onError || (() => {\n const res = new Response(ERROR_MESSAGE, {\n status: 413\n });\n throw new HTTPException(413, { res });\n });\n const maxSize = options.maxSize;\n return async function bodyLimit2(c, next) {\n if (!c.req.raw.body) {\n return next();\n }\n const hasTransferEncoding = c.req.raw.headers.has(\"transfer-encoding\");\n const hasContentLength = c.req.raw.headers.has(\"content-length\");\n if (hasTransferEncoding && hasContentLength) {\n }\n if (hasContentLength && !hasTransferEncoding) {\n const contentLength = parseInt(c.req.raw.headers.get(\"content-length\") || \"0\", 10);\n return contentLength > maxSize ? onError(c) : next();\n }\n let size = 0;\n const rawReader = c.req.raw.body.getReader();\n const reader = new ReadableStream({\n async start(controller) {\n try {\n for (; ; ) {\n const { done, value } = await rawReader.read();\n if (done) {\n break;\n }\n size += value.length;\n if (size > maxSize) {\n controller.error(new BodyLimitError(ERROR_MESSAGE));\n break;\n }\n controller.enqueue(value);\n }\n } finally {\n controller.close();\n }\n }\n });\n const requestInit = { body: reader, duplex: \"half\" };\n c.req.raw = new Request(c.req.raw, requestInit);\n await next();\n if (c.error instanceof BodyLimitError) {\n c.res = await onError(c);\n }\n };\n};\nexport {\n bodyLimit\n};\n","// src/utils/stream.ts\nvar StreamingApi = class {\n writer;\n encoder;\n writable;\n abortSubscribers = [];\n responseReadable;\n aborted = false;\n closed = false;\n constructor(writable, _readable) {\n this.writable = writable;\n this.writer = writable.getWriter();\n this.encoder = new TextEncoder();\n const reader = _readable.getReader();\n this.abortSubscribers.push(async () => {\n await reader.cancel();\n });\n this.responseReadable = new ReadableStream({\n async pull(controller) {\n const { done, value } = await reader.read();\n done ? controller.close() : controller.enqueue(value);\n },\n cancel: () => {\n this.abort();\n }\n });\n }\n async write(input) {\n try {\n if (typeof input === \"string\") {\n input = this.encoder.encode(input);\n }\n await this.writer.write(input);\n } catch {\n }\n return this;\n }\n async writeln(input) {\n await this.write(input + \"\\n\");\n return this;\n }\n sleep(ms) {\n return new Promise((res) => setTimeout(res, ms));\n }\n async close() {\n try {\n await this.writer.close();\n } catch {\n }\n this.closed = true;\n }\n async pipe(body) {\n this.writer.releaseLock();\n await body.pipeTo(this.writable, { preventClose: true });\n this.writer = this.writable.getWriter();\n }\n onAbort(listener) {\n this.abortSubscribers.push(listener);\n }\n abort() {\n if (!this.aborted) {\n this.aborted = true;\n this.abortSubscribers.forEach((subscriber) => subscriber());\n }\n }\n};\nexport {\n StreamingApi\n};\n","// src/helper/streaming/utils.ts\nvar isOldBunVersion = () => {\n const version = typeof Bun !== \"undefined\" ? Bun.version : void 0;\n if (version === void 0) {\n return false;\n }\n const result = version.startsWith(\"1.1\") || version.startsWith(\"1.0\") || version.startsWith(\"0.\");\n isOldBunVersion = () => result;\n return result;\n};\nexport {\n isOldBunVersion\n};\n","// src/helper/streaming/stream.ts\nimport { StreamingApi } from \"../../utils/stream.js\";\nimport { isOldBunVersion } from \"./utils.js\";\nvar contextStash = /* @__PURE__ */ new WeakMap();\nvar stream = (c, cb, onError) => {\n const { readable, writable } = new TransformStream();\n const stream2 = new StreamingApi(writable, readable);\n if (isOldBunVersion()) {\n c.req.raw.signal.addEventListener(\"abort\", () => {\n if (!stream2.closed) {\n stream2.abort();\n }\n });\n }\n contextStash.set(stream2.responseReadable, c);\n (async () => {\n try {\n await cb(stream2);\n } catch (e) {\n if (e === void 0) {\n } else if (e instanceof Error && onError) {\n await onError(e, stream2);\n } else {\n console.error(e);\n }\n } finally {\n stream2.close();\n }\n })();\n return c.newResponse(stream2.responseReadable);\n};\nexport {\n stream\n};\n","import type { ContextWithMastra } from '@mastra/core/server';\nimport {\n canAccessPublicly,\n checkRules,\n defaultAuthConfig,\n isDevPlaygroundRequest,\n isProtectedPath,\n} from '@mastra/server/auth';\nimport type { Next } from 'hono';\n\nexport const authenticationMiddleware = async (c: ContextWithMastra, next: Next) => {\n const mastra = c.get('mastra');\n const authConfig = mastra.getServer()?.auth;\n const customRouteAuthConfig = c.get('customRouteAuthConfig');\n\n if (!authConfig) {\n // No auth config, skip authentication\n return next();\n }\n\n const path = c.req.path;\n const method = c.req.method;\n const getHeader = (name: string) => c.req.header(name);\n\n if (isDevPlaygroundRequest(path, method, getHeader, authConfig)) {\n // Skip authentication for dev playground requests\n return next();\n }\n\n if (!isProtectedPath(c.req.path, c.req.method, authConfig, customRouteAuthConfig)) {\n return next();\n }\n\n // Skip authentication for public routes\n if (canAccessPublicly(c.req.path, c.req.method, authConfig)) {\n return next();\n }\n\n // Get token from header or query\n const authHeader = c.req.header('Authorization');\n let token: string | null = authHeader ? authHeader.replace('Bearer ', '') : null;\n\n if (!token && c.req.query('apiKey')) {\n token = c.req.query('apiKey') || null;\n }\n\n // Handle missing token\n if (!token) {\n return c.json({ error: 'Authentication required' }, 401);\n }\n\n try {\n // Verify token and get user data\n let user: unknown;\n\n // Client provided verify function\n if (typeof authConfig.authenticateToken === 'function') {\n user = await authConfig.authenticateToken(token, c.req);\n } else {\n throw new Error('No token verification method configured');\n }\n\n if (!user) {\n return c.json({ error: 'Invalid or expired token' }, 401);\n }\n\n // Store user in context\n c.get('requestContext').set('user', user);\n\n return next();\n } catch (err) {\n console.error(err);\n return c.json({ error: 'Invalid or expired token' }, 401);\n }\n};\n\nexport const authorizationMiddleware = async (c: ContextWithMastra, next: Next) => {\n const mastra = c.get('mastra');\n const authConfig = mastra.getServer()?.auth;\n const customRouteAuthConfig = c.get('customRouteAuthConfig');\n\n if (!authConfig) {\n // No auth config, skip authorization\n return next();\n }\n\n const path = c.req.path;\n const method = c.req.method;\n const getHeader = (name: string) => c.req.header(name);\n\n if (isDevPlaygroundRequest(path, method, getHeader, authConfig)) {\n // Skip authorization for dev playground requests\n return next();\n }\n\n if (!isProtectedPath(c.req.path, c.req.method, authConfig, customRouteAuthConfig)) {\n return next();\n }\n\n // Skip for public routes\n if (canAccessPublicly(path, method, authConfig)) {\n return next();\n }\n\n const user = c.get('requestContext').get('user');\n\n if ('authorizeUser' in authConfig && typeof authConfig.authorizeUser === 'function') {\n try {\n const isAuthorized = await authConfig.authorizeUser(user, c.req);\n\n if (isAuthorized) {\n return next();\n }\n\n return c.json({ error: 'Access denied' }, 403);\n } catch (err) {\n console.error(err);\n return c.json({ error: 'Authorization error' }, 500);\n }\n }\n\n // Client-provided authorization function\n if ('authorize' in authConfig && typeof authConfig.authorize === 'function') {\n try {\n const isAuthorized = await authConfig.authorize(path, method, user, c);\n\n if (isAuthorized) {\n return next();\n }\n\n return c.json({ error: 'Access denied' }, 403);\n } catch (err) {\n console.error(err);\n return c.json({ error: 'Authorization error' }, 500);\n }\n }\n\n // Custom rule-based authorization\n if ('rules' in authConfig && authConfig.rules && authConfig.rules.length > 0) {\n const isAuthorized = await checkRules(authConfig.rules, path, method, user);\n\n if (isAuthorized) {\n return next();\n }\n\n return c.json({ error: 'Access denied' }, 403);\n }\n\n // Default rule-based authorization\n if (defaultAuthConfig.rules && defaultAuthConfig.rules.length > 0) {\n const isAuthorized = await checkRules(defaultAuthConfig.rules, path, method, user);\n\n if (isAuthorized) {\n return next();\n }\n }\n\n return c.json({ error: 'Access denied' }, 403);\n};\n","import type { Mastra } from '@mastra/core/mastra';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport type { Tool } from '@mastra/core/tools';\nimport type { InMemoryTaskStore } from '@mastra/server/a2a/store';\nimport type { MCPHttpTransportResult, MCPSseTransportResult } from '@mastra/server/handlers/mcp';\nimport { MastraServer as MastraServerBase, redactStreamChunk } from '@mastra/server/server-adapter';\nimport type { ServerRoute } from '@mastra/server/server-adapter';\nimport { toReqRes, toFetchResponse } from 'fetch-to-node';\nimport type { Context, Env, Hono, HonoRequest, MiddlewareHandler } from 'hono';\nimport { bodyLimit } from 'hono/body-limit';\nimport { stream } from 'hono/streaming';\n\nimport { authenticationMiddleware, authorizationMiddleware } from './auth-middleware';\n\n// Export type definitions for Hono app configuration\nexport type HonoVariables = {\n mastra: Mastra;\n requestContext: RequestContext;\n tools: Record<string, Tool>;\n abortSignal: AbortSignal;\n taskStore: InMemoryTaskStore;\n customRouteAuthConfig?: Map<string, boolean>;\n playground?: boolean;\n isDev?: boolean;\n};\n\nexport type HonoBindings = {};\n\nexport class MastraServer extends MastraServerBase<Hono<any, any, any>, HonoRequest, Context> {\n createContextMiddleware(): MiddlewareHandler {\n return async (c, next) => {\n // Parse request context from request body and add to context\n\n let bodyRequestContext: Record<string, any> | undefined;\n let paramsRequestContext: Record<string, any> | undefined;\n\n // Parse request context from request body (POST/PUT)\n if (c.req.method === 'POST' || c.req.method === 'PUT') {\n const contentType = c.req.header('content-type');\n if (contentType?.includes('application/json')) {\n try {\n const clonedReq = c.req.raw.clone();\n const body = (await clonedReq.json()) as { requestContext?: Record<string, any> };\n if (body.requestContext) {\n bodyRequestContext = body.requestContext;\n }\n } catch {\n // Body parsing failed, continue without body\n }\n }\n }\n\n // Parse request context from query params (GET)\n if (c.req.method === 'GET') {\n try {\n const encodedRequestContext = c.req.query('requestContext');\n if (encodedRequestContext) {\n // Try JSON first\n try {\n paramsRequestContext = JSON.parse(encodedRequestContext);\n } catch {\n // Fallback to base64(JSON)\n try {\n const json = Buffer.from(encodedRequestContext, 'base64').toString('utf-8');\n paramsRequestContext = JSON.parse(json);\n } catch {\n // ignore if still invalid\n }\n }\n }\n } catch {\n // ignore query parsing errors\n }\n }\n\n const requestContext = this.mergeRequestContext({ paramsRequestContext, bodyRequestContext });\n\n // Add relevant contexts to hono context\n c.set('requestContext', requestContext);\n c.set('mastra', this.mastra);\n c.set('tools', this.tools || {});\n c.set('taskStore', this.taskStore);\n c.set('playground', this.playground === true);\n c.set('isDev', this.isDev === true);\n c.set('abortSignal', c.req.raw.signal);\n c.set('customRouteAuthConfig', this.customRouteAuthConfig);\n\n return next();\n };\n }\n async stream(route: ServerRoute, res: Context, result: { fullStream: ReadableStream }): Promise<any> {\n res.header('Content-Type', 'text/plain');\n res.header('Transfer-Encoding', 'chunked');\n\n const streamFormat = route.streamFormat || 'stream';\n\n return stream(\n res,\n async stream => {\n const readableStream = result instanceof ReadableStream ? result : result.fullStream;\n const reader = readableStream.getReader();\n\n stream.onAbort(() => {\n void reader.cancel('request aborted');\n });\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n if (value) {\n // Optionally redact sensitive data (system prompts, tool definitions, API keys) before sending to the client\n const shouldRedact = this.streamOptions?.redact ?? true;\n const outputValue = shouldRedact ? redactStreamChunk(value) : value;\n if (streamFormat === 'sse') {\n await stream.write(`data: ${JSON.stringify(outputValue)}\\n\\n`);\n } else {\n await stream.write(JSON.stringify(outputValue) + '\\x1E');\n }\n }\n }\n\n await stream.write('data: [DONE]\\n\\n');\n } catch (error) {\n console.error(error);\n } finally {\n await stream.close();\n }\n },\n async err => {\n console.error(err);\n },\n );\n }\n\n async getParams(\n route: ServerRoute,\n request: HonoRequest,\n ): Promise<{ urlParams: Record<string, string>; queryParams: Record<string, string>; body: unknown }> {\n const urlParams = request.param();\n const queryParams = request.query();\n let body: unknown;\n if (route.method === 'POST' || route.method === 'PUT' || route.method === 'PATCH') {\n try {\n body = await request.json();\n } catch {}\n }\n return { urlParams, queryParams: queryParams as Record<string, string>, body };\n }\n\n async sendResponse(route: ServerRoute, response: Context, result: unknown): Promise<any> {\n if (route.responseType === 'json') {\n return response.json(result as any, 200);\n } else if (route.responseType === 'stream') {\n return this.stream(route, response, result as { fullStream: ReadableStream });\n } else if (route.responseType === 'datastream-response') {\n const fetchResponse = result as globalThis.Response;\n return fetchResponse;\n } else if (route.responseType === 'mcp-http') {\n // MCP Streamable HTTP transport\n const { server, httpPath } = result as MCPHttpTransportResult;\n const { req, res } = toReqRes(response.req.raw);\n\n try {\n await server.startHTTP({\n url: new URL(response.req.url),\n httpPath,\n req,\n res,\n });\n return await toFetchResponse(res);\n } catch {\n if (!res.headersSent) {\n res.writeHead(500, { 'Content-Type': 'application/json' });\n res.end(\n JSON.stringify({\n jsonrpc: '2.0',\n error: { code: -32603, message: 'Internal server error' },\n id: null,\n }),\n );\n return await toFetchResponse(res);\n }\n return await toFetchResponse(res);\n }\n } else if (route.responseType === 'mcp-sse') {\n // MCP SSE transport\n const { server, ssePath, messagePath } = result as MCPSseTransportResult;\n\n try {\n return await server.startHonoSSE({\n url: new URL(response.req.url),\n ssePath,\n messagePath,\n context: response,\n });\n } catch {\n return response.json({ error: 'Error handling MCP SSE request' }, 500);\n }\n } else {\n return response.status(500);\n }\n }\n\n async registerRoute<E extends Env = any>(\n app: Hono<E, any, any>,\n route: ServerRoute,\n { prefix }: { prefix?: string },\n ): Promise<void> {\n // Determine if body limits should be applied\n const shouldApplyBodyLimit = this.bodyLimitOptions && ['POST', 'PUT', 'PATCH'].includes(route.method.toUpperCase());\n\n // Get the body size limit for this route (route-specific or default)\n const maxSize = route.maxBodySize ?? this.bodyLimitOptions?.maxSize;\n\n // Build middleware array\n const middlewares: MiddlewareHandler[] = [];\n\n if (shouldApplyBodyLimit && maxSize && this.bodyLimitOptions) {\n middlewares.push(\n bodyLimit({\n maxSize,\n onError: this.bodyLimitOptions.onError as any,\n }),\n );\n }\n\n app[route.method.toLowerCase() as 'get' | 'post' | 'put' | 'delete' | 'patch' | 'all'](\n `${prefix}${route.path}`,\n ...middlewares,\n async (c: Context) => {\n const params = await this.getParams(route, c.req);\n\n if (params.queryParams) {\n try {\n params.queryParams = await this.parseQueryParams(route, params.queryParams as Record<string, string>);\n } catch (error) {\n console.error('Error parsing query params', error);\n // Zod validation errors should return 400 Bad Request, not 500\n return c.json(\n {\n error: 'Invalid query parameters',\n details: error instanceof Error ? error.message : 'Unknown error',\n },\n 400,\n );\n }\n }\n\n if (params.body) {\n try {\n params.body = await this.parseBody(route, params.body);\n } catch (error) {\n console.error('Error parsing body:', error instanceof Error ? error.message : String(error));\n // Zod validation errors should return 400 Bad Request, not 500\n return c.json(\n {\n error: 'Invalid request body',\n details: error instanceof Error ? error.message : 'Unknown error',\n },\n 400,\n );\n }\n }\n\n const handlerParams = {\n ...params.urlParams,\n ...params.queryParams,\n ...(typeof params.body === 'object' ? params.body : {}),\n requestContext: c.get('requestContext'),\n mastra: this.mastra,\n tools: c.get('tools'),\n taskStore: c.get('taskStore'),\n abortSignal: c.get('abortSignal'),\n };\n\n try {\n const result = await route.handler(handlerParams);\n return this.sendResponse(route, c, result);\n } catch (error) {\n console.error('Error calling handler', error);\n // Check if it's an HTTPException or MastraError with a status code\n if (error && typeof error === 'object') {\n // Check for direct status property (HTTPException)\n if ('status' in error) {\n const status = (error as any).status;\n return c.json({ error: error instanceof Error ? error.message : 'Unknown error' }, status);\n }\n // Check for MastraError with status in details\n if ('details' in error && error.details && typeof error.details === 'object' && 'status' in error.details) {\n const status = (error.details as any).status;\n return c.json({ error: error instanceof Error ? error.message : 'Unknown error' }, status);\n }\n }\n return c.json({ error: error instanceof Error ? error.message : 'Unknown error' }, 500);\n }\n },\n );\n }\n\n registerContextMiddleware(): void {\n this.app.use('*', this.createContextMiddleware());\n }\n\n registerAuthMiddleware(): void {\n const authConfig = this.mastra.getServer()?.auth;\n if (!authConfig) {\n // No auth config, skip registration\n return;\n }\n\n this.app.use('*', authenticationMiddleware);\n this.app.use('*', authorizationMiddleware);\n }\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Mastra } from '@mastra/core/mastra';
|
|
2
2
|
import type { RequestContext } from '@mastra/core/request-context';
|
|
3
3
|
import type { Tool } from '@mastra/core/tools';
|
|
4
|
-
import { InMemoryTaskStore } from '@mastra/server/a2a/store';
|
|
5
|
-
import {
|
|
6
|
-
import type {
|
|
4
|
+
import type { InMemoryTaskStore } from '@mastra/server/a2a/store';
|
|
5
|
+
import { MastraServer as MastraServerBase } from '@mastra/server/server-adapter';
|
|
6
|
+
import type { ServerRoute } from '@mastra/server/server-adapter';
|
|
7
7
|
import type { Context, Env, Hono, HonoRequest, MiddlewareHandler } from 'hono';
|
|
8
8
|
export type HonoVariables = {
|
|
9
9
|
mastra: Mastra;
|
|
@@ -16,20 +16,7 @@ export type HonoVariables = {
|
|
|
16
16
|
isDev?: boolean;
|
|
17
17
|
};
|
|
18
18
|
export type HonoBindings = {};
|
|
19
|
-
export declare class
|
|
20
|
-
private taskStore;
|
|
21
|
-
private customRouteAuthConfig?;
|
|
22
|
-
private playground?;
|
|
23
|
-
private isDev?;
|
|
24
|
-
constructor({ mastra, tools, taskStore, customRouteAuthConfig, playground, isDev, bodyLimitOptions, }: {
|
|
25
|
-
mastra: Mastra;
|
|
26
|
-
tools?: Record<string, Tool>;
|
|
27
|
-
taskStore?: InMemoryTaskStore;
|
|
28
|
-
customRouteAuthConfig?: Map<string, boolean>;
|
|
29
|
-
playground?: boolean;
|
|
30
|
-
isDev?: boolean;
|
|
31
|
-
bodyLimitOptions?: BodyLimitOptions;
|
|
32
|
-
});
|
|
19
|
+
export declare class MastraServer extends MastraServerBase<Hono<any, any, any>, HonoRequest, Context> {
|
|
33
20
|
createContextMiddleware(): MiddlewareHandler;
|
|
34
21
|
stream(route: ServerRoute, res: Context, result: {
|
|
35
22
|
fullStream: ReadableStream;
|
|
@@ -43,10 +30,7 @@ export declare class HonoServerAdapter extends MastraServerAdapter<Hono<any, any
|
|
|
43
30
|
registerRoute<E extends Env = any>(app: Hono<E, any, any>, route: ServerRoute, { prefix }: {
|
|
44
31
|
prefix?: string;
|
|
45
32
|
}): Promise<void>;
|
|
46
|
-
registerContextMiddleware
|
|
47
|
-
|
|
48
|
-
prefix?: string;
|
|
49
|
-
openapiPath?: string;
|
|
50
|
-
}): Promise<void>;
|
|
33
|
+
registerContextMiddleware(): void;
|
|
34
|
+
registerAuthMiddleware(): void;
|
|
51
35
|
}
|
|
52
36
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.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AAK,EAAE,WAAW,EAClB,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,CAAC;IAY/F,YAAY,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC;IAsDlF,aAAa,CAAC,CAAC,SAAS,GAAG,GAAG,GAAG,EACrC,GAAG,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,EACtB,KAAK,EAAE,WAAW,EAClB,EAAE,MAAM,EAAE,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAC9B,OAAO,CAAC,IAAI,CAAC;IA4FhB,yBAAyB,IAAI,IAAI;IAIjC,sBAAsB,IAAI,IAAI;CAU/B"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { MastraServer as MastraServer$1, redactStreamChunk } from '@mastra/server/server-adapter';
|
|
2
|
+
import { toReqRes, toFetchResponse } from 'fetch-to-node';
|
|
3
|
+
import { isDevPlaygroundRequest, isProtectedPath, canAccessPublicly, checkRules, defaultAuthConfig } from '@mastra/server/auth';
|
|
3
4
|
|
|
4
5
|
// src/index.ts
|
|
5
6
|
|
|
6
|
-
// ../../node_modules/.pnpm/hono@4.10.
|
|
7
|
+
// ../../node_modules/.pnpm/hono@4.10.6/node_modules/hono/dist/http-exception.js
|
|
7
8
|
var HTTPException = class extends Error {
|
|
8
9
|
res;
|
|
9
10
|
status;
|
|
@@ -26,7 +27,7 @@ var HTTPException = class extends Error {
|
|
|
26
27
|
}
|
|
27
28
|
};
|
|
28
29
|
|
|
29
|
-
// ../../node_modules/.pnpm/hono@4.10.
|
|
30
|
+
// ../../node_modules/.pnpm/hono@4.10.6/node_modules/hono/dist/middleware/body-limit/index.js
|
|
30
31
|
var ERROR_MESSAGE = "Payload Too Large";
|
|
31
32
|
var BodyLimitError = class extends Error {
|
|
32
33
|
constructor(message) {
|
|
@@ -83,7 +84,7 @@ var bodyLimit = (options) => {
|
|
|
83
84
|
};
|
|
84
85
|
};
|
|
85
86
|
|
|
86
|
-
// ../../node_modules/.pnpm/hono@4.10.
|
|
87
|
+
// ../../node_modules/.pnpm/hono@4.10.6/node_modules/hono/dist/utils/stream.js
|
|
87
88
|
var StreamingApi = class {
|
|
88
89
|
writer;
|
|
89
90
|
encoder;
|
|
@@ -150,7 +151,7 @@ var StreamingApi = class {
|
|
|
150
151
|
}
|
|
151
152
|
};
|
|
152
153
|
|
|
153
|
-
// ../../node_modules/.pnpm/hono@4.10.
|
|
154
|
+
// ../../node_modules/.pnpm/hono@4.10.6/node_modules/hono/dist/helper/streaming/utils.js
|
|
154
155
|
var isOldBunVersion = () => {
|
|
155
156
|
const version = typeof Bun !== "undefined" ? Bun.version : void 0;
|
|
156
157
|
if (version === void 0) {
|
|
@@ -161,7 +162,7 @@ var isOldBunVersion = () => {
|
|
|
161
162
|
return result;
|
|
162
163
|
};
|
|
163
164
|
|
|
164
|
-
// ../../node_modules/.pnpm/hono@4.10.
|
|
165
|
+
// ../../node_modules/.pnpm/hono@4.10.6/node_modules/hono/dist/helper/streaming/stream.js
|
|
165
166
|
var contextStash = /* @__PURE__ */ new WeakMap();
|
|
166
167
|
var stream = (c, cb, onError) => {
|
|
167
168
|
const { readable, writable } = new TransformStream();
|
|
@@ -189,28 +190,112 @@ var stream = (c, cb, onError) => {
|
|
|
189
190
|
})();
|
|
190
191
|
return c.newResponse(stream2.responseReadable);
|
|
191
192
|
};
|
|
193
|
+
var authenticationMiddleware = async (c, next) => {
|
|
194
|
+
const mastra = c.get("mastra");
|
|
195
|
+
const authConfig = mastra.getServer()?.auth;
|
|
196
|
+
const customRouteAuthConfig = c.get("customRouteAuthConfig");
|
|
197
|
+
if (!authConfig) {
|
|
198
|
+
return next();
|
|
199
|
+
}
|
|
200
|
+
const path = c.req.path;
|
|
201
|
+
const method = c.req.method;
|
|
202
|
+
const getHeader = (name) => c.req.header(name);
|
|
203
|
+
if (isDevPlaygroundRequest(path, method, getHeader, authConfig)) {
|
|
204
|
+
return next();
|
|
205
|
+
}
|
|
206
|
+
if (!isProtectedPath(c.req.path, c.req.method, authConfig, customRouteAuthConfig)) {
|
|
207
|
+
return next();
|
|
208
|
+
}
|
|
209
|
+
if (canAccessPublicly(c.req.path, c.req.method, authConfig)) {
|
|
210
|
+
return next();
|
|
211
|
+
}
|
|
212
|
+
const authHeader = c.req.header("Authorization");
|
|
213
|
+
let token = authHeader ? authHeader.replace("Bearer ", "") : null;
|
|
214
|
+
if (!token && c.req.query("apiKey")) {
|
|
215
|
+
token = c.req.query("apiKey") || null;
|
|
216
|
+
}
|
|
217
|
+
if (!token) {
|
|
218
|
+
return c.json({ error: "Authentication required" }, 401);
|
|
219
|
+
}
|
|
220
|
+
try {
|
|
221
|
+
let user;
|
|
222
|
+
if (typeof authConfig.authenticateToken === "function") {
|
|
223
|
+
user = await authConfig.authenticateToken(token, c.req);
|
|
224
|
+
} else {
|
|
225
|
+
throw new Error("No token verification method configured");
|
|
226
|
+
}
|
|
227
|
+
if (!user) {
|
|
228
|
+
return c.json({ error: "Invalid or expired token" }, 401);
|
|
229
|
+
}
|
|
230
|
+
c.get("requestContext").set("user", user);
|
|
231
|
+
return next();
|
|
232
|
+
} catch (err) {
|
|
233
|
+
console.error(err);
|
|
234
|
+
return c.json({ error: "Invalid or expired token" }, 401);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
var authorizationMiddleware = async (c, next) => {
|
|
238
|
+
const mastra = c.get("mastra");
|
|
239
|
+
const authConfig = mastra.getServer()?.auth;
|
|
240
|
+
const customRouteAuthConfig = c.get("customRouteAuthConfig");
|
|
241
|
+
if (!authConfig) {
|
|
242
|
+
return next();
|
|
243
|
+
}
|
|
244
|
+
const path = c.req.path;
|
|
245
|
+
const method = c.req.method;
|
|
246
|
+
const getHeader = (name) => c.req.header(name);
|
|
247
|
+
if (isDevPlaygroundRequest(path, method, getHeader, authConfig)) {
|
|
248
|
+
return next();
|
|
249
|
+
}
|
|
250
|
+
if (!isProtectedPath(c.req.path, c.req.method, authConfig, customRouteAuthConfig)) {
|
|
251
|
+
return next();
|
|
252
|
+
}
|
|
253
|
+
if (canAccessPublicly(path, method, authConfig)) {
|
|
254
|
+
return next();
|
|
255
|
+
}
|
|
256
|
+
const user = c.get("requestContext").get("user");
|
|
257
|
+
if ("authorizeUser" in authConfig && typeof authConfig.authorizeUser === "function") {
|
|
258
|
+
try {
|
|
259
|
+
const isAuthorized = await authConfig.authorizeUser(user, c.req);
|
|
260
|
+
if (isAuthorized) {
|
|
261
|
+
return next();
|
|
262
|
+
}
|
|
263
|
+
return c.json({ error: "Access denied" }, 403);
|
|
264
|
+
} catch (err) {
|
|
265
|
+
console.error(err);
|
|
266
|
+
return c.json({ error: "Authorization error" }, 500);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if ("authorize" in authConfig && typeof authConfig.authorize === "function") {
|
|
270
|
+
try {
|
|
271
|
+
const isAuthorized = await authConfig.authorize(path, method, user, c);
|
|
272
|
+
if (isAuthorized) {
|
|
273
|
+
return next();
|
|
274
|
+
}
|
|
275
|
+
return c.json({ error: "Access denied" }, 403);
|
|
276
|
+
} catch (err) {
|
|
277
|
+
console.error(err);
|
|
278
|
+
return c.json({ error: "Authorization error" }, 500);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if ("rules" in authConfig && authConfig.rules && authConfig.rules.length > 0) {
|
|
282
|
+
const isAuthorized = await checkRules(authConfig.rules, path, method, user);
|
|
283
|
+
if (isAuthorized) {
|
|
284
|
+
return next();
|
|
285
|
+
}
|
|
286
|
+
return c.json({ error: "Access denied" }, 403);
|
|
287
|
+
}
|
|
288
|
+
if (defaultAuthConfig.rules && defaultAuthConfig.rules.length > 0) {
|
|
289
|
+
const isAuthorized = await checkRules(defaultAuthConfig.rules, path, method, user);
|
|
290
|
+
if (isAuthorized) {
|
|
291
|
+
return next();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return c.json({ error: "Access denied" }, 403);
|
|
295
|
+
};
|
|
192
296
|
|
|
193
297
|
// src/index.ts
|
|
194
|
-
var
|
|
195
|
-
taskStore;
|
|
196
|
-
customRouteAuthConfig;
|
|
197
|
-
playground;
|
|
198
|
-
isDev;
|
|
199
|
-
constructor({
|
|
200
|
-
mastra,
|
|
201
|
-
tools,
|
|
202
|
-
taskStore,
|
|
203
|
-
customRouteAuthConfig,
|
|
204
|
-
playground,
|
|
205
|
-
isDev,
|
|
206
|
-
bodyLimitOptions
|
|
207
|
-
}) {
|
|
208
|
-
super({ mastra, bodyLimitOptions, tools });
|
|
209
|
-
this.taskStore = taskStore || new InMemoryTaskStore();
|
|
210
|
-
this.customRouteAuthConfig = customRouteAuthConfig;
|
|
211
|
-
this.playground = playground;
|
|
212
|
-
this.isDev = isDev;
|
|
213
|
-
}
|
|
298
|
+
var MastraServer = class extends MastraServer$1 {
|
|
214
299
|
createContextMiddleware() {
|
|
215
300
|
return async (c, next) => {
|
|
216
301
|
let bodyRequestContext;
|
|
@@ -252,8 +337,8 @@ var HonoServerAdapter = class extends MastraServerAdapter {
|
|
|
252
337
|
c.set("taskStore", this.taskStore);
|
|
253
338
|
c.set("playground", this.playground === true);
|
|
254
339
|
c.set("isDev", this.isDev === true);
|
|
255
|
-
c.set("customRouteAuthConfig", this.customRouteAuthConfig);
|
|
256
340
|
c.set("abortSignal", c.req.raw.signal);
|
|
341
|
+
c.set("customRouteAuthConfig", this.customRouteAuthConfig);
|
|
257
342
|
return next();
|
|
258
343
|
};
|
|
259
344
|
}
|
|
@@ -274,12 +359,14 @@ var HonoServerAdapter = class extends MastraServerAdapter {
|
|
|
274
359
|
const { done, value } = await reader.read();
|
|
275
360
|
if (done) break;
|
|
276
361
|
if (value) {
|
|
362
|
+
const shouldRedact = this.streamOptions?.redact ?? true;
|
|
363
|
+
const outputValue = shouldRedact ? redactStreamChunk(value) : value;
|
|
277
364
|
if (streamFormat === "sse") {
|
|
278
|
-
await stream2.write(`data: ${JSON.stringify(
|
|
365
|
+
await stream2.write(`data: ${JSON.stringify(outputValue)}
|
|
279
366
|
|
|
280
367
|
`);
|
|
281
368
|
} else {
|
|
282
|
-
await stream2.write(JSON.stringify(
|
|
369
|
+
await stream2.write(JSON.stringify(outputValue) + "");
|
|
283
370
|
}
|
|
284
371
|
}
|
|
285
372
|
}
|
|
@@ -315,6 +402,43 @@ var HonoServerAdapter = class extends MastraServerAdapter {
|
|
|
315
402
|
} else if (route.responseType === "datastream-response") {
|
|
316
403
|
const fetchResponse = result;
|
|
317
404
|
return fetchResponse;
|
|
405
|
+
} else if (route.responseType === "mcp-http") {
|
|
406
|
+
const { server, httpPath } = result;
|
|
407
|
+
const { req, res } = toReqRes(response.req.raw);
|
|
408
|
+
try {
|
|
409
|
+
await server.startHTTP({
|
|
410
|
+
url: new URL(response.req.url),
|
|
411
|
+
httpPath,
|
|
412
|
+
req,
|
|
413
|
+
res
|
|
414
|
+
});
|
|
415
|
+
return await toFetchResponse(res);
|
|
416
|
+
} catch {
|
|
417
|
+
if (!res.headersSent) {
|
|
418
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
419
|
+
res.end(
|
|
420
|
+
JSON.stringify({
|
|
421
|
+
jsonrpc: "2.0",
|
|
422
|
+
error: { code: -32603, message: "Internal server error" },
|
|
423
|
+
id: null
|
|
424
|
+
})
|
|
425
|
+
);
|
|
426
|
+
return await toFetchResponse(res);
|
|
427
|
+
}
|
|
428
|
+
return await toFetchResponse(res);
|
|
429
|
+
}
|
|
430
|
+
} else if (route.responseType === "mcp-sse") {
|
|
431
|
+
const { server, ssePath, messagePath } = result;
|
|
432
|
+
try {
|
|
433
|
+
return await server.startHonoSSE({
|
|
434
|
+
url: new URL(response.req.url),
|
|
435
|
+
ssePath,
|
|
436
|
+
messagePath,
|
|
437
|
+
context: response
|
|
438
|
+
});
|
|
439
|
+
} catch {
|
|
440
|
+
return response.json({ error: "Error handling MCP SSE request" }, 500);
|
|
441
|
+
}
|
|
318
442
|
} else {
|
|
319
443
|
return response.status(500);
|
|
320
444
|
}
|
|
@@ -354,7 +478,7 @@ var HonoServerAdapter = class extends MastraServerAdapter {
|
|
|
354
478
|
try {
|
|
355
479
|
params.body = await this.parseBody(route, params.body);
|
|
356
480
|
} catch (error) {
|
|
357
|
-
console.error("Error parsing body", error);
|
|
481
|
+
console.error("Error parsing body:", error instanceof Error ? error.message : String(error));
|
|
358
482
|
return c.json(
|
|
359
483
|
{
|
|
360
484
|
error: "Invalid request body",
|
|
@@ -394,14 +518,19 @@ var HonoServerAdapter = class extends MastraServerAdapter {
|
|
|
394
518
|
}
|
|
395
519
|
);
|
|
396
520
|
}
|
|
397
|
-
registerContextMiddleware(
|
|
398
|
-
app.use("*", this.createContextMiddleware());
|
|
521
|
+
registerContextMiddleware() {
|
|
522
|
+
this.app.use("*", this.createContextMiddleware());
|
|
399
523
|
}
|
|
400
|
-
|
|
401
|
-
|
|
524
|
+
registerAuthMiddleware() {
|
|
525
|
+
const authConfig = this.mastra.getServer()?.auth;
|
|
526
|
+
if (!authConfig) {
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
this.app.use("*", authenticationMiddleware);
|
|
530
|
+
this.app.use("*", authorizationMiddleware);
|
|
402
531
|
}
|
|
403
532
|
};
|
|
404
533
|
|
|
405
|
-
export {
|
|
534
|
+
export { MastraServer };
|
|
406
535
|
//# sourceMappingURL=index.js.map
|
|
407
536
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../node_modules/.pnpm/hono@4.10.4/node_modules/hono/dist/http-exception.js","../../../node_modules/.pnpm/hono@4.10.4/node_modules/hono/dist/middleware/body-limit/index.js","../../../node_modules/.pnpm/hono@4.10.4/node_modules/hono/dist/utils/stream.js","../../../node_modules/.pnpm/hono@4.10.4/node_modules/hono/dist/helper/streaming/utils.js","../../../node_modules/.pnpm/hono@4.10.4/node_modules/hono/dist/helper/streaming/stream.js","../src/index.ts"],"names":["stream"],"mappings":";;;;;;AACA,IAAI,aAAA,GAAgB,cAAc,KAAA,CAAM;AAAA,EACtC,GAAA;AAAA,EACA,MAAA;AAAA,EACA,WAAA,CAAY,MAAA,GAAS,GAAA,EAAK,OAAA,EAAS;AACjC,IAAA,KAAA,CAAM,SAAS,OAAA,EAAS,EAAE,KAAA,EAAO,OAAA,EAAS,OAAO,CAAA;AACjD,IAAA,IAAA,CAAK,MAAM,OAAA,EAAS,GAAA;AACpB,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AAAA,EAChB;AAAA,EACA,WAAA,GAAc;AACZ,IAAA,IAAI,KAAK,GAAA,EAAK;AACZ,MAAA,MAAM,WAAA,GAAc,IAAI,QAAA,CAAS,IAAA,CAAK,IAAI,IAAA,EAAM;AAAA,QAC9C,QAAQ,IAAA,CAAK,MAAA;AAAA,QACb,OAAA,EAAS,KAAK,GAAA,CAAI;AAAA,OACnB,CAAA;AACD,MAAA,OAAO,WAAA;AAAA,IACT;AACA,IAAA,OAAO,IAAI,QAAA,CAAS,IAAA,CAAK,OAAA,EAAS;AAAA,MAChC,QAAQ,IAAA,CAAK;AAAA,KACd,CAAA;AAAA,EACH;AACF,CAAA;;;ACnBA,IAAI,aAAA,GAAgB,mBAAA;AACpB,IAAI,cAAA,GAAiB,cAAc,KAAA,CAAM;AAAA,EACvC,YAAY,OAAA,EAAS;AACnB,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,gBAAA;AAAA,EACd;AACF,CAAA;AACA,IAAI,SAAA,GAAY,CAAC,OAAA,KAAY;AAC3B,EAAA,MAAM,O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AAW,OAAO,MAAM,OAAA,KAAY,QAAA,IAAY,QAAA,IAAY,KAAA,CAAM,OAAA,EAAS;AACzG,cAAA,MAAM,MAAA,GAAU,MAAM,OAAA,CAAgB,MAAA;AACtC,cAAA,OAAO,CAAA,CAAE,IAAA,CAAK,EAAE,KAAA,EAAO,KAAA,YAAiB,QAAQ,KAAA,CAAM,OAAA,GAAU,eAAA,EAAgB,EAAG,MAAM,CAAA;AAAA,YAC3F;AAAA,UACF;AACA,UAAA,OAAO,CAAA,CAAE,IAAA,CAAK,EAAE,KAAA,EAAO,KAAA,YAAiB,QAAQ,KAAA,CAAM,OAAA,GAAU,eAAA,EAAgB,EAAG,GAAG,CAAA;AAAA,QACxF;AAAA,MACF;AAAA,KACF;AAAA,EACF;AAAA,EAEA,0BAA+C,GAAA,EAA8B;AAC3E,IAAA,GAAA,CAAI,GAAA,CAAI,GAAA,EAAK,IAAA,CAAK,uBAAA,EAAyB,CAAA;AAAA,EAC7C;AAAA,EAEA,MAAM,cAAA,CACJ,GAAA,EACA,EAAE,MAAA,EAAQ,aAAY,EACP;AAEf,IAAA,MAAM,MAAM,cAAA,CAAe,GAAA,EAAY,EAAE,MAAA,EAAQ,aAAa,CAAA;AAAA,EAChE;AACF","file":"index.js","sourcesContent":["// src/http-exception.ts\nvar HTTPException = class extends Error {\n res;\n status;\n constructor(status = 500, options) {\n super(options?.message, { cause: options?.cause });\n this.res = options?.res;\n this.status = status;\n }\n getResponse() {\n if (this.res) {\n const newResponse = new Response(this.res.body, {\n status: this.status,\n headers: this.res.headers\n });\n return newResponse;\n }\n return new Response(this.message, {\n status: this.status\n });\n }\n};\nexport {\n HTTPException\n};\n","// src/middleware/body-limit/index.ts\nimport { HTTPException } from \"../../http-exception.js\";\nvar ERROR_MESSAGE = \"Payload Too Large\";\nvar BodyLimitError = class extends Error {\n constructor(message) {\n super(message);\n this.name = \"BodyLimitError\";\n }\n};\nvar bodyLimit = (options) => {\n const onError = options.onError || (() => {\n const res = new Response(ERROR_MESSAGE, {\n status: 413\n });\n throw new HTTPException(413, { res });\n });\n const maxSize = options.maxSize;\n return async function bodyLimit2(c, next) {\n if (!c.req.raw.body) {\n return next();\n }\n const hasTransferEncoding = c.req.raw.headers.has(\"transfer-encoding\");\n const hasContentLength = c.req.raw.headers.has(\"content-length\");\n if (hasTransferEncoding && hasContentLength) {\n }\n if (hasContentLength && !hasTransferEncoding) {\n const contentLength = parseInt(c.req.raw.headers.get(\"content-length\") || \"0\", 10);\n return contentLength > maxSize ? onError(c) : next();\n }\n let size = 0;\n const rawReader = c.req.raw.body.getReader();\n const reader = new ReadableStream({\n async start(controller) {\n try {\n for (; ; ) {\n const { done, value } = await rawReader.read();\n if (done) {\n break;\n }\n size += value.length;\n if (size > maxSize) {\n controller.error(new BodyLimitError(ERROR_MESSAGE));\n break;\n }\n controller.enqueue(value);\n }\n } finally {\n controller.close();\n }\n }\n });\n const requestInit = { body: reader, duplex: \"half\" };\n c.req.raw = new Request(c.req.raw, requestInit);\n await next();\n if (c.error instanceof BodyLimitError) {\n c.res = await onError(c);\n }\n };\n};\nexport {\n bodyLimit\n};\n","// src/utils/stream.ts\nvar StreamingApi = class {\n writer;\n encoder;\n writable;\n abortSubscribers = [];\n responseReadable;\n aborted = false;\n closed = false;\n constructor(writable, _readable) {\n this.writable = writable;\n this.writer = writable.getWriter();\n this.encoder = new TextEncoder();\n const reader = _readable.getReader();\n this.abortSubscribers.push(async () => {\n await reader.cancel();\n });\n this.responseReadable = new ReadableStream({\n async pull(controller) {\n const { done, value } = await reader.read();\n done ? controller.close() : controller.enqueue(value);\n },\n cancel: () => {\n this.abort();\n }\n });\n }\n async write(input) {\n try {\n if (typeof input === \"string\") {\n input = this.encoder.encode(input);\n }\n await this.writer.write(input);\n } catch {\n }\n return this;\n }\n async writeln(input) {\n await this.write(input + \"\\n\");\n return this;\n }\n sleep(ms) {\n return new Promise((res) => setTimeout(res, ms));\n }\n async close() {\n try {\n await this.writer.close();\n } catch {\n }\n this.closed = true;\n }\n async pipe(body) {\n this.writer.releaseLock();\n await body.pipeTo(this.writable, { preventClose: true });\n this.writer = this.writable.getWriter();\n }\n onAbort(listener) {\n this.abortSubscribers.push(listener);\n }\n abort() {\n if (!this.aborted) {\n this.aborted = true;\n this.abortSubscribers.forEach((subscriber) => subscriber());\n }\n }\n};\nexport {\n StreamingApi\n};\n","// src/helper/streaming/utils.ts\nvar isOldBunVersion = () => {\n const version = typeof Bun !== \"undefined\" ? Bun.version : void 0;\n if (version === void 0) {\n return false;\n }\n const result = version.startsWith(\"1.1\") || version.startsWith(\"1.0\") || version.startsWith(\"0.\");\n isOldBunVersion = () => result;\n return result;\n};\nexport {\n isOldBunVersion\n};\n","// src/helper/streaming/stream.ts\nimport { StreamingApi } from \"../../utils/stream.js\";\nimport { isOldBunVersion } from \"./utils.js\";\nvar contextStash = /* @__PURE__ */ new WeakMap();\nvar stream = (c, cb, onError) => {\n const { readable, writable } = new TransformStream();\n const stream2 = new StreamingApi(writable, readable);\n if (isOldBunVersion()) {\n c.req.raw.signal.addEventListener(\"abort\", () => {\n if (!stream2.closed) {\n stream2.abort();\n }\n });\n }\n contextStash.set(stream2.responseReadable, c);\n (async () => {\n try {\n await cb(stream2);\n } catch (e) {\n if (e === void 0) {\n } else if (e instanceof Error && onError) {\n await onError(e, stream2);\n } else {\n console.error(e);\n }\n } finally {\n stream2.close();\n }\n })();\n return c.newResponse(stream2.responseReadable);\n};\nexport {\n stream\n};\n","import type { Mastra } from '@mastra/core/mastra';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport type { Tool } from '@mastra/core/tools';\nimport { InMemoryTaskStore } from '@mastra/server/a2a/store';\nimport { MastraServerAdapter } from '@mastra/server/server-adapter';\nimport type { BodyLimitOptions, ServerRoute } from '@mastra/server/server-adapter';\nimport type { Context, Env, Hono, HonoRequest, MiddlewareHandler } from 'hono';\nimport { bodyLimit } from 'hono/body-limit';\nimport { stream } from 'hono/streaming';\n\n// Export type definitions for Hono app configuration\nexport type HonoVariables = {\n mastra: Mastra;\n requestContext: RequestContext;\n tools: Record<string, Tool>;\n abortSignal: AbortSignal;\n taskStore: InMemoryTaskStore;\n customRouteAuthConfig?: Map<string, boolean>;\n playground?: boolean;\n isDev?: boolean;\n};\n\nexport type HonoBindings = {};\n\nexport class HonoServerAdapter extends MastraServerAdapter<Hono<any, any, any>, HonoRequest, Context> {\n private taskStore: InMemoryTaskStore;\n private customRouteAuthConfig?: Map<string, boolean>;\n private playground?: boolean;\n private isDev?: boolean;\n\n constructor({\n mastra,\n tools,\n taskStore,\n customRouteAuthConfig,\n playground,\n isDev,\n bodyLimitOptions,\n }: {\n mastra: Mastra;\n tools?: Record<string, Tool>;\n taskStore?: InMemoryTaskStore;\n customRouteAuthConfig?: Map<string, boolean>;\n playground?: boolean;\n isDev?: boolean;\n bodyLimitOptions?: BodyLimitOptions;\n }) {\n super({ mastra, bodyLimitOptions, tools });\n this.taskStore = taskStore || new InMemoryTaskStore();\n this.customRouteAuthConfig = customRouteAuthConfig;\n this.playground = playground;\n this.isDev = isDev;\n }\n\n createContextMiddleware(): MiddlewareHandler {\n return async (c, next) => {\n // Parse request context from request body and add to context\n\n let bodyRequestContext: Record<string, any> | undefined;\n let paramsRequestContext: Record<string, any> | undefined;\n\n // Parse request context from request body (POST/PUT)\n if (c.req.method === 'POST' || c.req.method === 'PUT') {\n const contentType = c.req.header('content-type');\n if (contentType?.includes('application/json')) {\n try {\n const clonedReq = c.req.raw.clone();\n const body = (await clonedReq.json()) as { requestContext?: Record<string, any> };\n if (body.requestContext) {\n bodyRequestContext = body.requestContext;\n }\n } catch {\n // Body parsing failed, continue without body\n }\n }\n }\n\n // Parse request context from query params (GET)\n if (c.req.method === 'GET') {\n try {\n const encodedRequestContext = c.req.query('requestContext');\n if (encodedRequestContext) {\n // Try JSON first\n try {\n paramsRequestContext = JSON.parse(encodedRequestContext);\n } catch {\n // Fallback to base64(JSON)\n try {\n const json = Buffer.from(encodedRequestContext, 'base64').toString('utf-8');\n paramsRequestContext = JSON.parse(json);\n } catch {\n // ignore if still invalid\n }\n }\n }\n } catch {\n // ignore query parsing errors\n }\n }\n\n const requestContext = this.mergeRequestContext({ paramsRequestContext, bodyRequestContext });\n\n // Add relevant contexts to hono context\n c.set('requestContext', requestContext);\n c.set('mastra', this.mastra);\n c.set('tools', this.tools || {});\n c.set('taskStore', this.taskStore);\n c.set('playground', this.playground === true);\n c.set('isDev', this.isDev === true);\n c.set('customRouteAuthConfig', this.customRouteAuthConfig);\n c.set('abortSignal', c.req.raw.signal);\n\n return next();\n };\n }\n async stream(route: ServerRoute, res: Context, result: { fullStream: ReadableStream }): Promise<any> {\n res.header('Content-Type', 'text/plain');\n res.header('Transfer-Encoding', 'chunked');\n\n const streamFormat = route.streamFormat || 'stream';\n\n return stream(\n res,\n async stream => {\n const readableStream = result instanceof ReadableStream ? result : result.fullStream;\n const reader = readableStream.getReader();\n\n stream.onAbort(() => {\n void reader.cancel('request aborted');\n });\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n if (value) {\n if (streamFormat === 'sse') {\n await stream.write(`data: ${JSON.stringify(value)}\\n\\n`);\n } else {\n await stream.write(JSON.stringify(value) + '\\x1E');\n }\n }\n }\n\n await stream.write('data: [DONE]\\n\\n');\n } catch (error) {\n console.error(error);\n } finally {\n await stream.close();\n }\n },\n async err => {\n console.error(err);\n },\n );\n }\n\n async getParams(\n route: ServerRoute,\n request: HonoRequest,\n ): Promise<{ urlParams: Record<string, string>; queryParams: Record<string, string>; body: unknown }> {\n const urlParams = request.param();\n const queryParams = request.query();\n let body: unknown;\n if (route.method === 'POST' || route.method === 'PUT' || route.method === 'PATCH') {\n try {\n body = await request.json();\n } catch {}\n }\n return { urlParams, queryParams: queryParams as Record<string, string>, body };\n }\n\n async sendResponse(route: ServerRoute, response: Context, result: unknown): Promise<any> {\n if (route.responseType === 'json') {\n return response.json(result as any, 200);\n } else if (route.responseType === 'stream') {\n return this.stream(route, response, result as { fullStream: ReadableStream });\n } else if (route.responseType === 'datastream-response') {\n const fetchResponse = result as globalThis.Response;\n return fetchResponse;\n } else {\n return response.status(500);\n }\n }\n\n async registerRoute<E extends Env = any>(\n app: Hono<E, any, any>,\n route: ServerRoute,\n { prefix }: { prefix?: string },\n ): Promise<void> {\n // Determine if body limits should be applied\n const shouldApplyBodyLimit = this.bodyLimitOptions && ['POST', 'PUT', 'PATCH'].includes(route.method.toUpperCase());\n\n // Get the body size limit for this route (route-specific or default)\n const maxSize = route.maxBodySize ?? this.bodyLimitOptions?.maxSize;\n\n // Build middleware array\n const middlewares: MiddlewareHandler[] = [];\n\n if (shouldApplyBodyLimit && maxSize && this.bodyLimitOptions) {\n middlewares.push(\n bodyLimit({\n maxSize,\n onError: this.bodyLimitOptions.onError as any,\n }),\n );\n }\n\n app[route.method.toLowerCase() as 'get' | 'post' | 'put' | 'delete' | 'patch' | 'all'](\n `${prefix}${route.path}`,\n ...middlewares,\n async (c: Context) => {\n const params = await this.getParams(route, c.req);\n\n if (params.queryParams) {\n try {\n params.queryParams = await this.parseQueryParams(route, params.queryParams as Record<string, string>);\n } catch (error) {\n console.error('Error parsing query params', error);\n // Zod validation errors should return 400 Bad Request, not 500\n return c.json(\n {\n error: 'Invalid query parameters',\n details: error instanceof Error ? error.message : 'Unknown error',\n },\n 400,\n );\n }\n }\n\n if (params.body) {\n try {\n params.body = await this.parseBody(route, params.body);\n } catch (error) {\n console.error('Error parsing body', error);\n // Zod validation errors should return 400 Bad Request, not 500\n return c.json(\n {\n error: 'Invalid request body',\n details: error instanceof Error ? error.message : 'Unknown error',\n },\n 400,\n );\n }\n }\n\n const handlerParams = {\n ...params.urlParams,\n ...params.queryParams,\n ...(typeof params.body === 'object' ? params.body : {}),\n requestContext: c.get('requestContext'),\n mastra: this.mastra,\n tools: c.get('tools'),\n taskStore: c.get('taskStore'),\n abortSignal: c.get('abortSignal'),\n };\n\n try {\n const result = await route.handler(handlerParams);\n return this.sendResponse(route, c, result);\n } catch (error) {\n console.error('Error calling handler', error);\n // Check if it's an HTTPException or MastraError with a status code\n if (error && typeof error === 'object') {\n // Check for direct status property (HTTPException)\n if ('status' in error) {\n const status = (error as any).status;\n return c.json({ error: error instanceof Error ? error.message : 'Unknown error' }, status);\n }\n // Check for MastraError with status in details\n if ('details' in error && error.details && typeof error.details === 'object' && 'status' in error.details) {\n const status = (error.details as any).status;\n return c.json({ error: error instanceof Error ? error.message : 'Unknown error' }, status);\n }\n }\n return c.json({ error: error instanceof Error ? error.message : 'Unknown error' }, 500);\n }\n },\n );\n }\n\n registerContextMiddleware<E extends Env = any>(app: Hono<E, any, any>): void {\n app.use('*', this.createContextMiddleware());\n }\n\n async registerRoutes<E extends Env = any>(\n app: Hono<E, any, any>,\n { prefix, openapiPath }: { prefix?: string; openapiPath?: string },\n ): Promise<void> {\n // Cast to base type for super call - safe because registerRoute is generic\n await super.registerRoutes(app as any, { prefix, openapiPath });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../node_modules/.pnpm/hono@4.10.6/node_modules/hono/dist/http-exception.js","../../../node_modules/.pnpm/hono@4.10.6/node_modules/hono/dist/middleware/body-limit/index.js","../../../node_modules/.pnpm/hono@4.10.6/node_modules/hono/dist/utils/stream.js","../../../node_modules/.pnpm/hono@4.10.6/node_modules/hono/dist/helper/streaming/utils.js","../../../node_modules/.pnpm/hono@4.10.6/node_modules/hono/dist/helper/streaming/stream.js","../src/auth-middleware.ts","../src/index.ts"],"names":["MastraServerBase","stream"],"mappings":";;;;;;;AACA,IAAI,aAAA,GAAgB,cAAc,KAAA,CAAM;AAAA,EACtC,GAAA;AAAA,EACA,MAAA;AAAA,EACA,WAAA,CAAY,MAAA,GAAS,GAAA,EAAK,OAAA,EAAS;AACjC,IAAA,KAAA,CAAM,SAAS,OAAA,EAAS,EAAE,KAAA,EAAO,OAAA,EAAS,OAAO,CAAA;AACjD,IAAA,IAAA,CAAK,MAAM,OAAA,EAAS,GAAA;AACpB,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;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;AAC7B,IAAA,MAAM,UAAA,GAAa,IAAA,CAAK,MAAA,CAAO,SAAA,EAAU,EAAG,IAAA;AAC5C,IAAA,IAAI,CAAC,UAAA,EAAY;AAEf,MAAA;AAAA,IACF;AAEA,IAAA,IAAA,CAAK,GAAA,CAAI,GAAA,CAAI,GAAA,EAAK,wBAAwB,CAAA;AAC1C,IAAA,IAAA,CAAK,GAAA,CAAI,GAAA,CAAI,GAAA,EAAK,uBAAuB,CAAA;AAAA,EAC3C;AACF","file":"index.js","sourcesContent":["// src/http-exception.ts\nvar HTTPException = class extends Error {\n res;\n status;\n constructor(status = 500, options) {\n super(options?.message, { cause: options?.cause });\n this.res = options?.res;\n this.status = status;\n }\n getResponse() {\n if (this.res) {\n const newResponse = new Response(this.res.body, {\n status: this.status,\n headers: this.res.headers\n });\n return newResponse;\n }\n return new Response(this.message, {\n status: this.status\n });\n }\n};\nexport {\n HTTPException\n};\n","// src/middleware/body-limit/index.ts\nimport { HTTPException } from \"../../http-exception.js\";\nvar ERROR_MESSAGE = \"Payload Too Large\";\nvar BodyLimitError = class extends Error {\n constructor(message) {\n super(message);\n this.name = \"BodyLimitError\";\n }\n};\nvar bodyLimit = (options) => {\n const onError = options.onError || (() => {\n const res = new Response(ERROR_MESSAGE, {\n status: 413\n });\n throw new HTTPException(413, { res });\n });\n const maxSize = options.maxSize;\n return async function bodyLimit2(c, next) {\n if (!c.req.raw.body) {\n return next();\n }\n const hasTransferEncoding = c.req.raw.headers.has(\"transfer-encoding\");\n const hasContentLength = c.req.raw.headers.has(\"content-length\");\n if (hasTransferEncoding && hasContentLength) {\n }\n if (hasContentLength && !hasTransferEncoding) {\n const contentLength = parseInt(c.req.raw.headers.get(\"content-length\") || \"0\", 10);\n return contentLength > maxSize ? onError(c) : next();\n }\n let size = 0;\n const rawReader = c.req.raw.body.getReader();\n const reader = new ReadableStream({\n async start(controller) {\n try {\n for (; ; ) {\n const { done, value } = await rawReader.read();\n if (done) {\n break;\n }\n size += value.length;\n if (size > maxSize) {\n controller.error(new BodyLimitError(ERROR_MESSAGE));\n break;\n }\n controller.enqueue(value);\n }\n } finally {\n controller.close();\n }\n }\n });\n const requestInit = { body: reader, duplex: \"half\" };\n c.req.raw = new Request(c.req.raw, requestInit);\n await next();\n if (c.error instanceof BodyLimitError) {\n c.res = await onError(c);\n }\n };\n};\nexport {\n bodyLimit\n};\n","// src/utils/stream.ts\nvar StreamingApi = class {\n writer;\n encoder;\n writable;\n abortSubscribers = [];\n responseReadable;\n aborted = false;\n closed = false;\n constructor(writable, _readable) {\n this.writable = writable;\n this.writer = writable.getWriter();\n this.encoder = new TextEncoder();\n const reader = _readable.getReader();\n this.abortSubscribers.push(async () => {\n await reader.cancel();\n });\n this.responseReadable = new ReadableStream({\n async pull(controller) {\n const { done, value } = await reader.read();\n done ? controller.close() : controller.enqueue(value);\n },\n cancel: () => {\n this.abort();\n }\n });\n }\n async write(input) {\n try {\n if (typeof input === \"string\") {\n input = this.encoder.encode(input);\n }\n await this.writer.write(input);\n } catch {\n }\n return this;\n }\n async writeln(input) {\n await this.write(input + \"\\n\");\n return this;\n }\n sleep(ms) {\n return new Promise((res) => setTimeout(res, ms));\n }\n async close() {\n try {\n await this.writer.close();\n } catch {\n }\n this.closed = true;\n }\n async pipe(body) {\n this.writer.releaseLock();\n await body.pipeTo(this.writable, { preventClose: true });\n this.writer = this.writable.getWriter();\n }\n onAbort(listener) {\n this.abortSubscribers.push(listener);\n }\n abort() {\n if (!this.aborted) {\n this.aborted = true;\n this.abortSubscribers.forEach((subscriber) => subscriber());\n }\n }\n};\nexport {\n StreamingApi\n};\n","// src/helper/streaming/utils.ts\nvar isOldBunVersion = () => {\n const version = typeof Bun !== \"undefined\" ? Bun.version : void 0;\n if (version === void 0) {\n return false;\n }\n const result = version.startsWith(\"1.1\") || version.startsWith(\"1.0\") || version.startsWith(\"0.\");\n isOldBunVersion = () => result;\n return result;\n};\nexport {\n isOldBunVersion\n};\n","// src/helper/streaming/stream.ts\nimport { StreamingApi } from \"../../utils/stream.js\";\nimport { isOldBunVersion } from \"./utils.js\";\nvar contextStash = /* @__PURE__ */ new WeakMap();\nvar stream = (c, cb, onError) => {\n const { readable, writable } = new TransformStream();\n const stream2 = new StreamingApi(writable, readable);\n if (isOldBunVersion()) {\n c.req.raw.signal.addEventListener(\"abort\", () => {\n if (!stream2.closed) {\n stream2.abort();\n }\n });\n }\n contextStash.set(stream2.responseReadable, c);\n (async () => {\n try {\n await cb(stream2);\n } catch (e) {\n if (e === void 0) {\n } else if (e instanceof Error && onError) {\n await onError(e, stream2);\n } else {\n console.error(e);\n }\n } finally {\n stream2.close();\n }\n })();\n return c.newResponse(stream2.responseReadable);\n};\nexport {\n stream\n};\n","import type { ContextWithMastra } from '@mastra/core/server';\nimport {\n canAccessPublicly,\n checkRules,\n defaultAuthConfig,\n isDevPlaygroundRequest,\n isProtectedPath,\n} from '@mastra/server/auth';\nimport type { Next } from 'hono';\n\nexport const authenticationMiddleware = async (c: ContextWithMastra, next: Next) => {\n const mastra = c.get('mastra');\n const authConfig = mastra.getServer()?.auth;\n const customRouteAuthConfig = c.get('customRouteAuthConfig');\n\n if (!authConfig) {\n // No auth config, skip authentication\n return next();\n }\n\n const path = c.req.path;\n const method = c.req.method;\n const getHeader = (name: string) => c.req.header(name);\n\n if (isDevPlaygroundRequest(path, method, getHeader, authConfig)) {\n // Skip authentication for dev playground requests\n return next();\n }\n\n if (!isProtectedPath(c.req.path, c.req.method, authConfig, customRouteAuthConfig)) {\n return next();\n }\n\n // Skip authentication for public routes\n if (canAccessPublicly(c.req.path, c.req.method, authConfig)) {\n return next();\n }\n\n // Get token from header or query\n const authHeader = c.req.header('Authorization');\n let token: string | null = authHeader ? authHeader.replace('Bearer ', '') : null;\n\n if (!token && c.req.query('apiKey')) {\n token = c.req.query('apiKey') || null;\n }\n\n // Handle missing token\n if (!token) {\n return c.json({ error: 'Authentication required' }, 401);\n }\n\n try {\n // Verify token and get user data\n let user: unknown;\n\n // Client provided verify function\n if (typeof authConfig.authenticateToken === 'function') {\n user = await authConfig.authenticateToken(token, c.req);\n } else {\n throw new Error('No token verification method configured');\n }\n\n if (!user) {\n return c.json({ error: 'Invalid or expired token' }, 401);\n }\n\n // Store user in context\n c.get('requestContext').set('user', user);\n\n return next();\n } catch (err) {\n console.error(err);\n return c.json({ error: 'Invalid or expired token' }, 401);\n }\n};\n\nexport const authorizationMiddleware = async (c: ContextWithMastra, next: Next) => {\n const mastra = c.get('mastra');\n const authConfig = mastra.getServer()?.auth;\n const customRouteAuthConfig = c.get('customRouteAuthConfig');\n\n if (!authConfig) {\n // No auth config, skip authorization\n return next();\n }\n\n const path = c.req.path;\n const method = c.req.method;\n const getHeader = (name: string) => c.req.header(name);\n\n if (isDevPlaygroundRequest(path, method, getHeader, authConfig)) {\n // Skip authorization for dev playground requests\n return next();\n }\n\n if (!isProtectedPath(c.req.path, c.req.method, authConfig, customRouteAuthConfig)) {\n return next();\n }\n\n // Skip for public routes\n if (canAccessPublicly(path, method, authConfig)) {\n return next();\n }\n\n const user = c.get('requestContext').get('user');\n\n if ('authorizeUser' in authConfig && typeof authConfig.authorizeUser === 'function') {\n try {\n const isAuthorized = await authConfig.authorizeUser(user, c.req);\n\n if (isAuthorized) {\n return next();\n }\n\n return c.json({ error: 'Access denied' }, 403);\n } catch (err) {\n console.error(err);\n return c.json({ error: 'Authorization error' }, 500);\n }\n }\n\n // Client-provided authorization function\n if ('authorize' in authConfig && typeof authConfig.authorize === 'function') {\n try {\n const isAuthorized = await authConfig.authorize(path, method, user, c);\n\n if (isAuthorized) {\n return next();\n }\n\n return c.json({ error: 'Access denied' }, 403);\n } catch (err) {\n console.error(err);\n return c.json({ error: 'Authorization error' }, 500);\n }\n }\n\n // Custom rule-based authorization\n if ('rules' in authConfig && authConfig.rules && authConfig.rules.length > 0) {\n const isAuthorized = await checkRules(authConfig.rules, path, method, user);\n\n if (isAuthorized) {\n return next();\n }\n\n return c.json({ error: 'Access denied' }, 403);\n }\n\n // Default rule-based authorization\n if (defaultAuthConfig.rules && defaultAuthConfig.rules.length > 0) {\n const isAuthorized = await checkRules(defaultAuthConfig.rules, path, method, user);\n\n if (isAuthorized) {\n return next();\n }\n }\n\n return c.json({ error: 'Access denied' }, 403);\n};\n","import type { Mastra } from '@mastra/core/mastra';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport type { Tool } from '@mastra/core/tools';\nimport type { InMemoryTaskStore } from '@mastra/server/a2a/store';\nimport type { MCPHttpTransportResult, MCPSseTransportResult } from '@mastra/server/handlers/mcp';\nimport { MastraServer as MastraServerBase, redactStreamChunk } from '@mastra/server/server-adapter';\nimport type { ServerRoute } from '@mastra/server/server-adapter';\nimport { toReqRes, toFetchResponse } from 'fetch-to-node';\nimport type { Context, Env, Hono, HonoRequest, MiddlewareHandler } from 'hono';\nimport { bodyLimit } from 'hono/body-limit';\nimport { stream } from 'hono/streaming';\n\nimport { authenticationMiddleware, authorizationMiddleware } from './auth-middleware';\n\n// Export type definitions for Hono app configuration\nexport type HonoVariables = {\n mastra: Mastra;\n requestContext: RequestContext;\n tools: Record<string, Tool>;\n abortSignal: AbortSignal;\n taskStore: InMemoryTaskStore;\n customRouteAuthConfig?: Map<string, boolean>;\n playground?: boolean;\n isDev?: boolean;\n};\n\nexport type HonoBindings = {};\n\nexport class MastraServer extends MastraServerBase<Hono<any, any, any>, HonoRequest, Context> {\n createContextMiddleware(): MiddlewareHandler {\n return async (c, next) => {\n // Parse request context from request body and add to context\n\n let bodyRequestContext: Record<string, any> | undefined;\n let paramsRequestContext: Record<string, any> | undefined;\n\n // Parse request context from request body (POST/PUT)\n if (c.req.method === 'POST' || c.req.method === 'PUT') {\n const contentType = c.req.header('content-type');\n if (contentType?.includes('application/json')) {\n try {\n const clonedReq = c.req.raw.clone();\n const body = (await clonedReq.json()) as { requestContext?: Record<string, any> };\n if (body.requestContext) {\n bodyRequestContext = body.requestContext;\n }\n } catch {\n // Body parsing failed, continue without body\n }\n }\n }\n\n // Parse request context from query params (GET)\n if (c.req.method === 'GET') {\n try {\n const encodedRequestContext = c.req.query('requestContext');\n if (encodedRequestContext) {\n // Try JSON first\n try {\n paramsRequestContext = JSON.parse(encodedRequestContext);\n } catch {\n // Fallback to base64(JSON)\n try {\n const json = Buffer.from(encodedRequestContext, 'base64').toString('utf-8');\n paramsRequestContext = JSON.parse(json);\n } catch {\n // ignore if still invalid\n }\n }\n }\n } catch {\n // ignore query parsing errors\n }\n }\n\n const requestContext = this.mergeRequestContext({ paramsRequestContext, bodyRequestContext });\n\n // Add relevant contexts to hono context\n c.set('requestContext', requestContext);\n c.set('mastra', this.mastra);\n c.set('tools', this.tools || {});\n c.set('taskStore', this.taskStore);\n c.set('playground', this.playground === true);\n c.set('isDev', this.isDev === true);\n c.set('abortSignal', c.req.raw.signal);\n c.set('customRouteAuthConfig', this.customRouteAuthConfig);\n\n return next();\n };\n }\n async stream(route: ServerRoute, res: Context, result: { fullStream: ReadableStream }): Promise<any> {\n res.header('Content-Type', 'text/plain');\n res.header('Transfer-Encoding', 'chunked');\n\n const streamFormat = route.streamFormat || 'stream';\n\n return stream(\n res,\n async stream => {\n const readableStream = result instanceof ReadableStream ? result : result.fullStream;\n const reader = readableStream.getReader();\n\n stream.onAbort(() => {\n void reader.cancel('request aborted');\n });\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n if (value) {\n // Optionally redact sensitive data (system prompts, tool definitions, API keys) before sending to the client\n const shouldRedact = this.streamOptions?.redact ?? true;\n const outputValue = shouldRedact ? redactStreamChunk(value) : value;\n if (streamFormat === 'sse') {\n await stream.write(`data: ${JSON.stringify(outputValue)}\\n\\n`);\n } else {\n await stream.write(JSON.stringify(outputValue) + '\\x1E');\n }\n }\n }\n\n await stream.write('data: [DONE]\\n\\n');\n } catch (error) {\n console.error(error);\n } finally {\n await stream.close();\n }\n },\n async err => {\n console.error(err);\n },\n );\n }\n\n async getParams(\n route: ServerRoute,\n request: HonoRequest,\n ): Promise<{ urlParams: Record<string, string>; queryParams: Record<string, string>; body: unknown }> {\n const urlParams = request.param();\n const queryParams = request.query();\n let body: unknown;\n if (route.method === 'POST' || route.method === 'PUT' || route.method === 'PATCH') {\n try {\n body = await request.json();\n } catch {}\n }\n return { urlParams, queryParams: queryParams as Record<string, string>, body };\n }\n\n async sendResponse(route: ServerRoute, response: Context, result: unknown): Promise<any> {\n if (route.responseType === 'json') {\n return response.json(result as any, 200);\n } else if (route.responseType === 'stream') {\n return this.stream(route, response, result as { fullStream: ReadableStream });\n } else if (route.responseType === 'datastream-response') {\n const fetchResponse = result as globalThis.Response;\n return fetchResponse;\n } else if (route.responseType === 'mcp-http') {\n // MCP Streamable HTTP transport\n const { server, httpPath } = result as MCPHttpTransportResult;\n const { req, res } = toReqRes(response.req.raw);\n\n try {\n await server.startHTTP({\n url: new URL(response.req.url),\n httpPath,\n req,\n res,\n });\n return await toFetchResponse(res);\n } catch {\n if (!res.headersSent) {\n res.writeHead(500, { 'Content-Type': 'application/json' });\n res.end(\n JSON.stringify({\n jsonrpc: '2.0',\n error: { code: -32603, message: 'Internal server error' },\n id: null,\n }),\n );\n return await toFetchResponse(res);\n }\n return await toFetchResponse(res);\n }\n } else if (route.responseType === 'mcp-sse') {\n // MCP SSE transport\n const { server, ssePath, messagePath } = result as MCPSseTransportResult;\n\n try {\n return await server.startHonoSSE({\n url: new URL(response.req.url),\n ssePath,\n messagePath,\n context: response,\n });\n } catch {\n return response.json({ error: 'Error handling MCP SSE request' }, 500);\n }\n } else {\n return response.status(500);\n }\n }\n\n async registerRoute<E extends Env = any>(\n app: Hono<E, any, any>,\n route: ServerRoute,\n { prefix }: { prefix?: string },\n ): Promise<void> {\n // Determine if body limits should be applied\n const shouldApplyBodyLimit = this.bodyLimitOptions && ['POST', 'PUT', 'PATCH'].includes(route.method.toUpperCase());\n\n // Get the body size limit for this route (route-specific or default)\n const maxSize = route.maxBodySize ?? this.bodyLimitOptions?.maxSize;\n\n // Build middleware array\n const middlewares: MiddlewareHandler[] = [];\n\n if (shouldApplyBodyLimit && maxSize && this.bodyLimitOptions) {\n middlewares.push(\n bodyLimit({\n maxSize,\n onError: this.bodyLimitOptions.onError as any,\n }),\n );\n }\n\n app[route.method.toLowerCase() as 'get' | 'post' | 'put' | 'delete' | 'patch' | 'all'](\n `${prefix}${route.path}`,\n ...middlewares,\n async (c: Context) => {\n const params = await this.getParams(route, c.req);\n\n if (params.queryParams) {\n try {\n params.queryParams = await this.parseQueryParams(route, params.queryParams as Record<string, string>);\n } catch (error) {\n console.error('Error parsing query params', error);\n // Zod validation errors should return 400 Bad Request, not 500\n return c.json(\n {\n error: 'Invalid query parameters',\n details: error instanceof Error ? error.message : 'Unknown error',\n },\n 400,\n );\n }\n }\n\n if (params.body) {\n try {\n params.body = await this.parseBody(route, params.body);\n } catch (error) {\n console.error('Error parsing body:', error instanceof Error ? error.message : String(error));\n // Zod validation errors should return 400 Bad Request, not 500\n return c.json(\n {\n error: 'Invalid request body',\n details: error instanceof Error ? error.message : 'Unknown error',\n },\n 400,\n );\n }\n }\n\n const handlerParams = {\n ...params.urlParams,\n ...params.queryParams,\n ...(typeof params.body === 'object' ? params.body : {}),\n requestContext: c.get('requestContext'),\n mastra: this.mastra,\n tools: c.get('tools'),\n taskStore: c.get('taskStore'),\n abortSignal: c.get('abortSignal'),\n };\n\n try {\n const result = await route.handler(handlerParams);\n return this.sendResponse(route, c, result);\n } catch (error) {\n console.error('Error calling handler', error);\n // Check if it's an HTTPException or MastraError with a status code\n if (error && typeof error === 'object') {\n // Check for direct status property (HTTPException)\n if ('status' in error) {\n const status = (error as any).status;\n return c.json({ error: error instanceof Error ? error.message : 'Unknown error' }, status);\n }\n // Check for MastraError with status in details\n if ('details' in error && error.details && typeof error.details === 'object' && 'status' in error.details) {\n const status = (error.details as any).status;\n return c.json({ error: error instanceof Error ? error.message : 'Unknown error' }, status);\n }\n }\n return c.json({ error: error instanceof Error ? error.message : 'Unknown error' }, 500);\n }\n },\n );\n }\n\n registerContextMiddleware(): void {\n this.app.use('*', this.createContextMiddleware());\n }\n\n registerAuthMiddleware(): void {\n const authConfig = this.mastra.getServer()?.auth;\n if (!authConfig) {\n // No auth config, skip registration\n return;\n }\n\n this.app.use('*', authenticationMiddleware);\n this.app.use('*', authorizationMiddleware);\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/hono",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2-beta.1",
|
|
4
4
|
"description": "Mastra Hono adapter for the server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
},
|
|
21
21
|
"license": "Apache-2.0",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"
|
|
23
|
+
"fetch-to-node": "^2.1.0",
|
|
24
|
+
"@mastra/server": "1.0.0-beta.6"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"@types/node": "^20.19.0",
|
|
@@ -33,19 +34,19 @@
|
|
|
33
34
|
"@hono/swagger-ui": "^0.5.2",
|
|
34
35
|
"@ai-sdk/openai": "^2.0.62",
|
|
35
36
|
"zod": "^3.25.0",
|
|
36
|
-
"@internal/lint": "0.0.
|
|
37
|
+
"@internal/lint": "0.0.53",
|
|
37
38
|
"@internal/server-adapter-test-utils": "0.0.1",
|
|
38
|
-
"@mastra/core": "0.0.0-trace-timeline-update-20251121114225",
|
|
39
|
-
"@mastra/observability": "0.0.0-trace-timeline-update-20251121114225",
|
|
40
|
-
"@mastra/memory": "0.0.0-trace-timeline-update-20251121114225",
|
|
41
39
|
"@internal/storage-test-utils": "0.0.49",
|
|
42
|
-
"@mastra/
|
|
43
|
-
"@
|
|
40
|
+
"@mastra/core": "1.0.0-beta.6",
|
|
41
|
+
"@mastra/libsql": "1.0.0-beta.3",
|
|
42
|
+
"@mastra/observability": "1.0.0-beta.2",
|
|
43
|
+
"@mastra/memory": "1.0.0-beta.3",
|
|
44
|
+
"@internal/types-builder": "0.0.28"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
47
|
+
"@mastra/core": ">=1.0.0-0 <2.0.0-0",
|
|
46
48
|
"express": "^5.1.0",
|
|
47
|
-
"@types/express": "^5.0.5"
|
|
48
|
-
"@mastra/core": "0.0.0-trace-timeline-update-20251121114225"
|
|
49
|
+
"@types/express": "^5.0.5"
|
|
49
50
|
},
|
|
50
51
|
"engines": {
|
|
51
52
|
"node": ">=22.13.0"
|