@mastra/nestjs 0.1.9 → 0.1.10-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/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { Logger, BadRequestException, Injectable, Inject, HttpException, HttpStatus, Catch, UnauthorizedException, ForbiddenException, Scope, ServiceUnavailableException, NotFoundException, All, Req, Res, Controller, UseInterceptors, UseFilters, UseGuards, Get, PayloadTooLargeException, Module, SetMetadata } from '@nestjs/common';
2
- import { SERVER_ROUTES, isReservedRequestContextKey, isStudioClientTypeHeader, MASTRA_CLIENT_TYPE_HEADER, MASTRA_IS_STUDIO_KEY, redactStreamChunk, normalizeQueryParams } from '@mastra/server/server-adapter';
3
- import { formatZodError } from '@mastra/server/handlers/error';
4
- import { ZodError } from 'zod';
2
+ import { SERVER_ROUTES, isZodError, isReservedRequestContextKey, isStudioClientTypeHeader, MASTRA_CLIENT_TYPE_HEADER, MASTRA_IS_STUDIO_KEY, redactStreamChunk, normalizeQueryParams } from '@mastra/server/server-adapter';
3
+ import { isZodError as isZodError$1, formatZodError } from '@mastra/server/handlers/error';
5
4
  import { isDevPlaygroundRequest, isProtectedPath, canAccessPublicly, checkRules, defaultAuthConfig } from '@mastra/server/auth';
6
5
  import { RequestContext } from '@mastra/core/request-context';
7
6
  import { REQUEST, Reflector, HttpAdapterHost } from '@nestjs/core';
@@ -11663,10 +11662,6 @@ function _ts_param(paramIndex, decorator) {
11663
11662
  };
11664
11663
  }
11665
11664
  __name(_ts_param, "_ts_param");
11666
- function isZodErrorLike(error) {
11667
- return error instanceof ZodError || typeof error === "object" && error !== null && "name" in error && error.name === "ZodError" && "issues" in error && Array.isArray(error.issues);
11668
- }
11669
- __name(isZodErrorLike, "isZodErrorLike");
11670
11665
  var RouteHandlerService = class _RouteHandlerService {
11671
11666
  static {
11672
11667
  __name(this, "RouteHandlerService");
@@ -11785,7 +11780,7 @@ var RouteHandlerService = class _RouteHandlerService {
11785
11780
  try {
11786
11781
  validatedPathParams = await route.pathParamSchema.parseAsync(params.pathParams);
11787
11782
  } catch (error) {
11788
- if (isZodErrorLike(error)) {
11783
+ if (isZodError(error)) {
11789
11784
  throw new ValidationError("Invalid path parameters", error);
11790
11785
  }
11791
11786
  throw error;
@@ -11796,7 +11791,7 @@ var RouteHandlerService = class _RouteHandlerService {
11796
11791
  try {
11797
11792
  validatedQueryParams = await route.queryParamSchema.parseAsync(params.queryParams);
11798
11793
  } catch (error) {
11799
- if (isZodErrorLike(error)) {
11794
+ if (isZodError(error)) {
11800
11795
  throw new ValidationError("Invalid query parameters", error);
11801
11796
  }
11802
11797
  throw error;
@@ -11807,7 +11802,7 @@ var RouteHandlerService = class _RouteHandlerService {
11807
11802
  try {
11808
11803
  validatedBody = await route.bodySchema.parseAsync(params.body);
11809
11804
  } catch (error) {
11810
- if (isZodErrorLike(error)) {
11805
+ if (isZodError(error)) {
11811
11806
  throw new ValidationError("Invalid request body", error);
11812
11807
  }
11813
11808
  throw error;
@@ -11831,7 +11826,8 @@ var RouteHandlerService = class _RouteHandlerService {
11831
11826
  return {
11832
11827
  data,
11833
11828
  responseType: route.responseType,
11834
- streamFormat: route.streamFormat
11829
+ streamFormat: route.streamFormat,
11830
+ sseFlushOnConnect: route.sseFlushOnConnect
11835
11831
  };
11836
11832
  }
11837
11833
  getRouteKey(method, path) {
@@ -11881,10 +11877,6 @@ function _ts_decorate2(decorators, target, key, desc) {
11881
11877
  return c > 3 && r && Object.defineProperty(target, key, r), r;
11882
11878
  }
11883
11879
  __name(_ts_decorate2, "_ts_decorate");
11884
- function isZodErrorLike2(exception) {
11885
- return exception instanceof ZodError || typeof exception === "object" && exception !== null && "name" in exception && exception.name === "ZodError" && "issues" in exception && Array.isArray(exception.issues);
11886
- }
11887
- __name(isZodErrorLike2, "isZodErrorLike");
11888
11880
  var MastraExceptionFilter = class _MastraExceptionFilter {
11889
11881
  static {
11890
11882
  __name(this, "MastraExceptionFilter");
@@ -11956,7 +11948,7 @@ var MastraExceptionFilter = class _MastraExceptionFilter {
11956
11948
  code: this.getErrorCode(status)
11957
11949
  };
11958
11950
  }
11959
- if (isZodErrorLike2(exception)) {
11951
+ if (isZodError$1(exception)) {
11960
11952
  const formatted = formatZodError(exception, "request");
11961
11953
  return {
11962
11954
  status: HttpStatus.BAD_REQUEST,
@@ -12977,6 +12969,9 @@ var StreamingInterceptor = class _StreamingInterceptor {
12977
12969
  if (streamFormat === "sse") {
12978
12970
  response.setHeader("X-Accel-Buffering", "no");
12979
12971
  }
12972
+ if (streamFormat === "sse" && result.sseFlushOnConnect) {
12973
+ response.write(": connected\n\n");
12974
+ }
12980
12975
  const data = result.data;
12981
12976
  const hasFullStream = data !== null && typeof data === "object" && "fullStream" in data;
12982
12977
  const stream = hasFullStream ? data.fullStream : data;
@@ -12997,6 +12992,10 @@ var StreamingInterceptor = class _StreamingInterceptor {
12997
12992
  break;
12998
12993
  }
12999
12994
  if (value) {
12995
+ if (streamFormat === "sse" && typeof value === "string" && value.startsWith(":")) {
12996
+ response.write(value);
12997
+ continue;
12998
+ }
13000
12999
  const outputValue = shouldRedact ? redactStreamChunk(value) : value;
13001
13000
  if (streamFormat === "sse") {
13002
13001
  response.write(`data: ${JSON.stringify(outputValue)}