@mastra/express 1.3.24-alpha.5 → 1.3.24-alpha.9

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 CHANGED
@@ -1,5 +1,56 @@
1
1
  # @mastra/express
2
2
 
3
+ ## 1.3.24-alpha.9
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`d72dc4b`](https://github.com/mastra-ai/mastra/commit/d72dc4b12d832546c05c20255fa96fe4eb515900)]:
8
+ - @mastra/core@1.37.0-alpha.9
9
+ - @mastra/server@1.37.0-alpha.9
10
+
11
+ ## 1.3.24-alpha.8
12
+
13
+ ### Patch Changes
14
+
15
+ - Improved agent thread subscription resilience by keeping server streams active during idle periods and allowing the JavaScript client to reconnect when subscription streams close or resubscribe requests fail. ([#17045](https://github.com/mastra-ai/mastra/pull/17045))
16
+
17
+ Enable automatic reconnection with `subscription.processDataStream({ onChunk: chunk => console.log(chunk), reconnect: true })`.
18
+
19
+ - Updated dependencies [[`c35b962`](https://github.com/mastra-ai/mastra/commit/c35b9625c7e854fcfdeee226a3338a750d0ff211), [`c35b962`](https://github.com/mastra-ai/mastra/commit/c35b9625c7e854fcfdeee226a3338a750d0ff211), [`4084113`](https://github.com/mastra-ai/mastra/commit/408411370fc48a822e8b616b3b63f9409774e0e9), [`bc01b1b`](https://github.com/mastra-ai/mastra/commit/bc01b1bfafe381d90af909f8bce7eeb4eee779f2)]:
20
+ - @mastra/core@1.37.0-alpha.8
21
+ - @mastra/server@1.37.0-alpha.8
22
+
23
+ ## 1.3.24-alpha.7
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies [[`168fa09`](https://github.com/mastra-ai/mastra/commit/168fa09d6b39114cb8c13bd06f1dccb9bc81c6cd)]:
28
+ - @mastra/core@1.37.0-alpha.7
29
+ - @mastra/server@1.37.0-alpha.7
30
+
31
+ ## 1.3.24-alpha.6
32
+
33
+ ### Patch Changes
34
+
35
+ - Developers can now cancel long-running custom API route work when clients disconnect. Node-based adapters pass abort signals into custom route handlers, clean up response streams correctly, and still surface upstream response body errors. ([#16335](https://github.com/mastra-ai/mastra/pull/16335))
36
+
37
+ ```ts
38
+ registerApiRoute('/stream', {
39
+ method: 'GET',
40
+ handler: async c => {
41
+ const stream = await agent.stream(prompt, {
42
+ abortSignal: c.req.raw.signal,
43
+ });
44
+
45
+ return stream.toTextStreamResponse();
46
+ },
47
+ });
48
+ ```
49
+
50
+ - Updated dependencies [[`fafed7a`](https://github.com/mastra-ai/mastra/commit/fafed7a24dc320f7c92ee872c347f4be087fd689), [`0cbece9`](https://github.com/mastra-ai/mastra/commit/0cbece9d832cb134a74cdbf3682d390a058215a4), [`7dfe1bc`](https://github.com/mastra-ai/mastra/commit/7dfe1bcfe71d261a6fd6bbf29b1dec49d78fb98f), [`70cb714`](https://github.com/mastra-ai/mastra/commit/70cb7149c8f16f478e15b58498254a53181750a4), [`7f9da22`](https://github.com/mastra-ai/mastra/commit/7f9da22efd5aa595e138a31de55a5f0f2f28b33d)]:
51
+ - @mastra/server@1.37.0-alpha.6
52
+ - @mastra/core@1.37.0-alpha.6
53
+
3
54
  ## 1.3.24-alpha.5
4
55
 
5
56
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -6,6 +6,9 @@ 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;
9
12
  // @__NO_SIDE_EFFECTS__
10
13
  function $constructor(name, initializer3, params) {
11
14
  function init(inst, def) {
@@ -58,15 +61,16 @@ function $constructor(name, initializer3, params) {
58
61
  Object.defineProperty(_, "name", { value: name });
59
62
  return _;
60
63
  }
64
+ (_a = globalThis).__zod_globalConfig ?? (_a.__zod_globalConfig = {});
61
65
 
62
- // ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/util.js
66
+ // ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/util.js
63
67
  function jsonStringifyReplacer(_, value) {
64
68
  if (typeof value === "bigint")
65
69
  return value.toString();
66
70
  return value;
67
71
  }
68
72
 
69
- // ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/errors.js
73
+ // ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/errors.js
70
74
  var initializer = (inst, def) => {
71
75
  inst.name = "$ZodError";
72
76
  Object.defineProperty(inst, "_zod", {
@@ -84,7 +88,7 @@ var initializer = (inst, def) => {
84
88
  });
85
89
  };
86
90
  var $ZodError = $constructor("$ZodError", initializer);
87
- function flattenError(error, mapper = (issue2) => issue2.message) {
91
+ function flattenError(error, mapper = (issue) => issue.message) {
88
92
  const fieldErrors = {};
89
93
  const formErrors = [];
90
94
  for (const sub of error.issues) {
@@ -97,32 +101,35 @@ function flattenError(error, mapper = (issue2) => issue2.message) {
97
101
  }
98
102
  return { formErrors, fieldErrors };
99
103
  }
100
- function formatError(error, mapper = (issue2) => issue2.message) {
104
+ function formatError(error, mapper = (issue) => issue.message) {
101
105
  const fieldErrors = { _errors: [] };
102
- const processError = (error2) => {
103
- for (const issue2 of error2.issues) {
104
- if (issue2.code === "invalid_union" && issue2.errors.length) {
105
- issue2.errors.map((issues) => processError({ issues }));
106
- } else if (issue2.code === "invalid_key") {
107
- processError({ issues: issue2.issues });
108
- } else if (issue2.code === "invalid_element") {
109
- processError({ issues: issue2.issues });
110
- } else if (issue2.path.length === 0) {
111
- fieldErrors._errors.push(mapper(issue2));
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]);
112
114
  } else {
113
- let curr = fieldErrors;
114
- let i = 0;
115
- while (i < issue2.path.length) {
116
- const el = issue2.path[i];
117
- const terminal = i === issue2.path.length - 1;
118
- if (!terminal) {
119
- curr[el] = curr[el] || { _errors: [] };
120
- } else {
121
- curr[el] = curr[el] || { _errors: [] };
122
- curr[el]._errors.push(mapper(issue2));
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++;
123
132
  }
124
- curr = curr[el];
125
- i++;
126
133
  }
127
134
  }
128
135
  }
@@ -131,54 +138,7 @@ function formatError(error, mapper = (issue2) => issue2.message) {
131
138
  return fieldErrors;
132
139
  }
133
140
 
134
- // ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/registries.js
135
- var _a;
136
- var $ZodRegistry = class {
137
- constructor() {
138
- this._map = /* @__PURE__ */ new WeakMap();
139
- this._idmap = /* @__PURE__ */ new Map();
140
- }
141
- add(schema, ..._meta) {
142
- const meta = _meta[0];
143
- this._map.set(schema, meta);
144
- if (meta && typeof meta === "object" && "id" in meta) {
145
- this._idmap.set(meta.id, schema);
146
- }
147
- return this;
148
- }
149
- clear() {
150
- this._map = /* @__PURE__ */ new WeakMap();
151
- this._idmap = /* @__PURE__ */ new Map();
152
- return this;
153
- }
154
- remove(schema) {
155
- const meta = this._map.get(schema);
156
- if (meta && typeof meta === "object" && "id" in meta) {
157
- this._idmap.delete(meta.id);
158
- }
159
- this._map.delete(schema);
160
- return this;
161
- }
162
- get(schema) {
163
- const p = schema._zod.parent;
164
- if (p) {
165
- const pm = { ...this.get(p) ?? {} };
166
- delete pm.id;
167
- const f = { ...pm, ...this._map.get(schema) };
168
- return Object.keys(f).length ? f : void 0;
169
- }
170
- return this._map.get(schema);
171
- }
172
- has(schema) {
173
- return this._map.has(schema);
174
- }
175
- };
176
- function registry() {
177
- return new $ZodRegistry();
178
- }
179
- (_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
180
-
181
- // ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/errors.js
141
+ // ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/errors.js
182
142
  var initializer2 = (inst, issues) => {
183
143
  $ZodError.init(inst, issues);
184
144
  inst.name = "ZodError";
@@ -192,8 +152,8 @@ var initializer2 = (inst, issues) => {
192
152
  // enumerable: false,
193
153
  },
194
154
  addIssue: {
195
- value: (issue2) => {
196
- inst.issues.push(issue2);
155
+ value: (issue) => {
156
+ inst.issues.push(issue);
197
157
  inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
198
158
  }
199
159
  // enumerable: false,
@@ -213,7 +173,7 @@ var initializer2 = (inst, issues) => {
213
173
  }
214
174
  });
215
175
  };
216
- var ZodError = $constructor("ZodError", initializer2);
176
+ var ZodError = /* @__PURE__ */ $constructor("ZodError", initializer2);
217
177
  function toWebRequest(req) {
218
178
  const protocol = req.protocol || "http";
219
179
  const host = req.get("host") || "localhost";
@@ -381,6 +341,10 @@ var MastraServer = class extends serverAdapter.MastraServer {
381
341
  const { done, value } = await reader.read();
382
342
  if (done) break;
383
343
  if (value) {
344
+ if (streamFormat === "sse" && typeof value === "string" && value.startsWith(":")) {
345
+ res.write(value);
346
+ continue;
347
+ }
384
348
  const shouldRedact = this.streamOptions?.redact ?? true;
385
349
  const outputValue = shouldRedact ? serverAdapter.redactStreamChunk(value) : value;
386
350
  if (streamFormat === "sse") {
@@ -796,10 +760,11 @@ var MastraServer = class extends serverAdapter.MastraServer {
796
760
  req.method,
797
761
  req.headers,
798
762
  req.body,
799
- res.locals.requestContext
763
+ res.locals.requestContext,
764
+ res.locals.abortSignal
800
765
  );
801
766
  if (!response) return next();
802
- await this.writeCustomRouteResponse(response, res);
767
+ await this.writeCustomRouteResponse(response, res, res.locals.abortSignal);
803
768
  });
804
769
  }
805
770
  registerContextMiddleware() {
@@ -819,14 +784,14 @@ var MastraServer = class extends serverAdapter.MastraServer {
819
784
  const method = req.method;
820
785
  const path = req.path;
821
786
  res.on("finish", () => {
822
- const duration2 = Date.now() - start;
787
+ const duration = Date.now() - start;
823
788
  const status = res.statusCode;
824
789
  const level = this.httpLoggingConfig?.level || "info";
825
790
  const logData = {
826
791
  method,
827
792
  path,
828
793
  status,
829
- duration: `${duration2}ms`
794
+ duration: `${duration}ms`
830
795
  };
831
796
  if (this.httpLoggingConfig?.includeQueryParams) {
832
797
  logData.query = req.query;
@@ -842,7 +807,7 @@ var MastraServer = class extends serverAdapter.MastraServer {
842
807
  });
843
808
  logData.headers = headers;
844
809
  }
845
- this.logger[level](`${method} ${path} ${status} ${duration2}ms`, logData);
810
+ this.logger[level](`${method} ${path} ${status} ${duration}ms`, logData);
846
811
  });
847
812
  next();
848
813
  });