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-create): sync the prompt limit across front and back
Paulo Castellano3dbb8e6f7e3c
diff --git a/app/Http/Requests/App/Ai/GeneratePostContentRequest.php b/app/Http/Requests/App/Ai/GeneratePostContentRequest.phpindex c8e1c8543..a94dc5341 100644--- a/app/Http/Requests/App/Ai/GeneratePostContentRequest.php+++ b/app/Http/Requests/App/Ai/GeneratePostContentRequest.php@@ -4,6 +4,7 @@ declare(strict_types=1);namespace App\Http\Requests\App\Ai;+use App\Support\AiPromptRules;use Illuminate\Foundation\Http\FormRequest;class GeneratePostContentRequest extends FormRequest@@ -19,7 +20,7 @@ class GeneratePostContentRequest extends FormRequestpublic function rules(): array{return [- 'prompt' => ['required', 'string', 'max:2000'],+ 'prompt' => ['required', 'string', 'max:'.AiPromptRules::PROMPT_MAX_LENGTH],'current_content' => ['nullable', 'string', 'max:10000'],];}diff --git a/app/Http/Requests/App/Ai/StartPostCreationRequest.php b/app/Http/Requests/App/Ai/StartPostCreationRequest.phpindex 2d24a4fa7..34ffb1bcd 100644--- a/app/Http/Requests/App/Ai/StartPostCreationRequest.php+++ b/app/Http/Requests/App/Ai/StartPostCreationRequest.php@@ -6,6 +6,7 @@ namespace App\Http\Requests\App\Ai;use App\Enums\Ai\ContentStyle;use App\Enums\PostPlatform\ContentType;+use App\Support\AiPromptRules;use Illuminate\Foundation\Http\FormRequest;use Illuminate\Validation\Rule;use Illuminate\Validation\Validator;@@ -33,7 +34,7 @@ class StartPostCreationRequest extends FormRequest],'social_account_id' => ['nullable', 'uuid'],'image_count' => ['nullable', 'integer', 'min:0', 'max:10'],- 'prompt' => ['required', 'string', 'max:2000'],+ 'prompt' => AiPromptRules::promptRule(),'date' => ['nullable', 'date_format:Y-m-d'],'template' => ['sometimes', 'string', Rule::enum(ContentStyle::class)],];diff --git a/app/Support/AiPromptRules.php b/app/Support/AiPromptRules.phpnew file mode 100644index 000000000..9803cb902--- /dev/null+++ b/app/Support/AiPromptRules.php@@ -0,0 +1,34 @@+<?php++declare(strict_types=1);++namespace App\Support;++/**+ * Single source of truth for the user-supplied AI generation prompt length,+ * shared by the create wizard (StartPostCreationRequest) and the editor's+ * content generation (GeneratePostContentRequest). The frontend counter in+ * resources/js/components/posts/create/AiPostWizard.vue mirrors these bounds.+ */+class AiPromptRules+{+ /**+ * Minimum prompt length (characters) for the create wizard.+ */+ public const PROMPT_MIN_LENGTH = 3;++ /**+ * Maximum prompt length (characters); mirrored by the frontend counter.+ */+ public const PROMPT_MAX_LENGTH = 2000;++ /**+ * Validation rules for the create wizard's generation prompt.+ *+ * @return array<int, string>+ */+ public static function promptRule(): array+ {+ return ['required', 'string', 'min:'.self::PROMPT_MIN_LENGTH, 'max:'.self::PROMPT_MAX_LENGTH];+ }+}diff --git a/resources/js/components/posts/create/AiPostWizard.vue b/resources/js/components/posts/create/AiPostWizard.vueindex 797f91f4d..4e304921a 100644--- a/resources/js/components/posts/create/AiPostWizard.vue+++ b/resources/js/components/posts/create/AiPostWizard.vue@@ -63,7 +63,7 @@ const selectedAccountId = ref<string | null>(null);const includeImages = ref(true);const imageCount = ref(2);const promptText = ref('');-// Mirrors the backend validation (`prompt` max:2000) so the limit is visible in the UI.+const PROMPT_MIN = 3;const PROMPT_MAX = 2000;const submitting = ref(false);@@ -159,11 +159,13 @@ const submittedImageCount = computed(() => {return 0;});+const promptLength = computed(() => [...promptText.value.trim()].length);+const canSubmit = computed(() =>selectedFormat.value !== null &&selectedAccountId.value !== null &&- promptText.value.trim().length >= 3 &&- promptText.value.length <= PROMPT_MAX,+ promptLength.value >= PROMPT_MIN &&+ promptLength.value <= PROMPT_MAX,);// Auto-pick the only account when format has exactly one match.@@ -363,9 +365,9 @@ const startGeneration = async () => {/><pclass="text-right text-xs tabular-nums"- :class="promptText.length > PROMPT_MAX ? 'font-semibold text-destructive' : 'text-muted-foreground'"+ :class="promptLength > PROMPT_MAX ? 'font-semibold text-destructive' : 'text-muted-foreground'">- {{ promptText.length }}/{{ PROMPT_MAX }}+ {{ promptLength }}/{{ PROMPT_MAX }}</p></div>diff --git a/tests/Feature/Ai/PostAiCreateTest.php b/tests/Feature/Ai/PostAiCreateTest.phpindex 8f588452d..91e276428 100644--- a/tests/Feature/Ai/PostAiCreateTest.php+++ b/tests/Feature/Ai/PostAiCreateTest.php@@ -8,6 +8,7 @@ use App\Jobs\Ai\StreamPostCreation;use App\Models\SocialAccount;use App\Models\User;use App\Models\Workspace;+use App\Support\AiPromptRules;use Illuminate\Support\Facades\Bus;use Symfony\Component\HttpFoundation\Response;@@ -32,6 +33,44 @@ test('start validates prompt is required', function () {->assertJsonValidationErrors(['prompt']);});+test('start rejects a prompt shorter than the minimum length', function () {+ Bus::fake();++ $this->actingAs($this->user)+ ->postJson(route('app.posts.ai.create'), ['prompt' => 'hi', 'format' => 'x_post'])+ ->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY)+ ->assertJsonValidationErrors(['prompt']);++ Bus::assertNotDispatched(StreamPostCreation::class);+});++test('start rejects a prompt longer than the maximum length', function () {+ Bus::fake();++ $this->actingAs($this->user)+ ->postJson(route('app.posts.ai.create'), [+ 'prompt' => str_repeat('a', AiPromptRules::PROMPT_MAX_LENGTH + 1),+ 'format' => 'x_post',+ ])+ ->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY)+ ->assertJsonValidationErrors(['prompt']);++ Bus::assertNotDispatched(StreamPostCreation::class);+});++test('start accepts a prompt at the maximum length', function () {+ Bus::fake();++ $this->actingAs($this->user)+ ->postJson(route('app.posts.ai.create'), [+ 'prompt' => str_repeat('a', AiPromptRules::PROMPT_MAX_LENGTH),+ 'format' => 'x_post',+ ])+ ->assertStatus(Response::HTTP_ACCEPTED);++ Bus::assertDispatched(StreamPostCreation::class);+});+test('start validates format is required', function () {Bus::fake();