Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

feat: delete tool

Nevo David668c971171e7
diff --git a/apps/backend/src/api/routes/users.controller.ts b/apps/backend/src/api/routes/users.controller.ts
index 3e51f0973..5134344f8 100644
--- a/apps/backend/src/api/routes/users.controller.ts
+++ b/apps/backend/src/api/routes/users.controller.ts
@@ -79,23 +79,6 @@ export class UsersController {
return { token };
}
- @Get('/agent-media-sso')
- async getAgentMediaSsoUrl(
- @GetUserFromRequest() user: User,
- @GetOrgFromRequest() organization: Organization
- ) {
- if (!process.env.AGENT_MEDIA_SSO_KEY) {
- throw new HttpException('Agent Media SSO is not configured', 400);
- }
-
- const token = sign(
- { id: organization.id, displayName: organization.name },
- process.env.AGENT_MEDIA_SSO_KEY
- );
-
- return { url: `https://app.agent-media.ai/sso/${token}` };
- }
-
@Get('/self')
async getSelf(
@GetUserFromRequest() user: User,
diff --git a/apps/frontend/src/components/layout/agent.media.modal.tsx b/apps/frontend/src/components/layout/agent.media.modal.tsx
deleted file mode 100644
index 0ee5fa594..000000000
--- a/apps/frontend/src/components/layout/agent.media.modal.tsx
+++ /dev/null
@@ -1,103 +0,0 @@
-'use client';
-
-import { FC, useCallback, useState } from 'react';
-import { useModals } from '@gitroom/frontend/components/layout/new-modal';
-import { useFetch } from '@gitroom/helpers/utils/custom.fetch';
-import { useT } from '@gitroom/react/translation/get.transation.service.client';
-import { Button } from '@gitroom/react/form/button';
-
-export const AgentMediaModal: FC = () => {
- const fetch = useFetch();
- const t = useT();
- const { closeCurrent } = useModals();
- const [loading, setLoading] = useState(false);
-
- const handleContinue = useCallback(async () => {
- setLoading(true);
- try {
- const response = await fetch('/user/agent-media-sso');
- const data = await response.json();
- if (data.url) {
- window.open(data.url, '_blank');
- }
- closeCurrent();
- } catch (e) {
- // ignore
- } finally {
- setLoading(false);
- }
- }, [fetch, closeCurrent]);
-
- return (
- <div className="flex flex-col gap-[20px] max-w-[520px]">
- <div className="text-[14px] leading-[22px] text-newTextColor opacity-80">
- {t(
- 'agent_media_different_company',
- 'UGC videos are powered by AgentMedia (agent-media.ai), a separate product with its own account and pricing β€” not part of your Postiz subscription.'
- )}
- </div>
-
- <div className="flex flex-col gap-[12px]">
- <div className="text-[14px] font-[600] text-newTextColor">
- {t('agent_media_what_you_get', 'What you get with AgentMedia')}
- </div>
- <ul className="flex flex-col gap-[8px] text-[14px] leading-[20px] text-newTextColor opacity-80">
- <li className="flex gap-[8px]">
- <span className="text-forth">β€’</span>
- <span>
- {t(
- 'agent_media_feature_videos',
- 'AI-generated UGC videos with captions written and baked in automatically'
- )}
- </span>
- </li>
- <li className="flex gap-[8px]">
- <span className="text-forth">β€’</span>
- <span>
- {t(
- 'agent_media_feature_quality',
- 'Studio-quality 9:16 vertical video at 1080p'
- )}
- </span>
- </li>
- <li className="flex gap-[8px]">
- <span className="text-forth">β€’</span>
- <span>
- {t(
- 'agent_media_feature_publish',
- 'Auto-publishing to TikTok, Instagram, YouTube and X'
- )}
- </span>
- </li>
- </ul>
- </div>
-
- <div className="flex flex-col gap-[12px]">
- <div className="text-[14px] font-[600] text-newTextColor">
- {t('agent_media_pricing', 'Separate pricing')}
- </div>
- <div className="flex flex-col gap-[6px] text-[14px] leading-[20px] text-newTextColor opacity-80">
- <div>
- {t('agent_media_plan_creator', 'Creator β€” $39/mo Β· 3,900 credits')}
- </div>
- <div>{t('agent_media_plan_pro', 'Pro β€” $69/mo Β· 6,900 credits')}</div>
- <div>
- {t(
- 'agent_media_plan_pro_plus',
- 'Pro Plus β€” $129/mo Β· 12,900 credits + early access'
- )}
- </div>
- </div>
- </div>
-
- <div className="flex gap-[12px] mt-[8px]">
- <Button loading={loading} onClick={handleContinue}>
- {t('agent_media_continue', 'Continue to AgentMedia')}
- </Button>
- <Button secondary={true} onClick={closeCurrent}>
- {t('cancel', 'Cancel')}
- </Button>
- </div>
- </div>
- );
-};
diff --git a/apps/frontend/src/components/layout/top.menu.tsx b/apps/frontend/src/components/layout/top.menu.tsx
index ec6a3fc84..27c07e3c3 100644
--- a/apps/frontend/src/components/layout/top.menu.tsx
+++ b/apps/frontend/src/components/layout/top.menu.tsx
@@ -1,12 +1,10 @@
'use client';
-import { FC, ReactNode, useCallback } from 'react';
+import { FC, ReactNode } from 'react';
import { useUser } from '@gitroom/frontend/components/layout/user.context';
import { useVariables } from '@gitroom/react/helpers/variable.context';
import { useT } from '@gitroom/react/translation/get.transation.service.client';
import { MenuItem } from '@gitroom/frontend/components/new-layout/menu-item';
-import { useModals } from '@gitroom/frontend/components/layout/new-modal';
-import { AgentMediaModal } from '@gitroom/frontend/components/layout/agent.media.modal';
interface MenuItemInterface {
name: string;
@@ -21,16 +19,6 @@ interface MenuItemInterface {
export const useMenuItem = () => {
const { isGeneral } = useVariables();
const t = useT();
- const { openModal } = useModals();
-
- const handleAgentMediaClick = useCallback(() => {
- openModal({
- title: t('agent_media_title', 'UGC videos by AgentMedia'),
- closeOnClickOutside: true,
- closeOnEscape: true,
- children: <AgentMediaModal />,
- });
- }, [openModal, t]);
const firstMenu = [
{
@@ -117,107 +105,6 @@ export const useMenuItem = () => {
] satisfies MenuItemInterface[] as MenuItemInterface[];
const secondMenu = [
- {
- name: t('make_ugc', 'Make UGC'),
- icon: (
- <svg
- xmlns="http://www.w3.org/2000/svg"
- width="20"
- height="20"
- viewBox="0 0 27.19 27.19"
- fill="none"
- >
- <g clipPath="url(#agent_media_clip)">
- <rect
- width="27.19"
- height="27.19"
- rx="6.43"
- fill="url(#agent_media_bg)"
- />
- <path
- fillRule="evenodd"
- clipRule="evenodd"
- d="M0 29.23V-2.06L22.12 9.99v7.46z"
- fill="url(#agent_media_play)"
- />
- <mask
- id="agent_media_mask"
- width="23"
- height="36"
- x="0"
- y="-4"
- maskUnits="userSpaceOnUse"
- style={{ maskType: 'alpha' }}
- >
- <path fill="#d9d9d9" d="M0-3.84h22.12v34.87H0z" />
- </mask>
- <g mask="url(#agent_media_mask)">
- <path
- fill="url(#agent_media_line1)"
- d="m42.33-1.9-64.3 37.13 3.48 6.04L45.8 4.14z"
- />
- <path
- fill="url(#agent_media_line2)"
- d="M-18.57-13.72 45.74 23.4l-3.48 6.03L-22.05-7.7z"
- />
- </g>
- </g>
- <defs>
- <radialGradient
- id="agent_media_bg"
- cx="0"
- cy="0"
- r="1"
- gradientTransform="matrix(-38.3537 0 0 -29.9787 38.354 13.597)"
- gradientUnits="userSpaceOnUse"
- >
- <stop />
- <stop offset="1" stopColor="#6112ff" />
- </radialGradient>
- <linearGradient
- id="agent_media_play"
- x1="22.12"
- x2="0"
- y1="13.6"
- y2="13.6"
- gradientUnits="userSpaceOnUse"
- >
- <stop />
- <stop offset="1" stopColor="#2a008d" />
- </linearGradient>
- <linearGradient
- id="agent_media_line1"
- x1="44.5"
- x2="-20.41"
- y1="0.37"
- y2="37.84"
- gradientUnits="userSpaceOnUse"
- >
- <stop offset="0.32" stopColor="#9162ff" />
- <stop offset="0.69" stopColor="#4500e7" />
- </linearGradient>
- <linearGradient
- id="agent_media_line2"
- x1="-20.74"
- x2="44.18"
- y1="-11.46"
- y2="26.02"
- gradientUnits="userSpaceOnUse"
- >
- <stop offset="0.32" stopColor="#9162ff" />
- <stop offset="0.69" stopColor="#4500e7" />
- </linearGradient>
- <clipPath id="agent_media_clip">
- <rect width="27.19" height="27.19" rx="6.43" fill="#fff" />
- </clipPath>
- </defs>
- </svg>
- ),
- path: '#',
- role: ['ADMIN', 'SUPERADMIN', 'USER'],
- requireBilling: true,
- onClick: handleAgentMediaClick,
- },
{
name: t('affiliate', 'Affiliate'),
icon: (
diff --git a/libraries/nestjs-libraries/src/chat/agent.tool.interface.ts b/libraries/nestjs-libraries/src/chat/agent.tool.interface.ts
index 26fabf23b..9c8f46fb5 100644
--- a/libraries/nestjs-libraries/src/chat/agent.tool.interface.ts
+++ b/libraries/nestjs-libraries/src/chat/agent.tool.interface.ts
@@ -8,5 +8,8 @@ export interface AgentToolInterface {
mcpOnly?: boolean;
// a tool of a feature this install has not configured is left out everywhere
available?(): boolean;
+ // a self-hosted instance without it can still connect through the cloud
+ // relay, calling it there asks to update the instance
+ optionalOnSelfHosted?: boolean;
run(): ToolReturn;
}
diff --git a/libraries/nestjs-libraries/src/chat/load.tools.service.ts b/libraries/nestjs-libraries/src/chat/load.tools.service.ts
index a023d05ef..4496aeaf7 100644
--- a/libraries/nestjs-libraries/src/chat/load.tools.service.ts
+++ b/libraries/nestjs-libraries/src/chat/load.tools.service.ts
@@ -46,13 +46,14 @@ export class LoadToolsService {
);
}
- // Tools every install has, whatever features it configured
+ // Tools a self-hosted instance must have to connect through the relay
+ // (every install has them, whatever features it configured)
coreToolNames() {
return toolList
.map(
(p) => this._moduleRef.get(p, { strict: false }) as AgentToolInterface
)
- .filter((p) => !p.mcpOnly && !p.available)
+ .filter((p) => !p.mcpOnly && !p.available && !p.optionalOnSelfHosted)
.map((p) => p.name);
}
@@ -73,6 +74,7 @@ export class LoadToolsService {
- 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)
+ - Delete a post (deletePostTool)
- Generate pictures for posts
- Generate videos for posts
- Generate text for posts
@@ -99,7 +101,7 @@ export class LoadToolsService {
- 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).
+ - To delete a post, first find it with postsListTool, then use deletePostTool with the post's id. It deletes the post on that one channel (with its comments) - when the same post was created for several channels, ask the user which channels to delete it from and call deletePostTool once per post id. A repeating post is listed once per repetition with the same id - deleting it deletes all the repetitions. Deleting a published post only removes it from Postiz, it stays live on the social network. Deletion cannot be undone, so show the user which post will be deleted (channel, date and text), mention the two cases above when they apply, and get their confirmation first.
- 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" box
diff --git a/libraries/nestjs-libraries/src/chat/mcp.relay.service.ts b/libraries/nestjs-libraries/src/chat/mcp.relay.service.ts
index 34a089df2..ec7a922d1 100644
--- a/libraries/nestjs-libraries/src/chat/mcp.relay.service.ts
+++ b/libraries/nestjs-libraries/src/chat/mcp.relay.service.ts
@@ -170,7 +170,8 @@ export class McpRelayService {
// Every tool any install has must run on the instance, an older one
// would answer some calls with errors (tools of optional features, like
- // clipping, depend on the instance setup, not its version)
+ // clipping, depend on the instance setup, not its version, and the
+ // optionalOnSelfHosted ones only ask an older instance to update)
const missing = this._loadToolsService
.coreToolNames()
.filter((name) => !tools.includes(name));
diff --git a/libraries/nestjs-libraries/src/chat/tools/delete.post.tool.ts b/libraries/nestjs-libraries/src/chat/tools/delete.post.tool.ts
new file mode 100644
index 000000000..fc5b5b484
--- /dev/null
+++ b/libraries/nestjs-libraries/src/chat/tools/delete.post.tool.ts
@@ -0,0 +1,78 @@
+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 DeletePostTool implements AgentToolInterface {
+ constructor(private _postsService: PostsService) {}
+ name = 'deletePostTool';
+ optionalOnSelfHosted = true;
+
+ run() {
+ return createTool({
+ id: 'deletePostTool',
+ mcp: {
+ annotations: {
+ title: 'Delete Post',
+ readOnlyHint: false,
+ destructiveHint: true,
+ idempotentHint: true,
+ openWorldHint: false,
+ },
+ },
+ description: `
+Use this when the user wants to delete an existing post (scheduled, draft, published or errored).
+Find the post first (list your posts) and pass its "id" here.
+It deletes the post on that one channel together with its comments - a post created for several channels has a separate id on each channel.
+A repeating post is listed once per repetition with the same id - deleting it deletes every repetition.
+A deleted scheduled post is not published. Deleting a published post only removes it from Postiz - it stays live on the social network.
+The deletion cannot be undone.
+If the post cannot be deleted, the result contains output.errors explaining why.
+`,
+ inputSchema: z.object({
+ id: z.string().describe('The "id" of the post to delete'),
+ }),
+ outputSchema: z.object({
+ output: z
+ .object({
+ postId: 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 [post] = await this._postsService.getPostsRecursively(
+ inputData.id,
+ false,
+ organizationId,
+ true
+ );
+
+ if (!post) {
+ return { output: { errors: 'Post not found' } };
+ }
+
+ // deleting goes by group, which a comment shares with its whole thread
+ if (post.parentPostId) {
+ return {
+ output: {
+ errors:
+ 'This id belongs to a comment, pass the id of the main post',
+ },
+ };
+ }
+
+ await this._postsService.deletePost(organizationId, post.group);
+
+ return { output: { postId: post.id } };
+ },
+ });
+ }
+}
diff --git a/libraries/nestjs-libraries/src/chat/tools/posts.list.tool.ts b/libraries/nestjs-libraries/src/chat/tools/posts.list.tool.ts
index 2dc3644d1..d8abc95fd 100644
--- a/libraries/nestjs-libraries/src/chat/tools/posts.list.tool.ts
+++ b/libraries/nestjs-libraries/src/chat/tools/posts.list.tool.ts
@@ -39,7 +39,6 @@ List the organization's posts scheduled to be published between two dates (the s
Returns every post in the window whatever its state (scheduled, draft, published, errored).
"startDate" and "endDate" are required (UTC) - to list all upcoming posts, pass a wide window (for example from now to a year ahead).
Each item has an "id", its publish date, state, error (for errored posts), content, channel and current provider settings.
-Posts cannot be deleted through the Postiz tools - if the user wants to delete a post, tell them to do it themselves in the Postiz app; never offer to delete a post.
`,
inputSchema: z.object({
startDate: z
diff --git a/libraries/nestjs-libraries/src/chat/tools/tool.list.ts b/libraries/nestjs-libraries/src/chat/tools/tool.list.ts
index 117306736..920d78730 100644
--- a/libraries/nestjs-libraries/src/chat/tools/tool.list.ts
+++ b/libraries/nestjs-libraries/src/chat/tools/tool.list.ts
@@ -15,6 +15,7 @@ import { UploadFromUrlTool } from '@gitroom/nestjs-libraries/chat/tools/upload.f
import { MediaListTool } from '@gitroom/nestjs-libraries/chat/tools/media.list.tool';
import { PostsListTool } from '@gitroom/nestjs-libraries/chat/tools/posts.list.tool';
import { PostSettingsTool } from '@gitroom/nestjs-libraries/chat/tools/post.settings.tool';
+import { DeletePostTool } from '@gitroom/nestjs-libraries/chat/tools/delete.post.tool';
import { UploadWidgetTool } from '@gitroom/nestjs-libraries/chat/tools/upload.widget.tool';
import { UploadWidgetTicketTool } from '@gitroom/nestjs-libraries/chat/tools/upload.widget.ticket.tool';
import { UploadWidgetStatusTool } from '@gitroom/nestjs-libraries/chat/tools/upload.widget.status.tool';
@@ -27,6 +28,7 @@ export const toolList = [
IntegrationSchedulePostTool,
PostsListTool,
PostSettingsTool,
+ DeletePostTool,
GenerateVideoOptionsTool,
VideoFunctionTool,
GenerateVideoTool,