Merge branch 'main' into add-authentik-sso

This commit is contained in:
egelhaus 2025-04-15 17:09:19 +02:00 committed by GitHub
commit 9d1c762327
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 21 deletions

View File

@ -1,21 +1,28 @@
import { Injectable } from '@nestjs/common';
import { McpTool } from '@gitroom/nestjs-libraries/mcp/mcp.tool';
import { IntegrationService } from '@gitroom/nestjs-libraries/database/prisma/integrations/integration.service';
import { string, array, enum as eenum, object } from 'zod';
import { string, array, enum as eenum, object, boolean } from 'zod';
import { PostsService } from '@gitroom/nestjs-libraries/database/prisma/posts/posts.service';
import { makeId } from '@gitroom/nestjs-libraries/services/make.is';
import dayjs from 'dayjs';
import { OpenaiService } from '@gitroom/nestjs-libraries/openai/openai.service';
@Injectable()
export class MainMcp {
constructor(
private _integrationService: IntegrationService,
private _postsService: PostsService
private _postsService: PostsService,
private _openAiService: OpenaiService
) {}
@McpTool({ toolName: 'POSTIZ_CONFIGURATION_PRERUN' })
@McpTool({ toolName: 'POSTIZ_GET_CONFIG_ID' })
async preRun() {
return [{type: 'text', text: `Today date is ${dayjs.utc().format()}`}];
return [
{
type: 'text',
text: `id: ${makeId(10)} Today date is ${dayjs.utc().format()}`,
},
];
}
@McpTool({ toolName: 'POSTIZ_PROVIDERS_LIST' })
@ -44,6 +51,8 @@ export class MainMcp {
toolName: 'POSTIZ_SCHEDULE_POST',
zod: {
type: eenum(['draft', 'scheduled']),
configId: string(),
generatePictures: boolean(),
date: string().describe('UTC TIME'),
providerId: string().describe('Use POSTIZ_PROVIDERS_LIST to get the id'),
posts: array(object({ text: string(), images: array(string()) })),
@ -53,9 +62,10 @@ export class MainMcp {
organization: string,
obj: {
type: 'draft' | 'schedule';
generatePictures: boolean;
date: string;
providerId: string;
posts: { text: string; images: string[] }[];
posts: { text: string }[];
}
) {
const create = await this._postsService.createPost(organization, {
@ -65,14 +75,23 @@ export class MainMcp {
posts: [
{
group: makeId(10),
value: obj.posts.map((post) => ({
content: post.text,
id: makeId(10),
image: post.images.map((image) => ({
id: image,
path: image,
})),
})),
value: await Promise.all(
obj.posts.map(async (post) => ({
content: post.text,
id: makeId(10),
image: !obj.generatePictures
? []
: [
{
id: makeId(10),
path: await this._openAiService.generateImage(
post.text,
true
),
},
],
}))
),
// @ts-ignore
settings: {},
integration: {

View File

@ -3,7 +3,6 @@ import { MainMcp } from '@gitroom/backend/mcp/main.mcp';
import { socialIntegrationList } from '@gitroom/nestjs-libraries/integrations/integration.manager';
export class McpSettings {
static singleton: McpSettings;
private _server: McpServer;
createServer(organization: string, service: MainMcp) {
this._server = new McpServer(
@ -69,12 +68,6 @@ export class McpSettings {
}
static load(organization: string, service: MainMcp): McpSettings {
if (!McpSettings.singleton) {
McpSettings.singleton = new McpSettings().createServer(
organization,
service
);
}
return McpSettings.singleton;
return new McpSettings().createServer(organization, service);
}
}