feat: mcps
This commit is contained in:
parent
026957b96e
commit
4474afde7f
|
|
@ -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: {
|
||||
|
|
|
|||
Loading…
Reference in New Issue