@mastra/fastify 0.0.0-agent-chat-ui-20260305212602
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 +617 -0
- package/LICENSE.md +30 -0
- package/README.md +85 -0
- package/dist/index.cjs +796 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +794 -0
- package/dist/index.js.map +1 -0
- package/package.json +73 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Portions of this software are licensed as follows:
|
|
2
|
+
|
|
3
|
+
- All content that resides under any directory named "ee/" within this
|
|
4
|
+
repository, including but not limited to:
|
|
5
|
+
- `packages/core/src/auth/ee/`
|
|
6
|
+
- `packages/server/src/server/auth/ee/`
|
|
7
|
+
is licensed under the license defined in `ee/LICENSE`.
|
|
8
|
+
|
|
9
|
+
- All third-party components incorporated into the Mastra Software are
|
|
10
|
+
licensed under the original license provided by the owner of the
|
|
11
|
+
applicable component.
|
|
12
|
+
|
|
13
|
+
- Content outside of the above-mentioned directories or restrictions is
|
|
14
|
+
available under the "Apache License 2.0" as defined below.
|
|
15
|
+
|
|
16
|
+
# Apache License 2.0
|
|
17
|
+
|
|
18
|
+
Copyright (c) 2025 Kepler Software, Inc.
|
|
19
|
+
|
|
20
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
21
|
+
you may not use this file except in compliance with the License.
|
|
22
|
+
You may obtain a copy of the License at
|
|
23
|
+
|
|
24
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
25
|
+
|
|
26
|
+
Unless required by applicable law or agreed to in writing, software
|
|
27
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
28
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
29
|
+
See the License for the specific language governing permissions and
|
|
30
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# @mastra/fastify
|
|
2
|
+
|
|
3
|
+
Fastify server adapter for Mastra, enabling you to run Mastra with the [Fastify](https://fastify.dev) framework.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @mastra/fastify fastify
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import Fastify from 'fastify';
|
|
15
|
+
import { MastraServer } from '@mastra/fastify';
|
|
16
|
+
import { mastra } from './mastra';
|
|
17
|
+
|
|
18
|
+
const app = Fastify({ logger: true });
|
|
19
|
+
const server = new MastraServer({ app, mastra });
|
|
20
|
+
|
|
21
|
+
await server.init();
|
|
22
|
+
|
|
23
|
+
app.listen({ port: 3000 }, (err, address) => {
|
|
24
|
+
if (err) {
|
|
25
|
+
console.error(err);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
console.log(`Server running on ${address}`);
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Adding Custom Routes
|
|
33
|
+
|
|
34
|
+
Add routes directly to the Fastify app with access to Mastra context:
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
// Routes added after init() have access to Mastra context
|
|
38
|
+
app.get('/health', async request => {
|
|
39
|
+
const mastraInstance = request.mastra;
|
|
40
|
+
const agents = Object.keys(mastraInstance.listAgents());
|
|
41
|
+
return { status: 'ok', agents };
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Configuration Options
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
const server = new MastraServer({
|
|
49
|
+
app,
|
|
50
|
+
mastra,
|
|
51
|
+
prefix: '/api/v2', // Route prefix
|
|
52
|
+
openapiPath: '/openapi.json', // OpenAPI spec endpoint
|
|
53
|
+
bodyLimitOptions: {
|
|
54
|
+
maxSize: 10 * 1024 * 1024, // 10MB
|
|
55
|
+
onError: err => ({ error: 'Payload too large' }),
|
|
56
|
+
},
|
|
57
|
+
streamOptions: { redact: true }, // Redact sensitive data from streams
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Context Variables
|
|
62
|
+
|
|
63
|
+
Access these in route handlers via `request`:
|
|
64
|
+
|
|
65
|
+
| Key | Description |
|
|
66
|
+
| ---------------- | --------------------------- |
|
|
67
|
+
| `mastra` | Mastra instance |
|
|
68
|
+
| `requestContext` | Request context map |
|
|
69
|
+
| `abortSignal` | Request cancellation signal |
|
|
70
|
+
| `tools` | Available tools |
|
|
71
|
+
|
|
72
|
+
## Multipart File Uploads
|
|
73
|
+
|
|
74
|
+
For multipart file uploads, register `@fastify/multipart`:
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import multipart from '@fastify/multipart';
|
|
78
|
+
|
|
79
|
+
await app.register(multipart);
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Related Links
|
|
83
|
+
|
|
84
|
+
- [Server Adapters Documentation](https://mastra.ai/docs/server/server-adapters)
|
|
85
|
+
- [Fastify Documentation](https://fastify.dev/docs/latest/)
|