π¨ The ultimate agentic social media scheduling tool π€
TypeScript nextjsopen-sourceopen-source-social-media-scheduling-toolosspostiz-cloudpostiz-hostedredisscheduling-toolsocial-media-scheduling-tooltypescript
feat(agent): add postSettingsTool to update a post's settings via the agent
Gilad Resisif5d30a2b3303
diff --git a/libraries/nestjs-libraries/src/chat/load.tools.service.ts b/libraries/nestjs-libraries/src/chat/load.tools.service.tsindex b4e098f46..a0194b624 100644--- a/libraries/nestjs-libraries/src/chat/load.tools.service.ts+++ b/libraries/nestjs-libraries/src/chat/load.tools.service.ts@@ -55,6 +55,7 @@ export class LoadToolsService {You are an agent that helps manage and schedule social media posts for users, you can:- Schedule posts into the future, or now, adding texts, images and videos- List the posts scheduled between two dates (postsListTool)+ - Update the settings of a scheduled post or draft that was not published yet (postSettingsTool)- Generate pictures for posts- Generate videos for posts- Generate text for posts@@ -78,6 +79,9 @@ export class LoadToolsService {- Make sure you always take the last information I give you about the socials, it might have changed.- Before scheduling a post, always make sure you ask the user confirmation by providing all the details of the post (text, images, videos, date, time, social media platform, account).- To find or inspect existing posts, use postsListTool with a UTC start and end date - it returns every post scheduled in that window. To cover "all my upcoming posts", pass a wide window starting now.+ - To change the provider settings of an existing post that was not published yet (scheduled or draft), first find it with postsListTool, then use postSettingsTool with the post's id. It only updates the settings - the content and the publish date stay as they are - and only the keys you pass are changed (get them with the integrationSchema tool). Show the user which post and which settings will change and get their confirmation first.+ - Never open the "modal with populated content" to edit an existing post - that modal only CREATES a new post, so using it to edit would duplicate the post. It is only for brand new posts.+ - You can create, schedule and update posts, but you CANNOT delete posts - there is no delete capability. Never offer to delete a post. If the user asks you to delete one, tell them deletion is a destructive action and they should delete it themselves in the Postiz app (the calendar).- Between tools, we will reference things like: [output:name] and [input:name] to set the information right.- When outputting a date for the user, make sure it's human readable with time- The content of the post, HTML, Each line must be wrapped in <p> here is the possible tags: h1, h2, h3, u, strong, li, ul, p (you can\'t have u and strong together), don't use a "code" boxdiff --git a/libraries/nestjs-libraries/src/chat/tools/post.settings.tool.ts b/libraries/nestjs-libraries/src/chat/tools/post.settings.tool.tsnew file mode 100644index 000000000..679d025d7--- /dev/null+++ b/libraries/nestjs-libraries/src/chat/tools/post.settings.tool.ts@@ -0,0 +1,93 @@+import { AgentToolInterface } from '@gitroom/nestjs-libraries/chat/agent.tool.interface';+import { createTool } from '@mastra/core/tools';+import { z } from 'zod';+import { Injectable } from '@nestjs/common';+import { PostsService } from '@gitroom/nestjs-libraries/database/prisma/posts/posts.service';+import { checkAuth } from '@gitroom/nestjs-libraries/chat/auth.context';++@Injectable()+export class PostSettingsTool implements AgentToolInterface {+ constructor(private _postsService: PostsService) {}+ name = 'postSettingsTool';++ run() {+ return createTool({+ id: 'postSettingsTool',+ mcp: {+ annotations: {+ title: 'Update Post Settings',+ readOnlyHint: false,+ destructiveHint: false,+ idempotentHint: false,+ openWorldHint: true,+ },+ },+ description: `+Update the provider settings of an existing post (scheduled or draft) that was NOT published yet.+Only the settings change - the content and the publish date stay exactly as they are.+Find the post first (list your posts) and pass its "id" here.+The settings are merged into the existing ones, so only pass the keys you want to change; anything you don't pass stays as it is.+This relies on the integrationSchema tool [input:settings] to know which keys exist for the platform.+If the tool returns errors, rerun it with the right parameters, don't ask again, just run it.+`,+ inputSchema: z.object({+ id: z+ .string()+ .describe('The "id" of the post to update its settings'),+ settings: z+ .array(+ z.object({+ key: z.string().describe('Name of the settings key to change'),+ value: z+ .any()+ .describe(+ 'New value of the key, always prefer the id then label if possible'+ ),+ })+ )+ .describe(+ 'Settings keys to change, merged into the existing settings. This relies on the integrationSchema tool [input:settings]'+ ),+ }),+ outputSchema: z.object({+ output: z+ .object({+ postId: z.string(),+ publishDate: z.string(),+ })+ .or(z.object({ errors: z.string() })),+ }),+ execute: async (inputData, context) => {+ checkAuth(inputData, context);+ const organizationId = JSON.parse(+ (context?.requestContext as any)?.get('organization') as string+ ).id;++ const settings = (inputData.settings || []).reduce(+ (acc: Record<string, any>, s: { key: string; value: any }) => ({+ ...acc,+ [s.key]: s.value,+ }),+ {} as Record<string, any>+ );++ try {+ const output = await this._postsService.updatePostSettings(+ organizationId,+ inputData.id,+ settings,+ 'MCP'+ );++ return { output };+ } catch (err: any) {+ return {+ output: {+ errors: err?.message || 'Failed to update the post settings',+ },+ };+ }+ },+ });+ }+}diff --git a/libraries/nestjs-libraries/src/chat/tools/tool.list.ts b/libraries/nestjs-libraries/src/chat/tools/tool.list.tsindex c95a5175b..ef386474f 100644--- a/libraries/nestjs-libraries/src/chat/tools/tool.list.ts+++ b/libraries/nestjs-libraries/src/chat/tools/tool.list.ts@@ -9,6 +9,7 @@ import { IntegrationListTool } from '@gitroom/nestjs-libraries/chat/tools/integrimport { GroupListTool } from '@gitroom/nestjs-libraries/chat/tools/group.list.tool';import { UploadFromUrlTool } from '@gitroom/nestjs-libraries/chat/tools/upload.from.url.tool';import { PostsListTool } from '@gitroom/nestjs-libraries/chat/tools/posts.list.tool';+import { PostSettingsTool } from '@gitroom/nestjs-libraries/chat/tools/post.settings.tool';export const toolList = [IntegrationListTool,@@ -17,6 +18,7 @@ export const toolList = [IntegrationTriggerTool,IntegrationSchedulePostTool,PostsListTool,+ PostSettingsTool,GenerateVideoOptionsTool,VideoFunctionTool,GenerateVideoTool,