@mastra/fastify 1.3.19-alpha.0 → 1.3.19-alpha.10
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 +84 -0
- package/dist/index.cjs +58 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +58 -10
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,89 @@
|
|
|
1
1
|
# @mastra/fastify
|
|
2
2
|
|
|
3
|
+
## 1.3.19-alpha.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`7ad5585`](https://github.com/mastra-ai/mastra/commit/7ad55856406f1de398dc713f6a9eaa78b2784bb6), [`210ea7a`](https://github.com/mastra-ai/mastra/commit/210ea7af559791b73a44fc9c12179908aaa3183f), [`83218c8`](https://github.com/mastra-ai/mastra/commit/83218c88b37773c9424fbe733b37be556e55e94d), [`265ec9f`](https://github.com/mastra-ai/mastra/commit/265ec9f887b5c81255c873a76ff7796f16e4f99b), [`6ce80bf`](https://github.com/mastra-ai/mastra/commit/6ce80bf4872a891e0bddf8b80561a80584efb14b), [`9268531`](https://github.com/mastra-ai/mastra/commit/9268531e7ec4be98beeba3b3ae8be0a7ea380662), [`13ead79`](https://github.com/mastra-ai/mastra/commit/13ead79149486b88144db7e11e6ff551caef5be1), [`bd36d8e`](https://github.com/mastra-ai/mastra/commit/bd36d8eb6de8c9a0310352649dbd4b06703c2299), [`8ac9141`](https://github.com/mastra-ai/mastra/commit/8ac9141439caa8fdd674944c4d84f29b3c730296)]:
|
|
8
|
+
- @mastra/core@1.33.0-alpha.10
|
|
9
|
+
- @mastra/server@1.33.0-alpha.10
|
|
10
|
+
|
|
11
|
+
## 1.3.19-alpha.9
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`5688881`](https://github.com/mastra-ai/mastra/commit/5688881669c7ed157f31ac77f6fc5f8d95ceea32)]:
|
|
16
|
+
- @mastra/core@1.33.0-alpha.9
|
|
17
|
+
- @mastra/server@1.33.0-alpha.9
|
|
18
|
+
|
|
19
|
+
## 1.3.19-alpha.8
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [[`7c275a8`](https://github.com/mastra-ai/mastra/commit/7c275a810595e1a6c41ccc39720531ab65734700), [`890b24c`](https://github.com/mastra-ai/mastra/commit/890b24cc7d32ed6aa4dfe253e54dc6bf4099f690), [`0f48ebf`](https://github.com/mastra-ai/mastra/commit/0f48ebfc7ac7897b2092a189f45751924cf56d1c), [`f180e49`](https://github.com/mastra-ai/mastra/commit/f180e4990e71b04c9a475b523584071712f0048f), [`9260e01`](https://github.com/mastra-ai/mastra/commit/9260e015276fb1b500f7878ee452b47476bf1583), [`2f6c54e`](https://github.com/mastra-ai/mastra/commit/2f6c54e17c041cac1def54baaa6b771647836414), [`e06a159`](https://github.com/mastra-ai/mastra/commit/e06a1598ca07a6c3778aefc2a2d288363c6294ff), [`db34bc6`](https://github.com/mastra-ai/mastra/commit/db34bc6fb36cf125bda0c46be4d3fdc774b70cc4)]:
|
|
24
|
+
- @mastra/core@1.33.0-alpha.8
|
|
25
|
+
- @mastra/server@1.33.0-alpha.8
|
|
26
|
+
|
|
27
|
+
## 1.3.19-alpha.7
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- Improved Studio agent serialization by making Studio mode and auth-related request context server-controlled across adapters. Playground requests now identify Studio traffic consistently, body and query request context cannot set reserved server values, and Studio placeholder fallback is limited to instruction rendering while serialized models, workspace, skills, tools, and default options use the real request context. ([#16152](https://github.com/mastra-ai/mastra/pull/16152))
|
|
32
|
+
|
|
33
|
+
- Updated dependencies [[`6742347`](https://github.com/mastra-ai/mastra/commit/6742347d71955d7639adc9ddf6ff8282de7ee3ba), [`7d57eeb`](https://github.com/mastra-ai/mastra/commit/7d57eeb8ad67c2e93c39d8fddb697aa11d677dbb), [`7b0ad1f`](https://github.com/mastra-ai/mastra/commit/7b0ad1f5c53dc118c6da12ae82ae2587037dc2b8), [`62666c3`](https://github.com/mastra-ai/mastra/commit/62666c367eaeac3941ead454b1d38810cc855721), [`4af2160`](https://github.com/mastra-ai/mastra/commit/4af2160322f4718cac421930cce85641e9512389), [`136c959`](https://github.com/mastra-ai/mastra/commit/136c9592fb0eeb0cd212f28629d8a29b7557a2fc), [`4df7cc7`](https://github.com/mastra-ai/mastra/commit/4df7cc79342fd065fe7fdeef93c094db14b12bcd), [`aca3121`](https://github.com/mastra-ai/mastra/commit/aca31211233dac25459f140ea4fcfb3a5af64c18), [`284b0d7`](https://github.com/mastra-ai/mastra/commit/284b0d78d0edb306413447e5268007491006937c), [`9cdf38e`](https://github.com/mastra-ai/mastra/commit/9cdf38e58506e1109c8b38f97cd7770978a4218e), [`990851e`](https://github.com/mastra-ai/mastra/commit/990851edcb0e30be5c2c18b6532f1a876cc2d335), [`6068a6c`](https://github.com/mastra-ai/mastra/commit/6068a6c42950fad3ebfc92346417896ba60803d2), [`00106be`](https://github.com/mastra-ai/mastra/commit/00106bede59b81e5b0e9cd6aad8d3b5dbc336387), [`284b0d7`](https://github.com/mastra-ai/mastra/commit/284b0d78d0edb306413447e5268007491006937c), [`e2a079c`](https://github.com/mastra-ai/mastra/commit/e2a079cc3755b1895f7bd5dc36e9be81b11c7c22), [`534a456`](https://github.com/mastra-ai/mastra/commit/534a456a25e4df1e5407e7e632f4cb3b1fa14f9d), [`36bae07`](https://github.com/mastra-ai/mastra/commit/36bae07c0e70b1b3006f2fd20830e8883dcbd066)]:
|
|
34
|
+
- @mastra/core@1.33.0-alpha.7
|
|
35
|
+
- @mastra/server@1.33.0-alpha.7
|
|
36
|
+
|
|
37
|
+
## 1.3.19-alpha.6
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- Updated dependencies [[`b560d6f`](https://github.com/mastra-ai/mastra/commit/b560d6f88b9b904b15c10f75c949eb145bc27684), [`36b3bbf`](https://github.com/mastra-ai/mastra/commit/36b3bbf5a8d59f7e23d47e29340e76c681b4929c), [`b275631`](https://github.com/mastra-ai/mastra/commit/b275631dc10541a482b2e2d4a3e3cfa843bd5fa1)]:
|
|
42
|
+
- @mastra/core@1.33.0-alpha.6
|
|
43
|
+
- @mastra/server@1.33.0-alpha.6
|
|
44
|
+
|
|
45
|
+
## 1.3.19-alpha.5
|
|
46
|
+
|
|
47
|
+
### Patch Changes
|
|
48
|
+
|
|
49
|
+
- Updated dependencies [[`bae019e`](https://github.com/mastra-ai/mastra/commit/bae019ecb6694da96909f7ec7b9eb3a0a33aa887), [`33f5061`](https://github.com/mastra-ai/mastra/commit/33f5061cd1c0335020c3faae61ce96de822854fa), [`99869ec`](https://github.com/mastra-ai/mastra/commit/99869ecb1f2aa6dfcc44fa4e843e5ee0344efa64), [`d86f031`](https://github.com/mastra-ai/mastra/commit/d86f031eb6b0b2570145afafea664e59bf688962)]:
|
|
50
|
+
- @mastra/core@1.33.0-alpha.5
|
|
51
|
+
- @mastra/server@1.33.0-alpha.5
|
|
52
|
+
|
|
53
|
+
## 1.3.19-alpha.4
|
|
54
|
+
|
|
55
|
+
### Patch Changes
|
|
56
|
+
|
|
57
|
+
- Fixed Fastify stream cleanup and route abort signals when clients disconnect before streamed responses finish. ([#16308](https://github.com/mastra-ai/mastra/pull/16308))
|
|
58
|
+
|
|
59
|
+
- Updated dependencies [[`9f17410`](https://github.com/mastra-ai/mastra/commit/9f1741080def23d42ee50b39887a385ae316a3c6), [`c6eb39e`](https://github.com/mastra-ai/mastra/commit/c6eb39ea6dca381c6563cb240237fbe608e02f93), [`900d086`](https://github.com/mastra-ai/mastra/commit/900d086bb737b9cf2fcf68f11b0389b801a2738c), [`4c0e286`](https://github.com/mastra-ai/mastra/commit/4c0e28637c9cfb4f416549b55e97ebfa13319dfc), [`c6eb39e`](https://github.com/mastra-ai/mastra/commit/c6eb39ea6dca381c6563cb240237fbe608e02f93), [`25184ff`](https://github.com/mastra-ai/mastra/commit/25184ffaf1293ec95119426eb1a1f8d38831b96c), [`25184ff`](https://github.com/mastra-ai/mastra/commit/25184ffaf1293ec95119426eb1a1f8d38831b96c), [`aebde9c`](https://github.com/mastra-ai/mastra/commit/aebde9cfacf56592c6b6350cae721740fe090b8a)]:
|
|
60
|
+
- @mastra/core@1.33.0-alpha.4
|
|
61
|
+
- @mastra/server@1.33.0-alpha.4
|
|
62
|
+
|
|
63
|
+
## 1.3.19-alpha.3
|
|
64
|
+
|
|
65
|
+
### Patch Changes
|
|
66
|
+
|
|
67
|
+
- Updated dependencies [[`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`0461546`](https://github.com/mastra-ai/mastra/commit/0461546755951706ca81bc24d1d31013d9d70a6d)]:
|
|
68
|
+
- @mastra/core@1.33.0-alpha.3
|
|
69
|
+
- @mastra/server@1.33.0-alpha.3
|
|
70
|
+
|
|
71
|
+
## 1.3.19-alpha.2
|
|
72
|
+
|
|
73
|
+
### Patch Changes
|
|
74
|
+
|
|
75
|
+
- Updated dependencies [[`d1fdbd0`](https://github.com/mastra-ai/mastra/commit/d1fdbd012add5623cb7e6b7f882b605ab358bbb4), [`d91ebe2`](https://github.com/mastra-ai/mastra/commit/d91ebe28ee065d8f2ed6df741c3c07f58d359529)]:
|
|
76
|
+
- @mastra/core@1.33.0-alpha.2
|
|
77
|
+
- @mastra/server@1.33.0-alpha.2
|
|
78
|
+
|
|
79
|
+
## 1.3.19-alpha.1
|
|
80
|
+
|
|
81
|
+
### Patch Changes
|
|
82
|
+
|
|
83
|
+
- Updated dependencies [[`dccd8f1`](https://github.com/mastra-ai/mastra/commit/dccd8f1f8b8f1ad203b77556207e5529567c616d)]:
|
|
84
|
+
- @mastra/core@1.33.0-alpha.1
|
|
85
|
+
- @mastra/server@1.33.0-alpha.1
|
|
86
|
+
|
|
3
87
|
## 1.3.19-alpha.0
|
|
4
88
|
|
|
5
89
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -306,9 +306,12 @@ function toWebRequest2(request) {
|
|
|
306
306
|
headers
|
|
307
307
|
});
|
|
308
308
|
}
|
|
309
|
+
function isRequestAborted(rawRequest) {
|
|
310
|
+
return rawRequest.aborted || rawRequest.readableAborted || !rawRequest.complete;
|
|
311
|
+
}
|
|
309
312
|
var MastraServer = class extends serverAdapter.MastraServer {
|
|
310
313
|
createContextMiddleware() {
|
|
311
|
-
return async (request,
|
|
314
|
+
return async (request, reply) => {
|
|
312
315
|
let bodyRequestContext;
|
|
313
316
|
let paramsRequestContext;
|
|
314
317
|
if (request.method === "POST" || request.method === "PUT") {
|
|
@@ -339,6 +342,13 @@ var MastraServer = class extends serverAdapter.MastraServer {
|
|
|
339
342
|
}
|
|
340
343
|
}
|
|
341
344
|
const requestContext = this.mergeRequestContext({ paramsRequestContext, bodyRequestContext });
|
|
345
|
+
this.applyRequestMetadataToContext({
|
|
346
|
+
requestContext,
|
|
347
|
+
getHeader: (name) => {
|
|
348
|
+
const value = request.headers[name.toLowerCase()];
|
|
349
|
+
return Array.isArray(value) ? value[0] : value;
|
|
350
|
+
}
|
|
351
|
+
});
|
|
342
352
|
request.requestContext = requestContext;
|
|
343
353
|
request.mastra = this.mastra;
|
|
344
354
|
request.registeredTools = this.tools || {};
|
|
@@ -348,14 +358,19 @@ var MastraServer = class extends serverAdapter.MastraServer {
|
|
|
348
358
|
request.customRouteAuthConfig = this.customRouteAuthConfig;
|
|
349
359
|
const controller = new AbortController();
|
|
350
360
|
request.raw.on("close", () => {
|
|
351
|
-
if (
|
|
361
|
+
if (isRequestAborted(request.raw)) {
|
|
362
|
+
controller.abort();
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
reply.raw.on("close", () => {
|
|
366
|
+
if (!reply.raw.writableEnded) {
|
|
352
367
|
controller.abort();
|
|
353
368
|
}
|
|
354
369
|
});
|
|
355
370
|
request.abortSignal = controller.signal;
|
|
356
371
|
};
|
|
357
372
|
}
|
|
358
|
-
async stream(route, reply, result) {
|
|
373
|
+
async stream(route, reply, result, request) {
|
|
359
374
|
const rawHeaders = reply.getHeaders();
|
|
360
375
|
const existingHeaders = {};
|
|
361
376
|
for (const [key, value] of Object.entries(rawHeaders)) {
|
|
@@ -381,9 +396,20 @@ var MastraServer = class extends serverAdapter.MastraServer {
|
|
|
381
396
|
});
|
|
382
397
|
const readableStream = result instanceof ReadableStream ? result : result.fullStream;
|
|
383
398
|
const reader = readableStream.getReader();
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
399
|
+
let readerCanceled = false;
|
|
400
|
+
const cancelReader = (reason) => {
|
|
401
|
+
if (readerCanceled) return;
|
|
402
|
+
readerCanceled = true;
|
|
403
|
+
void reader.cancel(reason);
|
|
404
|
+
};
|
|
405
|
+
const cancelReaderOnResponseClose = () => cancelReader("request aborted");
|
|
406
|
+
const cancelReaderOnRequestClose = () => {
|
|
407
|
+
if (request && isRequestAborted(request.raw)) {
|
|
408
|
+
cancelReader("request aborted");
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
reply.raw.on("close", cancelReaderOnResponseClose);
|
|
412
|
+
request?.raw.on("close", cancelReaderOnRequestClose);
|
|
387
413
|
try {
|
|
388
414
|
while (true) {
|
|
389
415
|
const { done, value } = await reader.read();
|
|
@@ -405,7 +431,11 @@ var MastraServer = class extends serverAdapter.MastraServer {
|
|
|
405
431
|
error: error instanceof Error ? { message: error.message, stack: error.stack } : error
|
|
406
432
|
});
|
|
407
433
|
} finally {
|
|
408
|
-
reply.raw.
|
|
434
|
+
reply.raw.off("close", cancelReaderOnResponseClose);
|
|
435
|
+
request?.raw.off("close", cancelReaderOnRequestClose);
|
|
436
|
+
if (!reply.raw.writableEnded && !reply.raw.destroyed) {
|
|
437
|
+
reply.raw.end();
|
|
438
|
+
}
|
|
409
439
|
}
|
|
410
440
|
}
|
|
411
441
|
async getParams(route, request) {
|
|
@@ -500,20 +530,34 @@ var MastraServer = class extends serverAdapter.MastraServer {
|
|
|
500
530
|
if (route.responseType === "json") {
|
|
501
531
|
await reply.send(result);
|
|
502
532
|
} else if (route.responseType === "stream") {
|
|
503
|
-
await this.stream(route, reply, result);
|
|
533
|
+
await this.stream(route, reply, result, request);
|
|
504
534
|
} else if (route.responseType === "datastream-response") {
|
|
505
535
|
const fetchResponse = result;
|
|
506
536
|
fetchResponse.headers.forEach((value, key) => reply.header(key, value));
|
|
507
537
|
reply.status(fetchResponse.status);
|
|
508
538
|
if (fetchResponse.body) {
|
|
509
539
|
const reader = fetchResponse.body.getReader();
|
|
540
|
+
let readerCanceled = false;
|
|
541
|
+
const cancelReader = (reason) => {
|
|
542
|
+
if (readerCanceled) return;
|
|
543
|
+
readerCanceled = true;
|
|
544
|
+
void reader.cancel(reason);
|
|
545
|
+
};
|
|
546
|
+
const cancelReaderOnResponseClose = () => cancelReader("request aborted");
|
|
547
|
+
const cancelReaderOnRequestClose = () => {
|
|
548
|
+
if (request && isRequestAborted(request.raw)) {
|
|
549
|
+
cancelReader("request aborted");
|
|
550
|
+
}
|
|
551
|
+
};
|
|
510
552
|
const onResError = (err) => {
|
|
511
553
|
this.mastra.getLogger()?.error("Error writing datastream response", {
|
|
512
554
|
error: err instanceof Error ? { message: err.message, stack: err.stack } : err
|
|
513
555
|
});
|
|
514
|
-
|
|
556
|
+
cancelReader("response write error");
|
|
515
557
|
};
|
|
516
558
|
reply.raw.once("error", onResError);
|
|
559
|
+
reply.raw.on("close", cancelReaderOnResponseClose);
|
|
560
|
+
request?.raw.on("close", cancelReaderOnRequestClose);
|
|
517
561
|
try {
|
|
518
562
|
while (true) {
|
|
519
563
|
const { done, value } = await reader.read();
|
|
@@ -526,7 +570,11 @@ var MastraServer = class extends serverAdapter.MastraServer {
|
|
|
526
570
|
});
|
|
527
571
|
} finally {
|
|
528
572
|
reply.raw.off("error", onResError);
|
|
529
|
-
reply.raw.
|
|
573
|
+
reply.raw.off("close", cancelReaderOnResponseClose);
|
|
574
|
+
request?.raw.off("close", cancelReaderOnRequestClose);
|
|
575
|
+
if (!reply.raw.writableEnded && !reply.raw.destroyed) {
|
|
576
|
+
reply.raw.end();
|
|
577
|
+
}
|
|
530
578
|
}
|
|
531
579
|
} else {
|
|
532
580
|
reply.raw.end();
|