@mastra/nestjs 0.0.0
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/README.md +324 -0
- package/dist/__tests__/test-helpers.d.ts +17 -0
- package/dist/__tests__/test-helpers.d.ts.map +1 -0
- package/dist/constants.d.ts +34 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/controllers/index.d.ts +3 -0
- package/dist/controllers/index.d.ts.map +1 -0
- package/dist/controllers/mastra.controller.d.ts +54 -0
- package/dist/controllers/mastra.controller.d.ts.map +1 -0
- package/dist/controllers/system.controller.d.ts +45 -0
- package/dist/controllers/system.controller.d.ts.map +1 -0
- package/dist/decorators/index.d.ts +3 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/public.decorator.d.ts +17 -0
- package/dist/decorators/public.decorator.d.ts.map +1 -0
- package/dist/decorators/throttle.decorator.d.ts +34 -0
- package/dist/decorators/throttle.decorator.d.ts.map +1 -0
- package/dist/filters/index.d.ts +2 -0
- package/dist/filters/index.d.ts.map +1 -0
- package/dist/filters/mastra-exception.filter.d.ts +28 -0
- package/dist/filters/mastra-exception.filter.d.ts.map +1 -0
- package/dist/guards/index.d.ts +3 -0
- package/dist/guards/index.d.ts.map +1 -0
- package/dist/guards/mastra-auth.guard.d.ts +42 -0
- package/dist/guards/mastra-auth.guard.d.ts.map +1 -0
- package/dist/guards/mastra-route.guard.d.ts +23 -0
- package/dist/guards/mastra-route.guard.d.ts.map +1 -0
- package/dist/guards/mastra-throttle.guard.d.ts +53 -0
- package/dist/guards/mastra-throttle.guard.d.ts.map +1 -0
- package/dist/index.cjs +14298 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14284 -0
- package/dist/index.js.map +1 -0
- package/dist/interceptors/index.d.ts +3 -0
- package/dist/interceptors/index.d.ts.map +1 -0
- package/dist/interceptors/request-tracking.interceptor.d.ts +13 -0
- package/dist/interceptors/request-tracking.interceptor.d.ts.map +1 -0
- package/dist/interceptors/streaming.interceptor.d.ts +40 -0
- package/dist/interceptors/streaming.interceptor.d.ts.map +1 -0
- package/dist/interceptors/tracing.interceptor.d.ts +12 -0
- package/dist/interceptors/tracing.interceptor.d.ts.map +1 -0
- package/dist/mastra-server.adapter.d.ts +10 -0
- package/dist/mastra-server.adapter.d.ts.map +1 -0
- package/dist/mastra.module.d.ts +173 -0
- package/dist/mastra.module.d.ts.map +1 -0
- package/dist/mastra.service.d.ts +51 -0
- package/dist/mastra.service.d.ts.map +1 -0
- package/dist/middleware/body-limit.middleware.d.ts +24 -0
- package/dist/middleware/body-limit.middleware.d.ts.map +1 -0
- package/dist/middleware/index.d.ts +3 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/json-body.middleware.d.ts +17 -0
- package/dist/middleware/json-body.middleware.d.ts.map +1 -0
- package/dist/services/auth.service.d.ts +34 -0
- package/dist/services/auth.service.d.ts.map +1 -0
- package/dist/services/index.d.ts +5 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/request-context.service.d.ts +52 -0
- package/dist/services/request-context.service.d.ts.map +1 -0
- package/dist/services/route-handler.service.d.ts +78 -0
- package/dist/services/route-handler.service.d.ts.map +1 -0
- package/dist/services/shutdown.service.d.ts +54 -0
- package/dist/services/shutdown.service.d.ts.map +1 -0
- package/dist/utils/constants.d.ts +3 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/format.d.ts +5 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/parse-multipart.d.ts +18 -0
- package/dist/utils/parse-multipart.d.ts.map +1 -0
- package/dist/utils/route-path.d.ts +6 -0
- package/dist/utils/route-path.d.ts.map +1 -0
- package/package.json +84 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interceptors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { ShutdownService } from '../services/shutdown.service.js';
|
|
4
|
+
/**
|
|
5
|
+
* Interceptor that tracks requests for graceful shutdown.
|
|
6
|
+
* Also rejects new requests during shutdown.
|
|
7
|
+
*/
|
|
8
|
+
export declare class RequestTrackingInterceptor implements NestInterceptor {
|
|
9
|
+
private readonly shutdownService;
|
|
10
|
+
constructor(shutdownService: ShutdownService);
|
|
11
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=request-tracking.interceptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-tracking.interceptor.d.ts","sourceRoot":"","sources":["../../src/interceptors/request-tracking.interceptor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAErF,OAAO,EAAE,UAAU,EAAmB,MAAM,MAAM,CAAC;AAEnD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D;;;GAGG;AACH,qBACa,0BAA2B,YAAW,eAAe;IAC3B,OAAO,CAAC,QAAQ,CAAC,eAAe;gBAAf,eAAe,EAAE,eAAe;IAEtF,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC;CAwB7E"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import type { MastraModuleOptions } from '../mastra.module.js';
|
|
4
|
+
import { ShutdownService } from '../services/shutdown.service.js';
|
|
5
|
+
/**
|
|
6
|
+
* Interceptor that handles streaming responses and MCP transports.
|
|
7
|
+
* Converts ReadableStream results to chunked HTTP responses.
|
|
8
|
+
*/
|
|
9
|
+
export declare class StreamingInterceptor implements NestInterceptor {
|
|
10
|
+
private readonly options;
|
|
11
|
+
private readonly shutdownService;
|
|
12
|
+
private readonly logger;
|
|
13
|
+
private readonly normalizedPrefix;
|
|
14
|
+
private readonly heartbeatMs;
|
|
15
|
+
constructor(options: MastraModuleOptions, shutdownService: ShutdownService);
|
|
16
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
|
|
17
|
+
/**
|
|
18
|
+
* Determine the response type of a handler result, or null if it's not
|
|
19
|
+
* a recognized RouteHandlerResult.
|
|
20
|
+
*/
|
|
21
|
+
private getResultType;
|
|
22
|
+
private handleJsonNull;
|
|
23
|
+
/**
|
|
24
|
+
* Handle streaming response - write chunks to response.
|
|
25
|
+
*/
|
|
26
|
+
private handleStreaming;
|
|
27
|
+
/**
|
|
28
|
+
* Handle datastream response (AI SDK Response).
|
|
29
|
+
*/
|
|
30
|
+
private handleDatastream;
|
|
31
|
+
/**
|
|
32
|
+
* Handle MCP HTTP transport response.
|
|
33
|
+
*/
|
|
34
|
+
private handleMcpHttp;
|
|
35
|
+
/**
|
|
36
|
+
* Handle MCP SSE transport response.
|
|
37
|
+
*/
|
|
38
|
+
private handleMcpSse;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=streaming.interceptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.interceptor.d.ts","sourceRoot":"","sources":["../../src/interceptors/streaming.interceptor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAErF,OAAO,EAAE,UAAU,EAAuB,MAAM,MAAM,CAAC;AAGvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAE5D,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D;;;GAGG;AACH,qBACa,oBAAqB,YAAW,eAAe;IAMhC,OAAO,CAAC,QAAQ,CAAC,OAAO;IACvB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAN3D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyC;IAChE,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAgB;gBAGD,OAAO,EAAE,mBAAmB,EAC3B,eAAe,EAAE,eAAe;IAuB5E,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC;IA2B5E;;;OAGG;IACH,OAAO,CAAC,aAAa;YAyBP,cAAc;IAQ5B;;OAEG;YACW,eAAe;IA2E7B;;OAEG;YACW,gBAAgB;IA4B9B;;OAEG;YACW,aAAa;IAuC3B;;OAEG;YACW,YAAY;CA+B3B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import type { MastraModuleOptions } from '../mastra.module.js';
|
|
4
|
+
import { RouteHandlerService } from '../services/route-handler.service.js';
|
|
5
|
+
export declare class TracingInterceptor implements NestInterceptor {
|
|
6
|
+
private readonly options;
|
|
7
|
+
private readonly routeHandler;
|
|
8
|
+
private readonly logger;
|
|
9
|
+
constructor(options: MastraModuleOptions, routeHandler: RouteHandlerService);
|
|
10
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=tracing.interceptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracing.interceptor.d.ts","sourceRoot":"","sources":["../../src/interceptors/tracing.interceptor.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAErF,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAIlC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AA6CxE,qBACa,kBAAmB,YAAW,eAAe;IAI9B,OAAO,CAAC,QAAQ,CAAC,OAAO;IACnB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAJ5D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuC;gBAGnB,OAAO,EAAE,mBAAmB,EACvB,YAAY,EAAE,mBAAmB;IAGjF,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC;CAoD7E"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MastraServerBase } from '@mastra/core/server';
|
|
2
|
+
import type { Application } from 'express';
|
|
3
|
+
/**
|
|
4
|
+
* Minimal Mastra server adapter wrapper for NestJS.
|
|
5
|
+
* Provides MastraServerBase compatibility so getServerApp() works.
|
|
6
|
+
*/
|
|
7
|
+
export declare class NestMastraServer extends MastraServerBase<Application> {
|
|
8
|
+
constructor(app: Application);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=mastra-server.adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mastra-server.adapter.d.ts","sourceRoot":"","sources":["../src/mastra-server.adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,gBAAgB,CAAC,WAAW,CAAC;gBACrD,GAAG,EAAE,WAAW;CAG7B"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import type { ToolsInput } from '@mastra/core/agent';
|
|
2
|
+
import type { Mastra } from '@mastra/core/mastra';
|
|
3
|
+
import type { InMemoryTaskStore } from '@mastra/server/a2a/store';
|
|
4
|
+
import type { DynamicModule, MiddlewareConsumer, NestModule, Type } from '@nestjs/common';
|
|
5
|
+
/**
|
|
6
|
+
* Options for MastraModule configuration.
|
|
7
|
+
*/
|
|
8
|
+
export interface MastraModuleOptions {
|
|
9
|
+
/** The Mastra instance to register */
|
|
10
|
+
mastra: Mastra;
|
|
11
|
+
/** Route prefix (default: '/api') */
|
|
12
|
+
prefix?: string;
|
|
13
|
+
/** Request body size limits */
|
|
14
|
+
bodyLimitOptions?: {
|
|
15
|
+
/** Max body size in bytes (default: 10MB) */
|
|
16
|
+
maxSize?: number;
|
|
17
|
+
/** Max per-file size in bytes (default: 50MB) */
|
|
18
|
+
maxFileSize?: number;
|
|
19
|
+
/** Temp directory for file uploads */
|
|
20
|
+
tempDir?: string;
|
|
21
|
+
/** Allowed MIME types for file uploads */
|
|
22
|
+
allowedMimeTypes?: string[];
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Rate limiting options.
|
|
26
|
+
* Rate limiting is ON by default - set enabled: false to disable.
|
|
27
|
+
*/
|
|
28
|
+
rateLimitOptions?: {
|
|
29
|
+
/** Enable/disable rate limiting (default: true) */
|
|
30
|
+
enabled?: boolean;
|
|
31
|
+
/** Default requests per window (default: 100) */
|
|
32
|
+
defaultLimit?: number;
|
|
33
|
+
/** Window size in ms (default: 60000 = 1 minute) */
|
|
34
|
+
windowMs?: number;
|
|
35
|
+
/** Stricter limit for /generate endpoints (default: 10) */
|
|
36
|
+
generateLimit?: number;
|
|
37
|
+
};
|
|
38
|
+
/** Graceful shutdown options */
|
|
39
|
+
shutdownOptions?: {
|
|
40
|
+
/** Max wait time for in-flight requests in ms (default: 30000) */
|
|
41
|
+
timeoutMs?: number;
|
|
42
|
+
/** Send shutdown event to SSE clients (default: true) */
|
|
43
|
+
notifyClients?: boolean;
|
|
44
|
+
};
|
|
45
|
+
/** Observability options */
|
|
46
|
+
tracingOptions?: {
|
|
47
|
+
/** Enable tracing (default: auto-detect @opentelemetry/api) */
|
|
48
|
+
enabled?: boolean;
|
|
49
|
+
/** Service name for spans */
|
|
50
|
+
serviceName?: string;
|
|
51
|
+
};
|
|
52
|
+
/** Context parsing options */
|
|
53
|
+
contextOptions?: {
|
|
54
|
+
/** Fail on parse errors (default: false) */
|
|
55
|
+
strict?: boolean;
|
|
56
|
+
/** Log parse warnings (default: true) */
|
|
57
|
+
logWarnings?: boolean;
|
|
58
|
+
};
|
|
59
|
+
/** Additional tools to register */
|
|
60
|
+
tools?: ToolsInput;
|
|
61
|
+
/** Task store for async operations */
|
|
62
|
+
taskStore?: InMemoryTaskStore;
|
|
63
|
+
/** Mastra-internal authentication configuration. Disabled by default.
|
|
64
|
+
* Most NestJS apps have their own global auth guards -- Mastra defers to those.
|
|
65
|
+
* Enable this only if you want Mastra's built-in token auth. */
|
|
66
|
+
auth?: {
|
|
67
|
+
/** Enable Mastra's internal auth (default: false) */
|
|
68
|
+
enabled?: boolean;
|
|
69
|
+
/** Allow `?apiKey=` query auth for backward compatibility (default: false) */
|
|
70
|
+
allowQueryApiKey?: boolean;
|
|
71
|
+
};
|
|
72
|
+
/** Per-route auth configuration */
|
|
73
|
+
customRouteAuthConfig?: Map<string, boolean>;
|
|
74
|
+
/** Streaming configuration */
|
|
75
|
+
streamOptions?: {
|
|
76
|
+
/** Redact sensitive data from streams (default: true) */
|
|
77
|
+
redact?: boolean;
|
|
78
|
+
/** Send SSE heartbeats every N ms (default: disabled). Set <= 0 to disable. */
|
|
79
|
+
heartbeatMs?: number;
|
|
80
|
+
};
|
|
81
|
+
/** MCP transport options */
|
|
82
|
+
mcpOptions?: {
|
|
83
|
+
/** Run in serverless mode */
|
|
84
|
+
serverless?: boolean;
|
|
85
|
+
/** Custom session ID generator */
|
|
86
|
+
sessionIdGenerator?: () => string;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Options for async module configuration.
|
|
91
|
+
*/
|
|
92
|
+
export interface MastraModuleAsyncOptions {
|
|
93
|
+
/** Modules to import for dependency injection */
|
|
94
|
+
imports?: any[];
|
|
95
|
+
/** Factory function to create module options */
|
|
96
|
+
useFactory?: (...args: any[]) => Promise<MastraModuleOptions> | MastraModuleOptions;
|
|
97
|
+
/** Dependencies to inject into the factory function */
|
|
98
|
+
inject?: any[];
|
|
99
|
+
/** Use an existing provider */
|
|
100
|
+
useExisting?: Type<MastraModuleOptionsFactory>;
|
|
101
|
+
/** Use a class to create options */
|
|
102
|
+
useClass?: Type<MastraModuleOptionsFactory>;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Interface for async options factory.
|
|
106
|
+
*/
|
|
107
|
+
export interface MastraModuleOptionsFactory {
|
|
108
|
+
createMastraOptions(): Promise<MastraModuleOptions> | MastraModuleOptions;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* NestJS module for integrating Mastra into your application.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* Basic registration:
|
|
115
|
+
* ```typescript
|
|
116
|
+
* @Module({
|
|
117
|
+
* imports: [
|
|
118
|
+
* MastraModule.register({
|
|
119
|
+
* mastra: new Mastra({ agents: { ... } }),
|
|
120
|
+
* prefix: '/api',
|
|
121
|
+
* }),
|
|
122
|
+
* ],
|
|
123
|
+
* })
|
|
124
|
+
* export class AppModule {}
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* With rate limiting disabled:
|
|
129
|
+
* ```typescript
|
|
130
|
+
* MastraModule.register({
|
|
131
|
+
* mastra,
|
|
132
|
+
* rateLimitOptions: { enabled: false },
|
|
133
|
+
* })
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* Async registration:
|
|
138
|
+
* ```typescript
|
|
139
|
+
* MastraModule.registerAsync({
|
|
140
|
+
* imports: [ConfigModule],
|
|
141
|
+
* useFactory: (config: ConfigService) => ({
|
|
142
|
+
* mastra: new Mastra({ ... }),
|
|
143
|
+
* prefix: config.get('MASTRA_PREFIX', '/api'),
|
|
144
|
+
* }),
|
|
145
|
+
* inject: [ConfigService],
|
|
146
|
+
* })
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
export declare class MastraModule implements NestModule {
|
|
150
|
+
/**
|
|
151
|
+
* Register Mastra with the NestJS application.
|
|
152
|
+
*
|
|
153
|
+
* @param options - Configuration options including the Mastra instance
|
|
154
|
+
* @returns Dynamic module configuration
|
|
155
|
+
*/
|
|
156
|
+
static register(options: MastraModuleOptions): DynamicModule;
|
|
157
|
+
/**
|
|
158
|
+
* Register Mastra asynchronously for when configuration depends on other services.
|
|
159
|
+
*
|
|
160
|
+
* @param options - Async configuration options
|
|
161
|
+
* @returns Dynamic module configuration
|
|
162
|
+
*/
|
|
163
|
+
static registerAsync(options: MastraModuleAsyncOptions): DynamicModule;
|
|
164
|
+
/**
|
|
165
|
+
* Configure middleware for the module.
|
|
166
|
+
* Order matters: body limit must run BEFORE JSON parsing.
|
|
167
|
+
*
|
|
168
|
+
* Middleware is scoped to MastraController to avoid affecting other routes
|
|
169
|
+
* in the user's NestJS application.
|
|
170
|
+
*/
|
|
171
|
+
configure(consumer: MiddlewareConsumer): void;
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=mastra.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mastra.module.d.ts","sourceRoot":"","sources":["../src/mastra.module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CA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;;;;;;;;;GAsCG;AACH,qBACa,YAAa,YAAW,UAAU;IAC7C;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,mBAAmB,GAAG,aAAa;IA8C5D;;;;;OAKG;IACH,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,wBAAwB,GAAG,aAAa;IAoFtE;;;;;;OAMG;IACH,SAAS,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI;CAK9C"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Mastra } from '@mastra/core/mastra';
|
|
2
|
+
import { HttpAdapterHost } from '@nestjs/core';
|
|
3
|
+
import type { MastraModuleOptions } from './mastra.module.js';
|
|
4
|
+
import { ShutdownService } from './services/shutdown.service.js';
|
|
5
|
+
/**
|
|
6
|
+
* Injectable service for accessing Mastra and managing lifecycle.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* @Injectable()
|
|
11
|
+
* export class MyService {
|
|
12
|
+
* constructor(private readonly mastraService: MastraService) {}
|
|
13
|
+
*
|
|
14
|
+
* async runAgent() {
|
|
15
|
+
* const mastra = this.mastraService.getMastra();
|
|
16
|
+
* const agent = mastra.getAgent('my-agent');
|
|
17
|
+
* return agent.generate({ messages: [{ role: 'user', content: 'Hello' }] });
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare class MastraService {
|
|
23
|
+
private readonly mastra;
|
|
24
|
+
private readonly options;
|
|
25
|
+
private readonly shutdownService;
|
|
26
|
+
private readonly httpAdapterHost;
|
|
27
|
+
private readonly logger;
|
|
28
|
+
private serverAdapter?;
|
|
29
|
+
constructor(mastra: Mastra, options: MastraModuleOptions, shutdownService: ShutdownService, httpAdapterHost: HttpAdapterHost);
|
|
30
|
+
/**
|
|
31
|
+
* Get the Mastra instance.
|
|
32
|
+
*/
|
|
33
|
+
getMastra(): Mastra;
|
|
34
|
+
/**
|
|
35
|
+
* Get module options.
|
|
36
|
+
*/
|
|
37
|
+
getOptions(): MastraModuleOptions;
|
|
38
|
+
/**
|
|
39
|
+
* Get an agent by ID.
|
|
40
|
+
*/
|
|
41
|
+
getAgent(agentId: string): import("@mastra/core/agent").Agent<any, import("@mastra/core/agent").ToolsInput, undefined, unknown>;
|
|
42
|
+
/**
|
|
43
|
+
* Get a workflow by ID.
|
|
44
|
+
*/
|
|
45
|
+
getWorkflow(workflowId: string): import("@mastra/core/workflows").AnyWorkflow;
|
|
46
|
+
/**
|
|
47
|
+
* Check if the service is shutting down.
|
|
48
|
+
*/
|
|
49
|
+
get isShuttingDown(): boolean;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=mastra.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mastra.service.d.ts","sourceRoot":"","sources":["../src/mastra.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAI/C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D;;;;;;;;;;;;;;;;GAgBG;AACH,qBACa,aAAa;IAKN,OAAO,CAAC,QAAQ,CAAC,MAAM;IACf,OAAO,CAAC,QAAQ,CAAC,OAAO;IACvB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,eAAe;IAP3D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkC;IACzD,OAAO,CAAC,aAAa,CAAC,CAAmB;gBAGN,MAAM,EAAE,MAAM,EACN,OAAO,EAAE,mBAAmB,EAC3B,eAAe,EAAE,eAAe,EAChC,eAAe,EAAE,eAAe;IAoB5E;;OAEG;IACH,SAAS,IAAI,MAAM;IAInB;;OAEG;IACH,UAAU,IAAI,mBAAmB;IAIjC;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM;IAIxB;;OAEG;IACH,WAAW,CAAC,UAAU,EAAE,MAAM;IAI9B;;OAEG;IACH,IAAI,cAAc,IAAI,OAAO,CAE5B;CACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { NestMiddleware } from '@nestjs/common';
|
|
2
|
+
import type { Request, Response, NextFunction } from 'express';
|
|
3
|
+
import type { MastraModuleOptions } from '../mastra.module.js';
|
|
4
|
+
/**
|
|
5
|
+
* Middleware that enforces body size limits via Content-Length header.
|
|
6
|
+
*
|
|
7
|
+
* This middleware runs BEFORE body parsers and provides early rejection
|
|
8
|
+
* of oversized payloads based on the Content-Length header.
|
|
9
|
+
*
|
|
10
|
+
* Note: JSON body size limits are also enforced by JsonBodyMiddleware's
|
|
11
|
+
* express.json({ limit: ... }) configuration, which handles both
|
|
12
|
+
* Content-Length validation and streaming body parsing.
|
|
13
|
+
*
|
|
14
|
+
* For multipart requests, size limits are enforced by Busboy in the
|
|
15
|
+
* route handler service.
|
|
16
|
+
*/
|
|
17
|
+
export declare class BodyLimitMiddleware implements NestMiddleware {
|
|
18
|
+
private readonly options;
|
|
19
|
+
private readonly logger;
|
|
20
|
+
private readonly maxSize;
|
|
21
|
+
constructor(options: MastraModuleOptions);
|
|
22
|
+
use(req: Request, res: Response, next: NextFunction): void;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=body-limit.middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body-limit.middleware.d.ts","sourceRoot":"","sources":["../../src/middleware/body-limit.middleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG/D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAI5D;;;;;;;;;;;;GAYG;AACH,qBACa,mBAAoB,YAAW,cAAc;IAIpB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAH5D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwC;IAC/D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAEoB,OAAO,EAAE,mBAAmB;IAIjF,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI;CAwB3D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { NestMiddleware } from '@nestjs/common';
|
|
2
|
+
import type { Request, Response, NextFunction } from 'express';
|
|
3
|
+
import type { MastraModuleOptions } from '../mastra.module.js';
|
|
4
|
+
/**
|
|
5
|
+
* Middleware that parses JSON request bodies.
|
|
6
|
+
* Uses express.json() with size limits from configuration.
|
|
7
|
+
*
|
|
8
|
+
* This middleware is essential for POST/PUT/PATCH requests to work properly.
|
|
9
|
+
* NestJS does not automatically parse JSON bodies unless body-parser is configured.
|
|
10
|
+
*/
|
|
11
|
+
export declare class JsonBodyMiddleware implements NestMiddleware {
|
|
12
|
+
private readonly options;
|
|
13
|
+
private readonly jsonParser;
|
|
14
|
+
constructor(options: MastraModuleOptions);
|
|
15
|
+
use(req: Request, res: Response, next: NextFunction): void;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=json-body.middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-body.middleware.d.ts","sourceRoot":"","sources":["../../src/middleware/json-body.middleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAI/D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAG5D;;;;;;GAMG;AACH,qBACa,kBAAmB,YAAW,cAAc;IAGnB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAF5D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAkC;gBAER,OAAO,EAAE,mBAAmB;IAUjF,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI;CAgB3D"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Mastra } from '@mastra/core/mastra';
|
|
2
|
+
import type { Request } from 'express';
|
|
3
|
+
import type { MastraModuleOptions } from '../mastra.module.js';
|
|
4
|
+
/**
|
|
5
|
+
* Service that handles authentication for Mastra routes.
|
|
6
|
+
* Called after route matching to check if auth is required.
|
|
7
|
+
*/
|
|
8
|
+
export declare class AuthService {
|
|
9
|
+
private readonly mastra;
|
|
10
|
+
private readonly options;
|
|
11
|
+
private readonly logger;
|
|
12
|
+
constructor(mastra: Mastra, options: MastraModuleOptions);
|
|
13
|
+
/**
|
|
14
|
+
* Check authentication for a request based on the matched route.
|
|
15
|
+
* Returns the authenticated user if auth succeeds, undefined if no auth required.
|
|
16
|
+
* Throws UnauthorizedException or ForbiddenException if auth fails.
|
|
17
|
+
*
|
|
18
|
+
* Type assertions (`as any`) are used because `@mastra/server/auth` types
|
|
19
|
+
* are Hono-centric. The runtime values work with Express requests.
|
|
20
|
+
*/
|
|
21
|
+
authenticate(request: Request): Promise<unknown>;
|
|
22
|
+
/**
|
|
23
|
+
* Check authorization for an authenticated user.
|
|
24
|
+
* `authConfig` is typed as `any` because `@mastra/server/auth` doesn't
|
|
25
|
+
* export a standalone type for the auth config object.
|
|
26
|
+
*/
|
|
27
|
+
private authorize;
|
|
28
|
+
/**
|
|
29
|
+
* Extract authentication token from request.
|
|
30
|
+
* Supports Authorization header (Bearer token) and API key query param.
|
|
31
|
+
*/
|
|
32
|
+
private extractToken;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=auth.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.service.d.ts","sourceRoot":"","sources":["../../src/services/auth.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAUlD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAS5D;;;GAGG;AACH,qBACa,WAAW;IAIJ,OAAO,CAAC,QAAQ,CAAC,MAAM;IACf,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJlD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgC;gBAGpB,MAAM,EAAE,MAAM,EACN,OAAO,EAAE,mBAAmB;IAGvE;;;;;;;OAOG;IACG,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IA4EtD;;;;OAIG;YACW,SAAS;IA0DvB;;;OAGG;IACH,OAAO,CAAC,YAAY;CAuBrB"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { RouteHandlerService, ValidationError, type RouteHandlerParams, type RouteHandlerResult, type RouteMatch, } from './route-handler.service.js';
|
|
2
|
+
export { RequestContextService } from './request-context.service.js';
|
|
3
|
+
export { ShutdownService } from './shutdown.service.js';
|
|
4
|
+
export { AuthService } from './auth.service.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,UAAU,GAChB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { RequestContext } from '@mastra/core/request-context';
|
|
2
|
+
import type { Request } from 'express';
|
|
3
|
+
import type { MastraModuleOptions } from '../mastra.module.js';
|
|
4
|
+
/**
|
|
5
|
+
* REQUEST-scoped service that manages request context and abort signaling.
|
|
6
|
+
* Created fresh for each HTTP request.
|
|
7
|
+
*/
|
|
8
|
+
export declare class RequestContextService {
|
|
9
|
+
private readonly request;
|
|
10
|
+
private readonly options;
|
|
11
|
+
private readonly logger;
|
|
12
|
+
private readonly abortController;
|
|
13
|
+
private readonly context;
|
|
14
|
+
private isAborted;
|
|
15
|
+
constructor(request: Request, options: MastraModuleOptions);
|
|
16
|
+
/**
|
|
17
|
+
* Get the abort signal for this request.
|
|
18
|
+
* Use this to detect client disconnection.
|
|
19
|
+
*/
|
|
20
|
+
get abortSignal(): AbortSignal;
|
|
21
|
+
/**
|
|
22
|
+
* Get the parsed request context.
|
|
23
|
+
*/
|
|
24
|
+
get requestContext(): RequestContext;
|
|
25
|
+
/**
|
|
26
|
+
* Set the authenticated user on the request context.
|
|
27
|
+
* Should be called after successful authentication.
|
|
28
|
+
*/
|
|
29
|
+
setUser(user: unknown): void;
|
|
30
|
+
/**
|
|
31
|
+
* Parse request context from body or query parameters.
|
|
32
|
+
*/
|
|
33
|
+
private parseRequestContext;
|
|
34
|
+
/**
|
|
35
|
+
* Parse encoded context from query parameter.
|
|
36
|
+
* Supports both plain JSON and base64-encoded JSON.
|
|
37
|
+
*/
|
|
38
|
+
private parseEncodedContext;
|
|
39
|
+
/**
|
|
40
|
+
* Merge parsed context values into the RequestContext.
|
|
41
|
+
*/
|
|
42
|
+
private mergeContext;
|
|
43
|
+
/**
|
|
44
|
+
* Setup abort handling for client disconnection.
|
|
45
|
+
*/
|
|
46
|
+
private setupAbortHandling;
|
|
47
|
+
/**
|
|
48
|
+
* Manually trigger abort (e.g., during shutdown).
|
|
49
|
+
*/
|
|
50
|
+
abort(): void;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=request-context.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-context.service.d.ts","sourceRoot":"","sources":["../../src/services/request-context.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG9D,OAAO,KAAK,EAAE,OAAO,EAAY,MAAM,SAAS,CAAC;AAGjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAE5D;;;GAGG;AACH,qBACa,qBAAqB;IAOb,OAAO,CAAC,QAAQ,CAAC,OAAO;IACjB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAPlD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0C;IACjE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAkB;IAClD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,SAAS,CAAS;gBAGU,OAAO,EAAE,OAAO,EACT,OAAO,EAAE,mBAAmB;IAOvE;;;OAGG;IACH,IAAI,WAAW,IAAI,WAAW,CAE7B;IAED;;OAEG;IACH,IAAI,cAAc,IAAI,cAAc,CAEnC;IAED;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;IAI5B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAiC3B;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAkB3B;;OAEG;IACH,OAAO,CAAC,YAAY;IAMpB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAmB1B;;OAEG;IACH,KAAK,IAAI,IAAI;CAUd"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { Mastra } from '@mastra/core/mastra';
|
|
2
|
+
import type { RequestContext } from '@mastra/core/request-context';
|
|
3
|
+
import type { ServerRoute } from '@mastra/server/server-adapter';
|
|
4
|
+
import { ZodError } from 'zod';
|
|
5
|
+
import type { MastraModuleOptions } from '../mastra.module.js';
|
|
6
|
+
export interface RouteMatch {
|
|
7
|
+
route: ServerRoute;
|
|
8
|
+
pathParams: Record<string, string>;
|
|
9
|
+
}
|
|
10
|
+
export interface RouteHandlerParams {
|
|
11
|
+
/** URL path parameters (e.g., { agentId: '123' }) */
|
|
12
|
+
pathParams: Record<string, string>;
|
|
13
|
+
/** Query string parameters */
|
|
14
|
+
queryParams: Record<string, unknown>;
|
|
15
|
+
/** Request body (for POST/PUT/PATCH) */
|
|
16
|
+
body: unknown;
|
|
17
|
+
/** Request context (user, session, etc.) */
|
|
18
|
+
requestContext: RequestContext;
|
|
19
|
+
/** Abort signal for request cancellation */
|
|
20
|
+
abortSignal: AbortSignal;
|
|
21
|
+
}
|
|
22
|
+
export interface RouteHandlerResult {
|
|
23
|
+
/** The result data from the handler */
|
|
24
|
+
data: unknown;
|
|
25
|
+
/** Response type determines how to send the response */
|
|
26
|
+
responseType: 'json' | 'stream' | 'datastream-response' | 'mcp-http' | 'mcp-sse';
|
|
27
|
+
/** Stream format (only for 'stream' responseType) */
|
|
28
|
+
streamFormat?: 'sse' | 'stream';
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Service that bridges NestJS controllers to Mastra route handlers.
|
|
32
|
+
* Handles parameter validation and invokes the appropriate handler.
|
|
33
|
+
*/
|
|
34
|
+
export declare class RouteHandlerService {
|
|
35
|
+
private readonly mastra;
|
|
36
|
+
private readonly options;
|
|
37
|
+
private readonly logger;
|
|
38
|
+
private readonly routeMap;
|
|
39
|
+
private readonly reservedParamKeys;
|
|
40
|
+
constructor(mastra: Mastra, options: MastraModuleOptions);
|
|
41
|
+
/**
|
|
42
|
+
* Find a route by exact method and path pattern.
|
|
43
|
+
* Use matchRoute() for parameterized path matching.
|
|
44
|
+
*/
|
|
45
|
+
findRoute(method: string, path: string): ServerRoute | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Match a request method and path against registered routes.
|
|
48
|
+
* Handles both exact matches and parameterized path patterns.
|
|
49
|
+
*
|
|
50
|
+
* @param method - HTTP method (GET, POST, etc.)
|
|
51
|
+
* @param path - Request path to match
|
|
52
|
+
* @returns Route match with path parameters, or null if no match
|
|
53
|
+
*/
|
|
54
|
+
matchRoute(method: string, path: string): RouteMatch | null;
|
|
55
|
+
/**
|
|
56
|
+
* Get all routes (for dynamic controller generation).
|
|
57
|
+
*/
|
|
58
|
+
getAllRoutes(): readonly ServerRoute[];
|
|
59
|
+
/**
|
|
60
|
+
* Match a path against a route pattern.
|
|
61
|
+
* Returns path parameters if matched, null otherwise.
|
|
62
|
+
*/
|
|
63
|
+
private matchPath;
|
|
64
|
+
/**
|
|
65
|
+
* Execute a route handler with the given parameters.
|
|
66
|
+
*/
|
|
67
|
+
executeHandler(route: ServerRoute, params: RouteHandlerParams): Promise<RouteHandlerResult>;
|
|
68
|
+
private getRouteKey;
|
|
69
|
+
private omitReservedKeys;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Error class for validation failures with Zod error details.
|
|
73
|
+
*/
|
|
74
|
+
export declare class ValidationError extends Error {
|
|
75
|
+
readonly zodError: ZodError;
|
|
76
|
+
constructor(message: string, zodError: ZodError);
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=route-handler.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-handler.service.d.ts","sourceRoot":"","sources":["../../src/services/route-handler.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,E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AE,MAAM,GAAG,WAAW,GAAG,SAAS;IAKhE;;;;;;;OAOG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI;IA4B3D;;OAEG;IACH,YAAY,IAAI,SAAS,WAAW,EAAE;IAItC;;;OAGG;IACH,OAAO,CAAC,SAAS;IAsCjB;;OAEG;IACG,cAAc,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAiEjG,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,gBAAgB;CAgBzB;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,KAAK;aAGtB,QAAQ,EAAE,QAAQ;gBADlC,OAAO,EAAE,MAAM,EACC,QAAQ,EAAE,QAAQ;CAKrC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { OnApplicationShutdown, OnModuleDestroy } from '@nestjs/common';
|
|
2
|
+
import type { Response } from 'express';
|
|
3
|
+
import type { MastraModuleOptions } from '../mastra.module.js';
|
|
4
|
+
/**
|
|
5
|
+
* Service that manages graceful shutdown.
|
|
6
|
+
* Tracks in-flight requests and waits for them to complete before shutdown.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ShutdownService implements OnModuleDestroy, OnApplicationShutdown {
|
|
9
|
+
private readonly options;
|
|
10
|
+
private readonly logger;
|
|
11
|
+
private readonly activeRequests;
|
|
12
|
+
private readonly sseClients;
|
|
13
|
+
private isShuttingDown;
|
|
14
|
+
private shutdownResolve;
|
|
15
|
+
constructor(options: MastraModuleOptions);
|
|
16
|
+
/**
|
|
17
|
+
* Check if the service is shutting down.
|
|
18
|
+
* Use this to reject new requests during shutdown.
|
|
19
|
+
*/
|
|
20
|
+
get shuttingDown(): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Get the number of active requests.
|
|
23
|
+
*/
|
|
24
|
+
get activeRequestCount(): number;
|
|
25
|
+
/**
|
|
26
|
+
* Register a new request.
|
|
27
|
+
* Returns a unique request ID for tracking.
|
|
28
|
+
*/
|
|
29
|
+
registerRequest(path: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Mark a request as complete.
|
|
32
|
+
*/
|
|
33
|
+
completeRequest(requestId: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Register an SSE client for shutdown notifications.
|
|
36
|
+
* Returns an unregister function.
|
|
37
|
+
*/
|
|
38
|
+
registerSseClient(response: Response): () => void;
|
|
39
|
+
/**
|
|
40
|
+
* Notify all connected SSE clients about shutdown.
|
|
41
|
+
*/
|
|
42
|
+
notifySseClients(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Called when the module is being destroyed.
|
|
45
|
+
* Marks the service as shutting down.
|
|
46
|
+
*/
|
|
47
|
+
onModuleDestroy(): void;
|
|
48
|
+
/**
|
|
49
|
+
* Called when the application is shutting down.
|
|
50
|
+
* Waits for in-flight requests to complete.
|
|
51
|
+
*/
|
|
52
|
+
onApplicationShutdown(signal?: string): Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=shutdown.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shutdown.service.d.ts","sourceRoot":"","sources":["../../src/services/shutdown.service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGxC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAE5D;;;GAGG;AACH,qBACa,eAAgB,YAAW,eAAe,EAAE,qBAAqB;IAOxC,OAAO,CAAC,QAAQ,CAAC,OAAO;IAN5D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoC;IAC3D,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA0D;IACzF,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAuB;IAClD,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,eAAe,CAA6B;gBAEC,OAAO,EAAE,mBAAmB;IAEjF;;;OAGG;IACH,IAAI,YAAY,IAAI,OAAO,CAE1B;IAED;;OAEG;IACH,IAAI,kBAAkB,IAAI,MAAM,CAE/B;IAED;;;OAGG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IASrC;;OAEG;IACH,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IASxC;;;OAGG;IACH,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,IAAI;IASjD;;OAEG;IACH,gBAAgB,IAAI,IAAI;IAkBxB;;;OAGG;IACH,eAAe,IAAI,IAAI;IAKvB;;;OAGG;IACG,qBAAqB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAoD5D"}
|