@nest-boot/mastra 0.0.0-stage → 8.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/LICENSE +21 -0
- package/README.md +60 -2
- package/dist/base.agent.d.ts +11 -0
- package/dist/base.agent.js +15 -0
- package/dist/base.agent.js.map +1 -0
- package/dist/base.step.d.ts +42 -0
- package/dist/base.step.js +62 -0
- package/dist/base.step.js.map +1 -0
- package/dist/base.tool.d.ts +61 -0
- package/dist/base.tool.js +52 -0
- package/dist/base.tool.js.map +1 -0
- package/dist/base.workflow.d.ts +47 -0
- package/dist/base.workflow.js +96 -0
- package/dist/base.workflow.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/mastra-studio.middleware.d.ts +40 -0
- package/dist/mastra-studio.middleware.js +230 -0
- package/dist/mastra-studio.middleware.js.map +1 -0
- package/dist/mastra.controller.d.ts +30 -0
- package/dist/mastra.controller.js +209 -0
- package/dist/mastra.controller.js.map +1 -0
- package/dist/mastra.manager.d.ts +51 -0
- package/dist/mastra.manager.js +159 -0
- package/dist/mastra.manager.js.map +1 -0
- package/dist/mastra.module-definition.d.ts +90 -0
- package/dist/mastra.module-definition.js +75 -0
- package/dist/mastra.module-definition.js.map +1 -0
- package/dist/mastra.module.d.ts +44 -0
- package/dist/mastra.module.js +351 -0
- package/dist/mastra.module.js.map +1 -0
- package/package.json +103 -3
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var MastraManager_1;
|
|
11
|
+
import { Agent as MastraAgent } from "@mastra/core/agent";
|
|
12
|
+
import { Mastra } from "@mastra/core/mastra";
|
|
13
|
+
import { Workflow as MastraWorkflow, } from "@mastra/core/workflows";
|
|
14
|
+
import { Injectable, Logger, } from "@nestjs/common";
|
|
15
|
+
import { DiscoveryService } from "@nestjs/core";
|
|
16
|
+
/**
|
|
17
|
+
* Discovers singleton NestJS providers extending Mastra `Agent` (including `BaseAgent`)
|
|
18
|
+
* and Mastra `Workflow` (including `BaseWorkflow`) across all loaded modules and
|
|
19
|
+
* registers them into the shared `Mastra` instance.
|
|
20
|
+
*/
|
|
21
|
+
let MastraManager = MastraManager_1 = class MastraManager {
|
|
22
|
+
discovery;
|
|
23
|
+
mastra;
|
|
24
|
+
logger = new Logger(MastraManager_1.name);
|
|
25
|
+
agents = new Map();
|
|
26
|
+
workflows = new Map();
|
|
27
|
+
initialized = false;
|
|
28
|
+
shutDown = false;
|
|
29
|
+
constructor(discovery, mastra) {
|
|
30
|
+
this.discovery = discovery;
|
|
31
|
+
this.mastra = mastra;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Scans NestJS providers and registers all discovered singleton Mastra agents and workflows.
|
|
35
|
+
*/
|
|
36
|
+
onModuleInit() {
|
|
37
|
+
if (this.initialized) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
for (const agent of Object.values(this.mastra.listAgents())) {
|
|
41
|
+
if (agent instanceof MastraAgent) {
|
|
42
|
+
this.agents.set(agent.id, agent);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
for (const workflow of Object.values(this.mastra.listWorkflows())) {
|
|
46
|
+
if (workflow instanceof MastraWorkflow) {
|
|
47
|
+
this.workflows.set(workflow.id, workflow);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
for (const provider of this.discovery.getProviders()) {
|
|
51
|
+
if (provider.isAlias) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const instance = provider.instance;
|
|
55
|
+
const target = !provider.metatype || provider.inject
|
|
56
|
+
? (instance?.constructor ??
|
|
57
|
+
(typeof provider.token === "function" ? provider.token : undefined))
|
|
58
|
+
: provider.metatype;
|
|
59
|
+
if (!target) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const isAgent = instance instanceof MastraAgent ||
|
|
63
|
+
(typeof target === "function" &&
|
|
64
|
+
target.prototype instanceof MastraAgent);
|
|
65
|
+
const isWorkflow = instance instanceof MastraWorkflow ||
|
|
66
|
+
(typeof target === "function" &&
|
|
67
|
+
target.prototype instanceof MastraWorkflow);
|
|
68
|
+
if (!isAgent && !isWorkflow) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (isAgent) {
|
|
72
|
+
if (!provider.isDependencyTreeStatic() ||
|
|
73
|
+
provider.isTransient ||
|
|
74
|
+
!(instance instanceof MastraAgent)) {
|
|
75
|
+
throw new Error(`Agent "${target.name}" must be a singleton Mastra Agent provider.`);
|
|
76
|
+
}
|
|
77
|
+
const previous = this.agents.get(instance.id);
|
|
78
|
+
if (previous) {
|
|
79
|
+
if (previous === instance) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
throw new Error(`Mastra agent "${String(instance.id)}" has multiple providers (${previous.constructor.name} and ${instance.constructor.name}). Use a unique agent id or reuse a single provider.`);
|
|
83
|
+
}
|
|
84
|
+
this.mastra.addAgent(instance);
|
|
85
|
+
this.agents.set(instance.id, instance);
|
|
86
|
+
this.logger.log(`Registered Mastra agent "${String(instance.id)}" (${instance.constructor.name})`);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (!provider.isDependencyTreeStatic() ||
|
|
90
|
+
provider.isTransient ||
|
|
91
|
+
!(instance instanceof MastraWorkflow)) {
|
|
92
|
+
throw new Error(`Workflow "${target.name}" must be a singleton Mastra Workflow provider.`);
|
|
93
|
+
}
|
|
94
|
+
const previous = this.workflows.get(instance.id);
|
|
95
|
+
if (previous) {
|
|
96
|
+
if (previous === instance) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
throw new Error(`Mastra workflow "${String(instance.id)}" has multiple providers (${previous.constructor.name} and ${instance.constructor.name}). Use a unique workflow id or reuse a single provider.`);
|
|
100
|
+
}
|
|
101
|
+
this.mastra.addWorkflow(instance);
|
|
102
|
+
this.workflows.set(instance.id, instance);
|
|
103
|
+
this.logger.log(`Registered Mastra workflow "${String(instance.id)}" (${instance.constructor.name})`);
|
|
104
|
+
}
|
|
105
|
+
this.initialized = true;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Returns all discovered and registered Mastra agents.
|
|
109
|
+
* @returns Array of registered Mastra agent instances
|
|
110
|
+
*/
|
|
111
|
+
getAgents() {
|
|
112
|
+
this.onModuleInit();
|
|
113
|
+
return [...this.agents.values()];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Looks up a registered Mastra agent by its id.
|
|
117
|
+
* @param id - Agent id
|
|
118
|
+
* @returns Matching agent instance or undefined
|
|
119
|
+
*/
|
|
120
|
+
getAgent(id) {
|
|
121
|
+
this.onModuleInit();
|
|
122
|
+
return this.agents.get(id);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Returns all discovered and registered Mastra workflows.
|
|
126
|
+
* @returns Array of registered Mastra workflow instances
|
|
127
|
+
*/
|
|
128
|
+
getWorkflows() {
|
|
129
|
+
this.onModuleInit();
|
|
130
|
+
return [...this.workflows.values()];
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Looks up a registered Mastra workflow by its id.
|
|
134
|
+
* @param id - Workflow id
|
|
135
|
+
* @returns Matching workflow instance or undefined
|
|
136
|
+
*/
|
|
137
|
+
getWorkflow(id) {
|
|
138
|
+
this.onModuleInit();
|
|
139
|
+
return this.workflows.get(id);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Flushes observability exporters and releases underlying storage handles
|
|
143
|
+
* (such as PostgreSQL connection pools) when the Nest application shuts down.
|
|
144
|
+
*/
|
|
145
|
+
async onApplicationShutdown() {
|
|
146
|
+
if (this.shutDown) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
this.shutDown = true;
|
|
150
|
+
await this.mastra.shutdown();
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
MastraManager = MastraManager_1 = __decorate([
|
|
154
|
+
Injectable(),
|
|
155
|
+
__metadata("design:paramtypes", [DiscoveryService,
|
|
156
|
+
Mastra])
|
|
157
|
+
], MastraManager);
|
|
158
|
+
export { MastraManager };
|
|
159
|
+
//# sourceMappingURL=mastra.manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mastra.manager.js","sourceRoot":"","sources":["../src/mastra.manager.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,KAAK,IAAI,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAEL,QAAQ,IAAI,cAAc,GAC3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,UAAU,EACV,MAAM,GAGP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD;;;;GAIG;AAEI,IAAM,aAAa,qBAAnB,MAAM,aAAa;IAQL;IACA;IARF,MAAM,GAAG,IAAI,MAAM,CAAC,eAAa,CAAC,IAAI,CAAC,CAAC;IACxC,MAAM,GAAG,IAAI,GAAG,EAAuB,CAAC;IACxC,SAAS,GAAG,IAAI,GAAG,EA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AAC,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACH,QAAQ,CAAC,EAAU;QACjB,IAAI,CAAC,YAAY,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACH,YAAY;QACV,IAAI,CAAC,YAAY,EAAE,CAAC;QACpB,OAAO,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;IACtC,CAAC;IAED;;;;OAIG;IACH,WAAW,CAAC,EAAU;QACpB,IAAI,CAAC,YAAY,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,qBAAqB;QACzB,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;IAC/B,CAAC;CACF,CAAA;AA5KY,aAAa;IADzB,UAAU,EAAE;qCASmB,gBAAgB;QACnB,MAAM;GATtB,aAAa,CA4KzB"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { Config as MastraConfig } from "@mastra/core/mastra";
|
|
2
|
+
import type { MastraModuleOptions as MastraCoreModuleOptions } from "@mastra/nestjs";
|
|
3
|
+
export declare const DEFAULT_MASTRA_API_PREFIX = "/api/mastra";
|
|
4
|
+
export type MastraServerModuleOptions = Omit<MastraCoreModuleOptions, "mastra" | "tools" | "auth" | "customRouteAuthConfig"> & {
|
|
5
|
+
/** Authentication belongs to NestJS guards and `@nest-boot/auth`. */
|
|
6
|
+
auth?: never;
|
|
7
|
+
/** Custom routes belong to NestJS controllers. */
|
|
8
|
+
customRouteAuthConfig?: never;
|
|
9
|
+
};
|
|
10
|
+
export interface MastraApiOptions extends MastraServerModuleOptions {
|
|
11
|
+
/** Whether to register the Mastra HTTP API controller and middleware (default: `true`). */
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface MastraStudioOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Whether to mount Mastra Studio at `${prefix}/studio`.
|
|
17
|
+
* Defaults to `true` when `api` is enabled, and `false` when `api` is disabled.
|
|
18
|
+
*/
|
|
19
|
+
enabled?: boolean;
|
|
20
|
+
/** Whether to hide Mastra Cloud CTA links in Studio (default: `true`). */
|
|
21
|
+
hideCloudCta?: boolean;
|
|
22
|
+
/** Whether to disable Studio telemetry (default: `true`). */
|
|
23
|
+
telemetryDisabled?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export type MastraModuleOptions = Omit<MastraConfig, "server" | "studio"> & {
|
|
26
|
+
/** HTTP server configuration belongs to NestJS; supplying `server` is rejected at startup. */
|
|
27
|
+
server?: never;
|
|
28
|
+
/**
|
|
29
|
+
* Configure the Mastra HTTP API routes and server options.
|
|
30
|
+
* - `true` / omitted: enabled under `/api/mastra`
|
|
31
|
+
* - `false`: disables Mastra HTTP API routes (and Studio by default)
|
|
32
|
+
* - object: customizes `enabled`, `prefix`, and `@mastra/nestjs` server options
|
|
33
|
+
*/
|
|
34
|
+
api?: boolean | MastraApiOptions;
|
|
35
|
+
/**
|
|
36
|
+
* Configure embedded Mastra Studio hosting at `${prefix}/studio`.
|
|
37
|
+
* - `true` / omitted: enabled whenever `api` is enabled
|
|
38
|
+
* - `false`: disables Mastra Studio
|
|
39
|
+
* - object: customizes `enabled`, `hideCloudCta`, and `telemetryDisabled`
|
|
40
|
+
*/
|
|
41
|
+
studio?: boolean | MastraStudioOptions;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Resolves and normalizes the Mastra HTTP API prefix.
|
|
45
|
+
* @param prefix - Optional configured prefix
|
|
46
|
+
* @returns Normalized API prefix (defaults to `/api/mastra`)
|
|
47
|
+
*/
|
|
48
|
+
export declare function resolveMastraApiPrefix(prefix?: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Resolves and normalizes the Mastra Studio base path (`${prefix}/studio`).
|
|
51
|
+
* @param prefix - Optional configured Mastra API prefix
|
|
52
|
+
* @returns Normalized Studio base path (defaults to `/api/mastra/studio`)
|
|
53
|
+
*/
|
|
54
|
+
export declare function resolveMastraStudioBasePath(prefix?: string): string;
|
|
55
|
+
/**
|
|
56
|
+
* Normalizes the `api` option into an enabled flag and `@mastra/nestjs` server options.
|
|
57
|
+
* @param api - Raw `api` module option
|
|
58
|
+
* @returns Normalized API enabled flag and server options with normalized prefix
|
|
59
|
+
*/
|
|
60
|
+
export declare function normalizeMastraApiOptions(api?: MastraModuleOptions["api"]): {
|
|
61
|
+
enabled: boolean;
|
|
62
|
+
serverOptions: MastraServerModuleOptions & {
|
|
63
|
+
prefix: string;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Normalizes the `studio` option into concrete boolean flags.
|
|
68
|
+
* @param studio - Raw `studio` module option
|
|
69
|
+
* @param apiEnabled - Whether Mastra HTTP API routes are enabled (default: `true`)
|
|
70
|
+
* @returns Normalized Studio options
|
|
71
|
+
*/
|
|
72
|
+
export declare function normalizeMastraStudioOptions(studio?: MastraModuleOptions["studio"], apiEnabled?: boolean): Required<MastraStudioOptions>;
|
|
73
|
+
export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<MastraModuleOptions, "forRoot", "create", {}>, MASTRA_MODULE_OPTIONS: string | symbol, OPTIONS_TYPE: Omit<MastraConfig<Record<string, import("@mastra/core/agent").Agent<any, import("@mastra/core/agent").ToolsInput, undefined, any, import("@mastra/core/agent").AgentEditorConfig | undefined>>, Record<string, import("@mastra/core/workflows").AnyWorkflow>, Record<string, import("@mastra/core/vector").MastraVector<any>>, Record<string, import("@mastra/core/tts").MastraTTS>, import("@mastra/core/logger").IMastraLogger, Record<string, import("@mastra/core/mcp").MCPServerBase<any>>, Record<string, import("@mastra/core/evals").MastraScorer<any, any, any, any>>, Record<string, import("@mastra/core/tools").ToolAction<any, any, any, any, any, any, unknown>>, Record<string, import("@mastra/core/processors").Processor<any, unknown>>, Record<string, import("@mastra/core/memory").MastraMemory>, Record<string, import("@mastra/core/channels").ChannelProvider>, Record<string, import("@mastra/core/classifier").Classifier<any>>, Record<string, import("@mastra/core/knowledge").Knowledge>>, "server" | "studio"> & {
|
|
74
|
+
/** HTTP server configuration belongs to NestJS; supplying `server` is rejected at startup. */
|
|
75
|
+
server?: never;
|
|
76
|
+
/**
|
|
77
|
+
* Configure the Mastra HTTP API routes and server options.
|
|
78
|
+
* - `true` / omitted: enabled under `/api/mastra`
|
|
79
|
+
* - `false`: disables Mastra HTTP API routes (and Studio by default)
|
|
80
|
+
* - object: customizes `enabled`, `prefix`, and `@mastra/nestjs` server options
|
|
81
|
+
*/
|
|
82
|
+
api?: boolean | MastraApiOptions;
|
|
83
|
+
/**
|
|
84
|
+
* Configure embedded Mastra Studio hosting at `${prefix}/studio`.
|
|
85
|
+
* - `true` / omitted: enabled whenever `api` is enabled
|
|
86
|
+
* - `false`: disables Mastra Studio
|
|
87
|
+
* - object: customizes `enabled`, `hideCloudCta`, and `telemetryDisabled`
|
|
88
|
+
*/
|
|
89
|
+
studio?: boolean | MastraStudioOptions;
|
|
90
|
+
} & Partial<{}>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<MastraModuleOptions, "create"> & Partial<{}>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { normalizeStudioBase } from "@mastra/deployer/build";
|
|
2
|
+
import { ConfigurableModuleBuilder } from "@nestjs/common";
|
|
3
|
+
export const DEFAULT_MASTRA_API_PREFIX = "/api/mastra";
|
|
4
|
+
/**
|
|
5
|
+
* Resolves and normalizes the Mastra HTTP API prefix.
|
|
6
|
+
* @param prefix - Optional configured prefix
|
|
7
|
+
* @returns Normalized API prefix (defaults to `/api/mastra`)
|
|
8
|
+
*/
|
|
9
|
+
export function resolveMastraApiPrefix(prefix) {
|
|
10
|
+
return normalizeStudioBase(prefix ?? DEFAULT_MASTRA_API_PREFIX) || "/api";
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Resolves and normalizes the Mastra Studio base path (`${prefix}/studio`).
|
|
14
|
+
* @param prefix - Optional configured Mastra API prefix
|
|
15
|
+
* @returns Normalized Studio base path (defaults to `/api/mastra/studio`)
|
|
16
|
+
*/
|
|
17
|
+
export function resolveMastraStudioBasePath(prefix) {
|
|
18
|
+
return normalizeStudioBase(`${resolveMastraApiPrefix(prefix)}/studio`);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Normalizes the `api` option into an enabled flag and `@mastra/nestjs` server options.
|
|
22
|
+
* @param api - Raw `api` module option
|
|
23
|
+
* @returns Normalized API enabled flag and server options with normalized prefix
|
|
24
|
+
*/
|
|
25
|
+
export function normalizeMastraApiOptions(api) {
|
|
26
|
+
if (api === false) {
|
|
27
|
+
return {
|
|
28
|
+
enabled: false,
|
|
29
|
+
serverOptions: {
|
|
30
|
+
prefix: DEFAULT_MASTRA_API_PREFIX,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const config = typeof api === "object" ? api : {};
|
|
35
|
+
const { enabled = true, prefix, ...rest } = config;
|
|
36
|
+
return {
|
|
37
|
+
enabled,
|
|
38
|
+
serverOptions: {
|
|
39
|
+
...rest,
|
|
40
|
+
prefix: resolveMastraApiPrefix(prefix),
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Normalizes the `studio` option into concrete boolean flags.
|
|
46
|
+
* @param studio - Raw `studio` module option
|
|
47
|
+
* @param apiEnabled - Whether Mastra HTTP API routes are enabled (default: `true`)
|
|
48
|
+
* @returns Normalized Studio options
|
|
49
|
+
*/
|
|
50
|
+
export function normalizeMastraStudioOptions(studio, apiEnabled = true) {
|
|
51
|
+
if (studio === false) {
|
|
52
|
+
return {
|
|
53
|
+
enabled: false,
|
|
54
|
+
hideCloudCta: true,
|
|
55
|
+
telemetryDisabled: true,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (studio === true) {
|
|
59
|
+
return {
|
|
60
|
+
enabled: true,
|
|
61
|
+
hideCloudCta: true,
|
|
62
|
+
telemetryDisabled: true,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const config = typeof studio === "object" ? studio : {};
|
|
66
|
+
return {
|
|
67
|
+
enabled: config.enabled ?? apiEnabled,
|
|
68
|
+
hideCloudCta: config.hideCloudCta ?? true,
|
|
69
|
+
telemetryDisabled: config.telemetryDisabled ?? true,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN: MASTRA_MODULE_OPTIONS, OPTIONS_TYPE, ASYNC_OPTIONS_TYPE, } = new ConfigurableModuleBuilder()
|
|
73
|
+
.setClassMethodName("forRoot")
|
|
74
|
+
.build();
|
|
75
|
+
//# sourceMappingURL=mastra.module-definition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mastra.module-definition.js","sourceRoot":"","sources":["../src/mastra.module-definition.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAE3D,MAAM,CAAC,MAAM,yBAAyB,GAAG,aAAa,CAAC;AAgDvD;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAe;IACpD,OAAO,mBAAmB,CAAC,MAAM,IAAI,yBAAyB,CAAC,IAAI,MAAM,CAAC;AAC5E,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,2BAA2B,CAAC,MAAe;IACzD,OAAO,mBAAmB,CAAC,GAAG,sBAAsB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AACzE,CAAC;AAED;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AAoB,EAAE,qBAAqB,EAC3C,YAAY,EACZ,kBAAkB,GACnB,GAAG,IAAI,yBAAyB,EAAuB;KACrD,kBAAkB,CAAC,SAAS,CAAC;KAC7B,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type DynamicModule, type MiddlewareConsumer, type NestModule } from "@nestjs/common";
|
|
2
|
+
import { type ASYNC_OPTIONS_TYPE, ConfigurableModuleClass, type MastraModuleOptions, type OPTIONS_TYPE } from "./mastra.module-definition.js";
|
|
3
|
+
export type MastraModuleAsyncOptions = typeof ASYNC_OPTIONS_TYPE & {
|
|
4
|
+
/**
|
|
5
|
+
* Set to `false` to skip registering `MastraController` statically when using
|
|
6
|
+
* `forRootAsync`.
|
|
7
|
+
*/
|
|
8
|
+
api?: boolean;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Global NestJS-native Mastra module.
|
|
12
|
+
*
|
|
13
|
+
* Reuses `@mastra/nestjs` services, interceptors, and filters with a local
|
|
14
|
+
* `MastraController` mounted at `api.prefix` (defaulting to `/api/mastra`),
|
|
15
|
+
* serves bundled Mastra Studio via middleware at `${prefix}/studio`, shares a
|
|
16
|
+
* single `Mastra` instance, and automatically discovers all singleton
|
|
17
|
+
* `BaseAgent` (and Mastra `Agent`) and `BaseWorkflow` (and Mastra `Workflow`)
|
|
18
|
+
* providers.
|
|
19
|
+
*/
|
|
20
|
+
export declare class MastraModule extends ConfigurableModuleClass implements NestModule {
|
|
21
|
+
private readonly options;
|
|
22
|
+
constructor(options: MastraModuleOptions);
|
|
23
|
+
/**
|
|
24
|
+
* Configures `MastraModule` synchronously. Skips registering `MastraController`
|
|
25
|
+
* when `options.api` is disabled (`false` or `{ enabled: false }`).
|
|
26
|
+
* @param options - Synchronous Mastra module options
|
|
27
|
+
* @returns Configured dynamic module
|
|
28
|
+
*/
|
|
29
|
+
static forRoot(options: typeof OPTIONS_TYPE): DynamicModule;
|
|
30
|
+
/**
|
|
31
|
+
* Configures `MastraModule` asynchronously. Pass `api: false` on the async
|
|
32
|
+
* options object to skip registering `MastraController` statically, or return
|
|
33
|
+
* `{ api: false }` from the factory to disable API handling at runtime.
|
|
34
|
+
* @param options - Asynchronous Mastra module options
|
|
35
|
+
* @returns Configured dynamic module
|
|
36
|
+
*/
|
|
37
|
+
static forRootAsync(options: MastraModuleAsyncOptions): DynamicModule;
|
|
38
|
+
/**
|
|
39
|
+
* Mounts Mastra Studio middleware at `${prefix}/studio` and Mastra JSON/body-limit
|
|
40
|
+
* middleware scoped to `MastraController`.
|
|
41
|
+
* @param consumer - NestJS middleware consumer
|
|
42
|
+
*/
|
|
43
|
+
configure(consumer: MiddlewareConsumer): void;
|
|
44
|
+
}
|