feat: change mastra instance to import

This commit is contained in:
Nevo David 2025-10-16 23:14:11 +07:00
parent 26bbded6bd
commit a3a6aa3926
1 changed files with 17 additions and 12 deletions

View File

@ -1,4 +1,4 @@
import { Mastra } from '@mastra/core/mastra';
import { type Mastra } from '@mastra/core/mastra';
import { ConsoleLogger } from '@mastra/core/logger';
import { pStore } from '@gitroom/nestjs-libraries/chat/mastra.store';
import { Injectable } from '@nestjs/common';
@ -9,17 +9,22 @@ export class MastraService {
static mastra: Mastra;
constructor(private _loadToolsService: LoadToolsService) {}
async mastra() {
MastraService.mastra =
MastraService.mastra ||
new Mastra({
storage: pStore,
agents: {
postiz: await this._loadToolsService.agent(),
},
logger: new ConsoleLogger({
level: 'info',
}),
});
if (MastraService.mastra) {
return MastraService.mastra;
}
const MastraInstance = await import('@mastra/core/mastra').then(
(m) => m.Mastra
);
MastraService.mastra = new MastraInstance({
storage: pStore,
agents: {
postiz: await this._loadToolsService.agent(),
},
logger: new ConsoleLogger({
level: 'info',
}),
});
return MastraService.mastra;
}