mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-19 16:37:42 +02:00
♻️ refactor: consolidate SessionService & TranscriptionService in @manacore/bot-services
Created shared services to eliminate code duplication across Matrix bots: **New Services in @manacore/bot-services:** - SessionService: User authentication via mana-core-auth (was duplicated in 11 bots) - TranscriptionService: Speech-to-text via mana-stt (was duplicated in 6 bots) **Migrated Bots:** - matrix-todo-bot: uses TranscriptionService - matrix-picture-bot: uses SessionService - matrix-clock-bot: uses TranscriptionService - matrix-zitare-bot: uses both SessionService & TranscriptionService **Code Reduction:** - Removed ~300 lines of duplicate code from migrated bots - Centralized service configuration via NestJS modules - Added comprehensive documentation in CLAUDE.md Remaining bots can be migrated following the same pattern documented in packages/bot-services/CLAUDE.md. Note: @storage/backend type-check fails due to pre-existing drizzle-orm issue Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
508ae124a9
commit
9b61831cb5
35 changed files with 1014 additions and 903 deletions
62
packages/bot-services/src/session/session.module.ts
Normal file
62
packages/bot-services/src/session/session.module.ts
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import { Module, DynamicModule, Global } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { SessionService } from './session.service';
|
||||
import { SessionModuleOptions, SESSION_MODULE_OPTIONS } from './types';
|
||||
|
||||
/**
|
||||
* Shared session management module for Matrix bots
|
||||
*
|
||||
* Provides SessionService for managing user authentication sessions.
|
||||
* Links Matrix user IDs to mana-core-auth JWT tokens.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* // With explicit configuration
|
||||
* @Module({
|
||||
* imports: [
|
||||
* SessionModule.register({
|
||||
* authUrl: 'http://mana-core-auth:3001',
|
||||
* sessionExpiryMs: 7 * 24 * 60 * 60 * 1000 // 7 days
|
||||
* })
|
||||
* ]
|
||||
* })
|
||||
*
|
||||
* // With ConfigService (reads from auth.url or MANA_CORE_AUTH_URL)
|
||||
* @Module({
|
||||
* imports: [SessionModule.forRoot()]
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
@Global()
|
||||
@Module({})
|
||||
export class SessionModule {
|
||||
/**
|
||||
* Register module with explicit options
|
||||
*/
|
||||
static register(options: SessionModuleOptions = {}): DynamicModule {
|
||||
return {
|
||||
module: SessionModule,
|
||||
imports: [ConfigModule],
|
||||
providers: [
|
||||
{
|
||||
provide: SESSION_MODULE_OPTIONS,
|
||||
useValue: options,
|
||||
},
|
||||
SessionService,
|
||||
],
|
||||
exports: [SessionService],
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Register module with ConfigService (reads auth.url or MANA_CORE_AUTH_URL from config)
|
||||
*/
|
||||
static forRoot(): DynamicModule {
|
||||
return {
|
||||
module: SessionModule,
|
||||
imports: [ConfigModule],
|
||||
providers: [SessionService],
|
||||
exports: [SessionService],
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue