trypost/resources/js/lib/aiGenerateVariants.ts
Paulo Castellano 4cbdfa37d7 Hide video-only formats in the automation Generate node.
AI generate only produces images, so Video Pin / Reel / TikTok Video are filtered out in previewOnly and rejected server-side with a clear error.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-24 23:29:58 -03:00

32 lines
1,023 B
TypeScript

import { getMediaRulesForContentType } from '@/composables/useMediaRules';
/**
* The automation Generate node (and AI wizard) only produce images. When
* `imageOnly` is true (previewOnly / generate context), drop video-only
* content types so they can't be selected.
*/
export const filterImageCapableVariants = <T extends { value: string }>(
variants: readonly T[],
imageOnly: boolean,
): T[] => {
if (! imageOnly) {
return [...variants];
}
return variants.filter((variant) => getMediaRulesForContentType(variant.value).acceptImages);
};
/**
* When the current content type was filtered out (e.g. Video Pin in Generate),
* return the first remaining variant to switch to — or null when already valid.
*/
export const fallbackImageCapableVariant = (
contentType: string,
available: readonly { value: string }[],
): string | null => {
if (available.some((variant) => variant.value === contentType)) {
return null;
}
return available[0]?.value ?? null;
};