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.
PHP ai-agentsblueskyfacebookinstagramlaravellinkedinmastodonmcpmcp-serveropen-sourcerest-apiself-hostedsocial-mediasocial-media-managementsocial-media-schedulerthreadstiktokvuejsxyoutube
fix(ai-templates): paragraph spacing bug, registry cache, coverage gaps, empty-account UX
Paulo Castellanobb55e1442371
diff --git a/app/Ai/Templates/AiTemplateRegistry.php b/app/Ai/Templates/AiTemplateRegistry.phpindex f1be810a3..c81716e04 100644--- a/app/Ai/Templates/AiTemplateRegistry.php+++ b/app/Ai/Templates/AiTemplateRegistry.php@@ -15,10 +15,13 @@ class AiTemplateRegistryTweetCardTemplate::class,];+ /** @var array<int, AiContentTemplate>|null */+ private ?array $templates = null;+/** @return array<int, AiContentTemplate> */public function all(): array{- return array_map(fn (string $class) => app($class), self::TEMPLATES);+ return $this->templates ??= array_map(fn (string $class) => app($class), self::TEMPLATES);}/** @return array<int, string> */diff --git a/app/Http/Controllers/App/PostController.php b/app/Http/Controllers/App/PostController.phpindex 5c7f9c7fc..65576b9cd 100644--- a/app/Http/Controllers/App/PostController.php+++ b/app/Http/Controllers/App/PostController.php@@ -9,6 +9,7 @@ use App\Actions\Post\DeletePost;use App\Actions\Post\DuplicatePost;use App\Actions\Post\SyncPostPlatforms;use App\Actions\Post\UpdatePost;+use App\Ai\Templates\AiContentTemplate;use App\Ai\Templates\AiTemplateRegistry;use App\Enums\Post\Action as PostAction;use App\Enums\Post\Status as PostStatus;@@ -145,7 +146,7 @@ class PostController extends Controller$registry = app(AiTemplateRegistry::class);- $templates = array_map(fn ($t) => [+ $templates = array_map(fn (AiContentTemplate $t) => ['key' => $t->key(),'name' => trans($t->name()),'description' => trans($t->description()),diff --git a/app/Services/Image/TemplateImageGenerator.php b/app/Services/Image/TemplateImageGenerator.phpindex dbd763223..a4be6670f 100644--- a/app/Services/Image/TemplateImageGenerator.php+++ b/app/Services/Image/TemplateImageGenerator.php@@ -590,7 +590,7 @@ class TemplateImageGenerator$bodyLineHeight = 1.55;$paragraphGap = (int) round($bodySize * $bodyLineHeight * 0.6);- $paragraphs = array_filter(array_map('trim', explode("\n\n", $tweetText)), fn ($p) => $p !== '');+ $paragraphs = array_values(array_filter(array_map('trim', explode("\n\n", $tweetText)), fn ($p) => $p !== ''));$allBodyLines = [];foreach ($paragraphs as $i => $para) {$lines = ($fontMedium ? $this->wrapText($para, $fontMedium, $bodySize, $cardW - 2 * $cardPadding) : [str_replace("\n", ' ', $para)]);diff --git a/lang/en/posts.php b/lang/en/posts.phpindex b966ee45c..252754f52 100644--- a/lang/en/posts.php+++ b/lang/en/posts.php@@ -620,6 +620,7 @@ return ['retry' => 'Try again','no_platforms' => 'No connected accounts','connect_first' => 'Connect at least one social account to use AI generation.',+ 'no_account_for_template' => 'Connect a compatible account to use this template.','format' => ['instagram_feed' => 'Instagram Feed Post',diff --git a/lang/es/posts.php b/lang/es/posts.phpindex 6926f1526..4dd580e6b 100644--- a/lang/es/posts.php+++ b/lang/es/posts.php@@ -621,6 +621,7 @@ return ['retry' => 'Intentar de nuevo','no_platforms' => 'Sin cuentas conectadas','connect_first' => 'Conecta al menos una cuenta social para usar la generación con IA.',+ 'no_account_for_template' => 'Conecta una cuenta compatible para usar esta plantilla.','format' => ['instagram_feed' => 'Post de Feed de Instagram',diff --git a/lang/pt-BR/posts.php b/lang/pt-BR/posts.phpindex c19e0b2a2..c9fdc07c7 100644--- a/lang/pt-BR/posts.php+++ b/lang/pt-BR/posts.php@@ -620,6 +620,7 @@ return ['retry' => 'Tentar novamente','no_platforms' => 'Nenhuma conta conectada','connect_first' => 'Conecte pelo menos uma conta social para usar a geração com IA.',+ 'no_account_for_template' => 'Conecte uma conta compatível para usar este template.','format' => ['instagram_feed' => 'Post no Feed do Instagram',diff --git a/resources/js/components/posts/create/AiPostWizard.vue b/resources/js/components/posts/create/AiPostWizard.vueindex 566e0229f..d4592bf2d 100644--- a/resources/js/components/posts/create/AiPostWizard.vue+++ b/resources/js/components/posts/create/AiPostWizard.vue@@ -337,7 +337,10 @@ const startGeneration = async () => {<!-- Account (when template needs_account OR there's a choice to make) --><div v-if="selectedFormat && (templateNeedsAccount || showsAccountPicker)" class="space-y-2"><Label class="text-sm font-bold">{{ $t('posts.create.steps.account_title') }}</Label>- <div class="grid grid-cols-2 gap-2 sm:grid-cols-3">+ <p v-if="templateNeedsAccount && accountsForFormat.length === 0" class="text-sm text-foreground/60">+ {{ $t('posts.create.steps.no_account_for_template') }}+ </p>+ <div v-else class="grid grid-cols-2 gap-2 sm:grid-cols-3"><buttonv-for="account in accountsForFormat":key="account.id"diff --git a/tests/Feature/Ai/StreamPostCreationTest.php b/tests/Feature/Ai/StreamPostCreationTest.phpindex fa16a161c..0f0813181 100644--- a/tests/Feature/Ai/StreamPostCreationTest.php+++ b/tests/Feature/Ai/StreamPostCreationTest.php@@ -117,6 +117,8 @@ test('tweet_card template stores the tweet_text as post content and attaches a m$platform = PostPlatform::where('social_account_id', $this->account->id)->firstOrFail();expect($platform->content_type)->toBe(ContentType::XPost);++ PostContentHumanizer::assertNeverPrompted();});test('the humanizer is given the same platform context as the generator so the rewrite honours the character cap', function () {diff --git a/tests/Feature/Ai/Templates/AiTemplateRegistryTest.php b/tests/Feature/Ai/Templates/AiTemplateRegistryTest.phpindex 225ccb542..28c52ef7c 100644--- a/tests/Feature/Ai/Templates/AiTemplateRegistryTest.php+++ b/tests/Feature/Ai/Templates/AiTemplateRegistryTest.php@@ -7,7 +7,7 @@ use App\Ai\Templates\ImageCardTemplate;test('registry resolves keys and defaults to image_card', function () {$registry = app(AiTemplateRegistry::class);- expect($registry->keys())->toContain('image_card', 'carousel')+ expect($registry->keys())->toContain('image_card', 'carousel', 'tweet_card')->and($registry->find('image_card'))->toBeInstanceOf(ImageCardTemplate::class)->and($registry->default()->key())->toBe('image_card');});diff --git a/tests/Feature/Ai/Templates/TweetCardRenderTest.php b/tests/Feature/Ai/Templates/TweetCardRenderTest.phpindex 8d28c800c..d1fc3473b 100644--- a/tests/Feature/Ai/Templates/TweetCardRenderTest.php+++ b/tests/Feature/Ai/Templates/TweetCardRenderTest.php@@ -4,11 +4,14 @@ declare(strict_types=1);use App\Models\SocialAccount;use App\Models\Workspace;+use App\Services\Image\PostImagePipeline;use App\Services\Image\TemplateImageGenerator;use Illuminate\Support\Facades\Storage;+use Laravel\Ai\Image;test('renderTweetCard produces a stored webp without calling the AI image client', function () {Storage::fake();+ Image::fake();$workspace = Workspace::factory()->create(['brand_color' => '#1d9bf0']);$account = SocialAccount::factory()->create(['workspace_id' => $workspace->id,@@ -26,4 +29,44 @@ test('renderTweetCard produces a stored webp without calling the AI image client->and($result['path'])->toEndWith('.webp')->and(Storage::exists($result['path']))->toBeTrue()->and(data_get($result, 'source_meta.template'))->toBe('tweet_card');++ Image::assertNothingGenerated();+});++test('renderTweetCard succeeds when the account has no avatar_url', function () {+ Storage::fake();+ Image::fake();+ $workspace = Workspace::factory()->create(['brand_color' => '#1d9bf0']);+ $account = SocialAccount::factory()->create([+ 'workspace_id' => $workspace->id,+ 'display_name' => 'No Avatar User',+ 'username' => 'noavatar',+ 'avatar_url' => null,+ ]);++ $result = app(TemplateImageGenerator::class)->renderTweetCard(+ $workspace,+ $account,+ 'A tweet with no avatar attached.',+ );++ expect($result)->not->toBeNull()+ ->and($result['path'])->toEndWith('.webp')+ ->and(Storage::exists($result['path']))->toBeTrue();+});++test('forTweetCard returns [] when renderTweetCard returns null', function () {+ Storage::fake();++ $workspace = Workspace::factory()->create();+ $account = SocialAccount::factory()->create(['workspace_id' => $workspace->id]);++ $mock = Mockery::mock(TemplateImageGenerator::class)->makePartial();+ $mock->shouldReceive('renderTweetCard')->andReturn(null);++ $this->app->instance(TemplateImageGenerator::class, $mock);++ $result = app(PostImagePipeline::class)->forTweetCard($workspace, $account, 'some text');++ expect($result)->toBe([]);});