@mastra/koa 1.5.8 → 1.5.9-alpha.2
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 +30 -0
- package/dist/index.cjs +6 -171
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -172
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @mastra/koa
|
|
2
2
|
|
|
3
|
+
## 1.5.9-alpha.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixed validation error responses on routes with `bodySchema`, `queryParamSchema`, or `pathParamSchema` losing field path information when consumers pin `zod@^3`. Responses now return the actual field name in `issues[].field` (e.g. `"agent_id"`) instead of `"unknown"` with the raw Zod issues serialized into `issues[0].message`. Fixes [#17167](https://github.com/mastra-ai/mastra/issues/17167). ([#17172](https://github.com/mastra-ai/mastra/pull/17172))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`d779de3`](https://github.com/mastra-ai/mastra/commit/d779de3cd9d2e7ed8110547190e2f15e786a0e41), [`1750c97`](https://github.com/mastra-ai/mastra/commit/1750c975d6179fbf6db2813b15229d4f8f23fc55), [`09972fe`](https://github.com/mastra-ai/mastra/commit/09972fe6b7b92ade32d70deda7094af2e52b2676), [`0e32507`](https://github.com/mastra-ai/mastra/commit/0e32507962cdfa5569b7bda5bc6fb3dd34e40b03), [`3a081c1`](https://github.com/mastra-ai/mastra/commit/3a081c1255c5ae8c99f6dad91cc612934ef6f2bd), [`fe9eacd`](https://github.com/mastra-ai/mastra/commit/fe9eacd9545a0a9d64aad31c9fa90294a425289e), [`db79c86`](https://github.com/mastra-ai/mastra/commit/db79c86c60723d57e02f9636ca2611bd4515f194)]:
|
|
10
|
+
- @mastra/core@1.38.0-alpha.2
|
|
11
|
+
- @mastra/server@1.38.0-alpha.2
|
|
12
|
+
|
|
13
|
+
## 1.5.9-alpha.1
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Added sseFlushOnConnect route option to scope the SSE connected comment to subscribe endpoints only ([#17158](https://github.com/mastra-ai/mastra/pull/17158))
|
|
18
|
+
|
|
19
|
+
- Scoped the SSE connected comment to subscribe routes only and added SSE comment passthrough for Fastify and NestJS adapters ([#17158](https://github.com/mastra-ai/mastra/pull/17158))
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [[`9d87d68`](https://github.com/mastra-ai/mastra/commit/9d87d688371f5d1252ebb18d96890b51ade7de7c), [`49f8abc`](https://github.com/mastra-ai/mastra/commit/49f8abce8258e4f2f87bd326acfbdb641264a47c), [`9d87d68`](https://github.com/mastra-ai/mastra/commit/9d87d688371f5d1252ebb18d96890b51ade7de7c)]:
|
|
22
|
+
- @mastra/server@1.37.2-alpha.1
|
|
23
|
+
- @mastra/core@1.37.2-alpha.1
|
|
24
|
+
|
|
25
|
+
## 1.5.9-alpha.0
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [[`07c3de7`](https://github.com/mastra-ai/mastra/commit/07c3de7f7bc418beccaea3b5e6b7f7cdda79d492)]:
|
|
30
|
+
- @mastra/core@1.37.2-alpha.0
|
|
31
|
+
- @mastra/server@1.37.2-alpha.0
|
|
32
|
+
|
|
3
33
|
## 1.5.8
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -6,174 +6,6 @@ var serverAdapter = require('@mastra/server/server-adapter');
|
|
|
6
6
|
var requestContext = require('@mastra/core/request-context');
|
|
7
7
|
|
|
8
8
|
// src/index.ts
|
|
9
|
-
|
|
10
|
-
// ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/core.js
|
|
11
|
-
var _a;
|
|
12
|
-
// @__NO_SIDE_EFFECTS__
|
|
13
|
-
function $constructor(name, initializer3, params) {
|
|
14
|
-
function init(inst, def) {
|
|
15
|
-
if (!inst._zod) {
|
|
16
|
-
Object.defineProperty(inst, "_zod", {
|
|
17
|
-
value: {
|
|
18
|
-
def,
|
|
19
|
-
constr: _,
|
|
20
|
-
traits: /* @__PURE__ */ new Set()
|
|
21
|
-
},
|
|
22
|
-
enumerable: false
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
if (inst._zod.traits.has(name)) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
inst._zod.traits.add(name);
|
|
29
|
-
initializer3(inst, def);
|
|
30
|
-
const proto = _.prototype;
|
|
31
|
-
const keys = Object.keys(proto);
|
|
32
|
-
for (let i = 0; i < keys.length; i++) {
|
|
33
|
-
const k = keys[i];
|
|
34
|
-
if (!(k in inst)) {
|
|
35
|
-
inst[k] = proto[k].bind(inst);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
const Parent = params?.Parent ?? Object;
|
|
40
|
-
class Definition extends Parent {
|
|
41
|
-
}
|
|
42
|
-
Object.defineProperty(Definition, "name", { value: name });
|
|
43
|
-
function _(def) {
|
|
44
|
-
var _a2;
|
|
45
|
-
const inst = params?.Parent ? new Definition() : this;
|
|
46
|
-
init(inst, def);
|
|
47
|
-
(_a2 = inst._zod).deferred ?? (_a2.deferred = []);
|
|
48
|
-
for (const fn of inst._zod.deferred) {
|
|
49
|
-
fn();
|
|
50
|
-
}
|
|
51
|
-
return inst;
|
|
52
|
-
}
|
|
53
|
-
Object.defineProperty(_, "init", { value: init });
|
|
54
|
-
Object.defineProperty(_, Symbol.hasInstance, {
|
|
55
|
-
value: (inst) => {
|
|
56
|
-
if (params?.Parent && inst instanceof params.Parent)
|
|
57
|
-
return true;
|
|
58
|
-
return inst?._zod?.traits?.has(name);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
Object.defineProperty(_, "name", { value: name });
|
|
62
|
-
return _;
|
|
63
|
-
}
|
|
64
|
-
(_a = globalThis).__zod_globalConfig ?? (_a.__zod_globalConfig = {});
|
|
65
|
-
|
|
66
|
-
// ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/util.js
|
|
67
|
-
function jsonStringifyReplacer(_, value) {
|
|
68
|
-
if (typeof value === "bigint")
|
|
69
|
-
return value.toString();
|
|
70
|
-
return value;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/errors.js
|
|
74
|
-
var initializer = (inst, def) => {
|
|
75
|
-
inst.name = "$ZodError";
|
|
76
|
-
Object.defineProperty(inst, "_zod", {
|
|
77
|
-
value: inst._zod,
|
|
78
|
-
enumerable: false
|
|
79
|
-
});
|
|
80
|
-
Object.defineProperty(inst, "issues", {
|
|
81
|
-
value: def,
|
|
82
|
-
enumerable: false
|
|
83
|
-
});
|
|
84
|
-
inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
|
|
85
|
-
Object.defineProperty(inst, "toString", {
|
|
86
|
-
value: () => inst.message,
|
|
87
|
-
enumerable: false
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
var $ZodError = $constructor("$ZodError", initializer);
|
|
91
|
-
function flattenError(error, mapper = (issue) => issue.message) {
|
|
92
|
-
const fieldErrors = {};
|
|
93
|
-
const formErrors = [];
|
|
94
|
-
for (const sub of error.issues) {
|
|
95
|
-
if (sub.path.length > 0) {
|
|
96
|
-
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
|
|
97
|
-
fieldErrors[sub.path[0]].push(mapper(sub));
|
|
98
|
-
} else {
|
|
99
|
-
formErrors.push(mapper(sub));
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return { formErrors, fieldErrors };
|
|
103
|
-
}
|
|
104
|
-
function formatError(error, mapper = (issue) => issue.message) {
|
|
105
|
-
const fieldErrors = { _errors: [] };
|
|
106
|
-
const processError = (error2, path = []) => {
|
|
107
|
-
for (const issue of error2.issues) {
|
|
108
|
-
if (issue.code === "invalid_union" && issue.errors.length) {
|
|
109
|
-
issue.errors.map((issues) => processError({ issues }, [...path, ...issue.path]));
|
|
110
|
-
} else if (issue.code === "invalid_key") {
|
|
111
|
-
processError({ issues: issue.issues }, [...path, ...issue.path]);
|
|
112
|
-
} else if (issue.code === "invalid_element") {
|
|
113
|
-
processError({ issues: issue.issues }, [...path, ...issue.path]);
|
|
114
|
-
} else {
|
|
115
|
-
const fullpath = [...path, ...issue.path];
|
|
116
|
-
if (fullpath.length === 0) {
|
|
117
|
-
fieldErrors._errors.push(mapper(issue));
|
|
118
|
-
} else {
|
|
119
|
-
let curr = fieldErrors;
|
|
120
|
-
let i = 0;
|
|
121
|
-
while (i < fullpath.length) {
|
|
122
|
-
const el = fullpath[i];
|
|
123
|
-
const terminal = i === fullpath.length - 1;
|
|
124
|
-
if (!terminal) {
|
|
125
|
-
curr[el] = curr[el] || { _errors: [] };
|
|
126
|
-
} else {
|
|
127
|
-
curr[el] = curr[el] || { _errors: [] };
|
|
128
|
-
curr[el]._errors.push(mapper(issue));
|
|
129
|
-
}
|
|
130
|
-
curr = curr[el];
|
|
131
|
-
i++;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
processError(error);
|
|
138
|
-
return fieldErrors;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/errors.js
|
|
142
|
-
var initializer2 = (inst, issues) => {
|
|
143
|
-
$ZodError.init(inst, issues);
|
|
144
|
-
inst.name = "ZodError";
|
|
145
|
-
Object.defineProperties(inst, {
|
|
146
|
-
format: {
|
|
147
|
-
value: (mapper) => formatError(inst, mapper)
|
|
148
|
-
// enumerable: false,
|
|
149
|
-
},
|
|
150
|
-
flatten: {
|
|
151
|
-
value: (mapper) => flattenError(inst, mapper)
|
|
152
|
-
// enumerable: false,
|
|
153
|
-
},
|
|
154
|
-
addIssue: {
|
|
155
|
-
value: (issue) => {
|
|
156
|
-
inst.issues.push(issue);
|
|
157
|
-
inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
|
|
158
|
-
}
|
|
159
|
-
// enumerable: false,
|
|
160
|
-
},
|
|
161
|
-
addIssues: {
|
|
162
|
-
value: (issues2) => {
|
|
163
|
-
inst.issues.push(...issues2);
|
|
164
|
-
inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
|
|
165
|
-
}
|
|
166
|
-
// enumerable: false,
|
|
167
|
-
},
|
|
168
|
-
isEmpty: {
|
|
169
|
-
get() {
|
|
170
|
-
return inst.issues.length === 0;
|
|
171
|
-
}
|
|
172
|
-
// enumerable: false,
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
};
|
|
176
|
-
var ZodError = /* @__PURE__ */ $constructor("ZodError", initializer2);
|
|
177
9
|
function toWebRequest(ctx) {
|
|
178
10
|
const protocol = ctx.protocol || "http";
|
|
179
11
|
const host = ctx.host || "localhost";
|
|
@@ -496,7 +328,7 @@ var MastraServer = class extends serverAdapter.MastraServer {
|
|
|
496
328
|
this.mastra.getLogger()?.error("Error parsing query params", {
|
|
497
329
|
error: error instanceof Error ? { message: error.message, stack: error.stack } : error
|
|
498
330
|
});
|
|
499
|
-
if (error
|
|
331
|
+
if (serverAdapter.isZodError(error)) {
|
|
500
332
|
const resolved = this.resolveValidationError(route, error, "query");
|
|
501
333
|
ctx.status = resolved.status;
|
|
502
334
|
ctx.body = resolved.body;
|
|
@@ -517,7 +349,7 @@ var MastraServer = class extends serverAdapter.MastraServer {
|
|
|
517
349
|
this.mastra.getLogger()?.error("Error parsing body", {
|
|
518
350
|
error: error instanceof Error ? { message: error.message, stack: error.stack } : error
|
|
519
351
|
});
|
|
520
|
-
if (error
|
|
352
|
+
if (serverAdapter.isZodError(error)) {
|
|
521
353
|
const resolved = this.resolveValidationError(route, error, "body");
|
|
522
354
|
ctx.status = resolved.status;
|
|
523
355
|
ctx.body = resolved.body;
|
|
@@ -538,7 +370,7 @@ var MastraServer = class extends serverAdapter.MastraServer {
|
|
|
538
370
|
this.mastra.getLogger()?.error("Error parsing path params", {
|
|
539
371
|
error: error instanceof Error ? { message: error.message, stack: error.stack } : error
|
|
540
372
|
});
|
|
541
|
-
if (error
|
|
373
|
+
if (serverAdapter.isZodError(error)) {
|
|
542
374
|
const resolved = this.resolveValidationError(route, error, "path");
|
|
543
375
|
ctx.status = resolved.status;
|
|
544
376
|
ctx.body = resolved.body;
|
|
@@ -626,6 +458,9 @@ var MastraServer = class extends serverAdapter.MastraServer {
|
|
|
626
458
|
...sseHeaders,
|
|
627
459
|
"Transfer-Encoding": "chunked"
|
|
628
460
|
});
|
|
461
|
+
if (streamFormat === "sse" && route.sseFlushOnConnect) {
|
|
462
|
+
ctx.res.write(": connected\n\n");
|
|
463
|
+
}
|
|
629
464
|
const readableStream = result instanceof ReadableStream ? result : result.fullStream;
|
|
630
465
|
const reader = readableStream.getReader();
|
|
631
466
|
ctx.res.on("close", () => {
|