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.

refactor: drop RenderedSlide DTO and content_language null fallbacks

Paulo Castellanod97822c7e8a4
diff --git a/app/Ai/Agents/PostContentGenerator.php b/app/Ai/Agents/PostContentGenerator.php
index 4de29847b..52dc336cb 100644
--- a/app/Ai/Agents/PostContentGenerator.php
+++ b/app/Ai/Agents/PostContentGenerator.php
@@ -62,7 +62,7 @@ class PostContentGenerator implements Agent, HasStructuredOutput
'brand_description' => $this->workspace->brand_description ?? '',
'brand_tone' => $this->workspace->brand_tone ?? '',
'brand_voice_notes' => $this->workspace->brand_voice_notes ?? '',
- 'content_language' => $this->workspace->content_language ?? 'en',
+ 'content_language' => $this->workspace->content_language,
'current_content' => $this->currentContent,
'format' => $this->format,
'slide_count' => $this->slideCount,
diff --git a/app/Ai/Agents/PostContentHumanizer.php b/app/Ai/Agents/PostContentHumanizer.php
index eb0d34a5a..d0dfd7a23 100644
--- a/app/Ai/Agents/PostContentHumanizer.php
+++ b/app/Ai/Agents/PostContentHumanizer.php
@@ -34,7 +34,7 @@ class PostContentHumanizer implements Agent, HasStructuredOutput
'brand_name' => $this->workspace->name ?? '',
'brand_tone' => $this->workspace->brand_tone ?? '',
'brand_voice_notes' => $this->workspace->brand_voice_notes ?? '',
- 'content_language' => $this->workspace->content_language ?? 'en',
+ 'content_language' => $this->workspace->content_language,
'format' => $this->format,
])->render();
}
diff --git a/app/Ai/Agents/PostContentReviewer.php b/app/Ai/Agents/PostContentReviewer.php
index 4c87980bd..07a398555 100644
--- a/app/Ai/Agents/PostContentReviewer.php
+++ b/app/Ai/Agents/PostContentReviewer.php
@@ -27,7 +27,7 @@ class PostContentReviewer implements Agent, HasStructuredOutput
'brand_name' => $this->workspace->name ?? '',
'brand_tone' => $this->workspace->brand_tone ?? '',
'brand_voice_notes' => $this->workspace->brand_voice_notes ?? '',
- 'content_language' => $this->workspace->content_language ?? 'en',
+ 'content_language' => $this->workspace->content_language,
])->render();
}
diff --git a/app/Ai/Agents/PostContentStreamer.php b/app/Ai/Agents/PostContentStreamer.php
index 348f35429..091fb0b76 100644
--- a/app/Ai/Agents/PostContentStreamer.php
+++ b/app/Ai/Agents/PostContentStreamer.php
@@ -35,7 +35,7 @@ class PostContentStreamer implements Agent
'brand_description' => $this->workspace->brand_description ?? '',
'brand_tone' => $this->workspace->brand_tone ?? '',
'brand_voice_notes' => $this->workspace->brand_voice_notes ?? '',
- 'content_language' => $this->workspace->content_language ?? 'en',
+ 'content_language' => $this->workspace->content_language,
'current_content' => $this->currentContent,
'format' => 'single',
'slide_count' => 1,
diff --git a/app/Http/Controllers/App/PostTemplateController.php b/app/Http/Controllers/App/PostTemplateController.php
index 28b8f30bd..c7889097b 100644
--- a/app/Http/Controllers/App/PostTemplateController.php
+++ b/app/Http/Controllers/App/PostTemplateController.php
@@ -79,7 +79,7 @@ class PostTemplateController extends Controller
);
if ($rendered) {
- $mediaItem = $this->createMediaItem($workspace, $rendered->path);
+ $mediaItem = $this->createMediaItem($workspace, $rendered['path']);
$media[] = $mediaItem;
}
}
diff --git a/app/Jobs/Ai/StreamPostCreation.php b/app/Jobs/Ai/StreamPostCreation.php
index cd2cddd7d..780a32a22 100644
--- a/app/Jobs/Ai/StreamPostCreation.php
+++ b/app/Jobs/Ai/StreamPostCreation.php
@@ -21,7 +21,6 @@ use App\Models\Workspace;
use App\Services\Ai\AiImageClient;
use App\Services\Ai\RecordAiUsage;
use App\Services\Image\BrandColorMapper;
-use App\Services\Image\RenderedSlide;
use App\Services\Image\TemplateImageGenerator;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
@@ -313,15 +312,13 @@ class StreamPostCreation implements ShouldQueue
$user = User::findOrFail($this->userId);
- $locale = $workspace->content_language ?? 'en';
-
SendNotification::dispatch(
user: $user,
workspaceId: $workspace->id,
type: NotificationType::PostReady,
channel: NotificationChannel::InApp,
- title: trans('notifications.post_ready.title', [], $locale),
- body: trans('notifications.post_ready.body', [], $locale),
+ title: trans('notifications.post_ready.title', [], $workspace->content_language),
+ body: trans('notifications.post_ready.body', [], $workspace->content_language),
data: ['post_id' => $post->id],
);
}
@@ -340,17 +337,18 @@ class StreamPostCreation implements ShouldQueue
}
/**
+ * @param array{path: string, source_meta: array<string, mixed>} $rendered
* @return array<string, mixed>
*/
- private function buildAiMediaItem(Workspace $workspace, RenderedSlide $rendered): array
+ private function buildAiMediaItem(Workspace $workspace, array $rendered): array
{
$media = $workspace->media()->create([
'collection' => 'ai-generated',
'type' => MediaType::Image,
- 'path' => $rendered->path,
- 'original_filename' => basename($rendered->path),
+ 'path' => $rendered['path'],
+ 'original_filename' => basename($rendered['path']),
'mime_type' => 'image/webp',
- 'size' => Storage::size($rendered->path),
+ 'size' => Storage::size($rendered['path']),
'order' => 0,
]);
@@ -361,7 +359,7 @@ class StreamPostCreation implements ShouldQueue
'type' => 'image',
'mime_type' => 'image/webp',
'source' => Source::Ai->value,
- 'source_meta' => $rendered->sourceMeta,
+ 'source_meta' => $rendered['source_meta'],
];
}
}
diff --git a/app/Services/Image/RenderedSlide.php b/app/Services/Image/RenderedSlide.php
deleted file mode 100644
index cde282938..000000000
--- a/app/Services/Image/RenderedSlide.php
+++ /dev/null
@@ -1,16 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace App\Services\Image;
-
-class RenderedSlide
-{
- /**
- * @param array<string, mixed> $sourceMeta
- */
- public function __construct(
- public readonly string $path,
- public readonly array $sourceMeta,
- ) {}
-}
diff --git a/app/Services/Image/TemplateImageGenerator.php b/app/Services/Image/TemplateImageGenerator.php
index 5ab2896e8..ace9b29de 100644
--- a/app/Services/Image/TemplateImageGenerator.php
+++ b/app/Services/Image/TemplateImageGenerator.php
@@ -35,10 +35,12 @@ class TemplateImageGenerator
) {}
/**
- * Render a slide using Template A (full bleed) or Template B (photo card).
+ * Render a slide and return the storage path plus the source meta needed
+ * to regenerate it later. Returns null on failure (e.g. the AI client
+ * could not produce a usable image).
*
* @param array<int, string> $imageKeywords
- * @return RenderedSlide|null The storage path + source meta, or null on failure.
+ * @return array{path: string, source_meta: array<string, mixed>}|null
*/
public function render(
Workspace $workspace,
@@ -48,7 +50,7 @@ class TemplateImageGenerator
array $imageKeywords,
int $width = self::DEFAULT_WIDTH,
int $height = self::DEFAULT_HEIGHT,
- ): ?RenderedSlide {
+ ): ?array {
$this->width = $width;
$this->height = $height;
@@ -59,7 +61,7 @@ class TemplateImageGenerator
is_string($rawStyle) => ImageStyle::tryFrom($rawStyle) ?? ImageStyle::DEFAULT,
default => ImageStyle::DEFAULT,
};
- $language = $workspace->content_language ?? 'en';
+ $language = $workspace->content_language;
$imageData = $this->aiImage->generate(
keywords: $imageKeywords,
@@ -101,9 +103,9 @@ class TemplateImageGenerator
],
);
- return new RenderedSlide(
- path: $filename,
- sourceMeta: [
+ return [
+ 'path' => $filename,
+ 'source_meta' => [
'keywords' => array_values($imageKeywords),
'style' => $imageStyle->value,
'language' => $language,
@@ -113,7 +115,7 @@ class TemplateImageGenerator
'width' => $this->width,
'height' => $this->height,
],
- );
+ ];
}
/**
diff --git a/database/factories/WorkspaceFactory.php b/database/factories/WorkspaceFactory.php
index 6b8ca431f..3e9de50fa 100644
--- a/database/factories/WorkspaceFactory.php
+++ b/database/factories/WorkspaceFactory.php
@@ -24,6 +24,10 @@ class WorkspaceFactory extends Factory
return [
'user_id' => User::factory(),
'name' => fake()->company(),
+ 'content_language' => 'en',
+ 'brand_tone' => 'professional',
+ 'brand_font' => 'Inter',
+ 'image_style' => 'cinematic',
];
}
diff --git a/tests/Unit/Services/Image/TemplateImageGeneratorTest.php b/tests/Unit/Services/Image/TemplateImageGeneratorTest.php
index 62f317fc0..515345129 100644
--- a/tests/Unit/Services/Image/TemplateImageGeneratorTest.php
+++ b/tests/Unit/Services/Image/TemplateImageGeneratorTest.php
@@ -73,8 +73,8 @@ test('renders a slide and stores webp when AI returns bytes', function () use ($
);
if ($result !== null) {
- expect($result->path)->toStartWith('ai-images/')->toEndWith('.webp');
- expect($result->sourceMeta)
+ expect($result['path'])->toStartWith('ai-images/')->toEndWith('.webp');
+ expect($result['source_meta'])
->toHaveKey('keywords')
->toHaveKey('style', 'illustration')
->toHaveKey('model', 'gpt-image-2')