feat(gateway): Discord channel auto-creation on project bootstrap (#200)
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
Co-authored-by: Jason Woltje <jason@diversecanvas.com> Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #200.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||
import type { Brain } from '@mosaic/brain';
|
||||
import { BRAIN } from '../brain/brain.tokens.js';
|
||||
import { PluginService } from '../plugin/plugin.service.js';
|
||||
import { WorkspaceService } from './workspace.service.js';
|
||||
|
||||
export interface BootstrapProjectParams {
|
||||
@@ -23,6 +24,7 @@ export class ProjectBootstrapService {
|
||||
constructor(
|
||||
@Inject(BRAIN) private readonly brain: Brain,
|
||||
private readonly workspace: WorkspaceService,
|
||||
private readonly pluginService: PluginService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -67,6 +69,28 @@ export class ProjectBootstrapService {
|
||||
status: 'active',
|
||||
});
|
||||
|
||||
// 4. Notify plugins so they can set up project-specific resources (e.g. Discord channel)
|
||||
try {
|
||||
for (const plugin of this.pluginService.getPlugins()) {
|
||||
if (plugin.onProjectCreated) {
|
||||
const result = await plugin.onProjectCreated({
|
||||
id: project.id,
|
||||
name: params.name,
|
||||
description: params.description,
|
||||
});
|
||||
if (result?.channelId) {
|
||||
await this.brain.projects.update(project.id, {
|
||||
metadata: { discordChannelId: result.channelId },
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
this.logger.warn(
|
||||
`Plugin project notification failed: ${err instanceof Error ? err.message : String(err)}`,
|
||||
);
|
||||
}
|
||||
|
||||
this.logger.log(`Project ${project.id} bootstrapped at ${workspacePath}`);
|
||||
|
||||
return { projectId: project.id, workspacePath };
|
||||
|
||||
Reference in New Issue
Block a user