Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

feat(posts): introduce change_mode for flexible image and text regeneration

Paulo Castellano91a144142fc9
diff --git a/app/Ai/Agents/PostImageRegenerator.php b/app/Ai/Agents/PostImageRegenerator.php
index 0e3b9179e..5fe2edc4e 100644
--- a/app/Ai/Agents/PostImageRegenerator.php
+++ b/app/Ai/Agents/PostImageRegenerator.php
@@ -41,8 +41,9 @@ class PostImageRegenerator implements Agent, HasStructuredOutput
->items($schema->string())
->description('3-10 short keywords for image generation context.')
->required(),
- 'regenerate_image' => $schema->boolean()
- ->description('Whether the background image should be regenerated. Use false when only text/typo changes are needed and visual should stay the same.')
+ 'change_mode' => $schema->string()
+ ->enum(['image_only', 'text_only', 'both'])
+ ->description('Set to image_only (change visual only), text_only (change text only), or both (change visual and text).')
->required(),
];
}
diff --git a/app/Jobs/Ai/RegeneratePostMediaImage.php b/app/Jobs/Ai/RegeneratePostMediaImage.php
index ac3ecba78..f1fffacca 100644
--- a/app/Jobs/Ai/RegeneratePostMediaImage.php
+++ b/app/Jobs/Ai/RegeneratePostMediaImage.php
@@ -121,7 +121,14 @@ class RegeneratePostMediaImage implements ShouldQueue
* width: int,
* height: int
* } $baseContext
- * @return array{title: string, body: string, keywords: array<int, string>, regenerate_image: bool}
+ * @return array{
+ * title: string,
+ * body: string,
+ * keywords: array<int, string>,
+ * regenerate_image: bool,
+ * regenerate_text: bool,
+ * change_mode: 'image_only'|'text_only'|'both'
+ * }
*/
private function regenerateSlideCopy(Workspace $workspace, Post $post, array $baseContext): array
{
@@ -161,22 +168,45 @@ class RegeneratePostMediaImage implements ShouldQueue
* height: int
* } $baseContext
* @param array<string, mixed> $structured
- * @return array{title: string, body: string, keywords: array<int, string>, regenerate_image: bool}
+ * @return array{
+ * title: string,
+ * body: string,
+ * keywords: array<int, string>,
+ * regenerate_image: bool,
+ * regenerate_text: bool,
+ * change_mode: 'image_only'|'text_only'|'both'
+ * }
*/
private function mergeStructuredCopy(array $baseContext, array $structured): array
{
+ $changeMode = $this->resolveChangeMode((string) data_get($structured, 'change_mode', 'both'));
+ $regenerateImage = in_array($changeMode, ['image_only', 'both'], true);
+ $regenerateText = in_array($changeMode, ['text_only', 'both'], true);
$keywords = $this->normalizeKeywords(data_get($structured, 'keywords', $baseContext['keywords']));
return [
- 'title' => trim((string) data_get($structured, 'title', $baseContext['title'])),
- 'body' => trim((string) data_get($structured, 'body', $baseContext['body'])),
- 'keywords' => $keywords !== [] ? $keywords : $baseContext['keywords'],
- 'regenerate_image' => (bool) data_get($structured, 'regenerate_image', true),
+ 'title' => $regenerateText
+ ? trim((string) data_get($structured, 'title', $baseContext['title']))
+ : $baseContext['title'],
+ 'body' => $regenerateText
+ ? trim((string) data_get($structured, 'body', $baseContext['body']))
+ : $baseContext['body'],
+ 'keywords' => $regenerateImage && $keywords !== [] ? $keywords : $baseContext['keywords'],
+ 'regenerate_image' => $regenerateImage,
+ 'regenerate_text' => $regenerateText,
+ 'change_mode' => $changeMode,
];
}
/**
- * @param array{title: string, body: string, keywords: array<int, string>, regenerate_image: bool} $copy
+ * @param array{
+ * title: string,
+ * body: string,
+ * keywords: array<int, string>,
+ * regenerate_image: bool,
+ * regenerate_text: bool,
+ * change_mode: 'image_only'|'text_only'|'both'
+ * } $copy
* @param array{
* title: string,
* body: string,
@@ -377,6 +407,17 @@ class RegeneratePostMediaImage implements ShouldQueue
->all();
}
+ /**
+ * @return 'image_only'|'text_only'|'both'
+ */
+ private function resolveChangeMode(string $value): string
+ {
+ return match ($value) {
+ 'image_only', 'text_only', 'both' => $value,
+ default => 'both',
+ };
+ }
+
private function resolveSocialAccount(Post $post, Workspace $workspace): ?SocialAccount
{
$enabledAccount = $post->postPlatforms
diff --git a/resources/views/prompts/post_image/regenerator.blade.php b/resources/views/prompts/post_image/regenerator.blade.php
index 372bfbd96..f74f81aa3 100644
--- a/resources/views/prompts/post_image/regenerator.blade.php
+++ b/resources/views/prompts/post_image/regenerator.blade.php
@@ -3,12 +3,13 @@ You are editing text that will be printed inside a social media image.
Your job:
- Apply the user's instruction to the current title/body/keywords.
- Keep the same language as the input unless the instruction explicitly asks to change it.
-- Fix spelling and grammar when needed.
- Keep output concise and suitable for image overlays.
- Preserve intent and topic; only change what is needed.
-- Set `regenerate_image` to:
- - `false` when changes are text-only (typos, wording, capitalization, punctuation, CTA wording) and the visual background should stay the same.
- - `true` when the user asks to change visual style, scene, objects, mood, colors, composition, or anything that requires a new background image.
+- Return one `change_mode` value:
+ - `text_only`: user asked to change only wording/typos/capitalization/punctuation. Keep visual unchanged.
+ - `image_only`: user asked to change visual only. Keep title/body exactly as provided (no spelling/casing normalization).
+ - `both`: user asked to change both visual and text.
+- In `image_only`, do not rewrite title/body and do not "fix" grammar/casing automatically.
Return JSON only, following the schema.
diff --git a/tests/Feature/Ai/RegeneratePostMediaImageJobTest.php b/tests/Feature/Ai/RegeneratePostMediaImageJobTest.php
index 9c84704b6..9af696f2c 100644
--- a/tests/Feature/Ai/RegeneratePostMediaImageJobTest.php
+++ b/tests/Feature/Ai/RegeneratePostMediaImageJobTest.php
@@ -41,3 +41,83 @@ test('job fallback source context uses post content when source_meta is missing'
expect(data_get($context, 'width'))->toBe(1080);
expect(data_get($context, 'height'))->toBe(1350);
});
+
+test('merge structured copy keeps text unchanged for image_only mode', function () {
+ $job = new RegeneratePostMediaImage(
+ workspaceId: 'workspace-id',
+ postId: 'post-id',
+ userId: 'user-id',
+ mediaId: 'media-id',
+ regenerationId: 'regen-id',
+ instruction: 'change image only',
+ );
+
+ $method = new ReflectionMethod(RegeneratePostMediaImage::class, 'mergeStructuredCopy');
+ $method->setAccessible(true);
+
+ $baseContext = [
+ 'title' => 'Keep THIS Text',
+ 'body' => 'Body should remain exactly the same.',
+ 'keywords' => ['saas', 'dashboard'],
+ 'background_path' => 'ai-images/bg.webp',
+ 'language' => 'en',
+ 'width' => 1080,
+ 'height' => 1350,
+ ];
+
+ $structured = [
+ 'change_mode' => 'image_only',
+ 'title' => 'Model tried to rewrite',
+ 'body' => 'Model tried to rewrite body',
+ 'keywords' => ['modern office', 'team'],
+ ];
+
+ $copy = $method->invoke($job, $baseContext, $structured);
+
+ expect(data_get($copy, 'title'))->toBe($baseContext['title'])
+ ->and(data_get($copy, 'body'))->toBe($baseContext['body'])
+ ->and(data_get($copy, 'keywords'))->toBe(['modern office', 'team'])
+ ->and(data_get($copy, 'regenerate_image'))->toBeTrue()
+ ->and(data_get($copy, 'regenerate_text'))->toBeFalse()
+ ->and(data_get($copy, 'change_mode'))->toBe('image_only');
+});
+
+test('merge structured copy keeps keywords unchanged for text_only mode', function () {
+ $job = new RegeneratePostMediaImage(
+ workspaceId: 'workspace-id',
+ postId: 'post-id',
+ userId: 'user-id',
+ mediaId: 'media-id',
+ regenerationId: 'regen-id',
+ instruction: 'change text only',
+ );
+
+ $method = new ReflectionMethod(RegeneratePostMediaImage::class, 'mergeStructuredCopy');
+ $method->setAccessible(true);
+
+ $baseContext = [
+ 'title' => 'Old title',
+ 'body' => 'Old body',
+ 'keywords' => ['saas', 'dashboard'],
+ 'background_path' => 'ai-images/bg.webp',
+ 'language' => 'en',
+ 'width' => 1080,
+ 'height' => 1350,
+ ];
+
+ $structured = [
+ 'change_mode' => 'text_only',
+ 'title' => 'New title',
+ 'body' => 'New body',
+ 'keywords' => ['ignored', 'for', 'text-only'],
+ ];
+
+ $copy = $method->invoke($job, $baseContext, $structured);
+
+ expect(data_get($copy, 'title'))->toBe('New title')
+ ->and(data_get($copy, 'body'))->toBe('New body')
+ ->and(data_get($copy, 'keywords'))->toBe($baseContext['keywords'])
+ ->and(data_get($copy, 'regenerate_image'))->toBeFalse()
+ ->and(data_get($copy, 'regenerate_text'))->toBeTrue()
+ ->and(data_get($copy, 'change_mode'))->toBe('text_only');
+});