From 59b36dc6d0d01873f911db27389598c81a20fd9f Mon Sep 17 00:00:00 2001 From: dazzatronus Date: Fri, 28 Aug 2026 15:40:46 +1000 Subject: [PATCH] refactor: lift generation type and prompt helpers into shared utils --- src/core/shared/ai-asset-utils.ts | 13 +++++++++++++ src/core/ui/generate-toolbar.ts | 13 +------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/core/shared/ai-asset-utils.ts b/src/core/shared/ai-asset-utils.ts index d0a18562..99ff6b47 100644 --- a/src/core/shared/ai-asset-utils.ts +++ b/src/core/shared/ai-asset-utils.ts @@ -212,3 +212,16 @@ export function truncatePrompt(prompt: string, maxLength = 60): string { } return `${prompt.substring(0, maxLength - 3)}...`; } + +/** Asset type → the media kind a generator produces. Folds the legacy aliases onto the unified types. */ +export const GENERATION_TYPE: Readonly> = { + image: "image", + video: "video", + audio: "audio", + "text-to-image": "image", + "image-to-video": "video", + "text-to-speech": "audio" +}; + +/** The legacy speech asset keeps its prompt under `text`. */ +export const promptProperty = (asset: { type: string }): "prompt" | "text" => (asset.type === "text-to-speech" ? "text" : "prompt"); diff --git a/src/core/ui/generate-toolbar.ts b/src/core/ui/generate-toolbar.ts index ae4f99f6..27972bb5 100644 --- a/src/core/ui/generate-toolbar.ts +++ b/src/core/ui/generate-toolbar.ts @@ -3,33 +3,22 @@ import { isGenerationOptionValueValid, missingGenerationOptions, reconcileGenerationOptions, - type GenerationAssetType, type GenerationModelDefinition, type GenerationOptionDefinition } from "@core/generation/model-catalogue"; import { MERGE_FIELD_TEST_PATTERN } from "@core/merge/merge-field-service"; -import { canCarryPrompt } from "@core/shared/ai-asset-utils"; +import { canCarryPrompt, GENERATION_TYPE, promptProperty } from "@core/shared/ai-asset-utils"; import { injectShotstackStyles } from "@styles/inject"; import { BaseToolbar, TOOLBAR_ICONS } from "./base-toolbar"; const PROMPT_DEBOUNCE_MS = 300; -const GENERATION_TYPE: Readonly> = { - image: "image", - video: "video", - audio: "audio", - "text-to-image": "image", - "image-to-video": "video", - "text-to-speech": "audio" -}; - const OPTION_INPUT_TYPE: Readonly> = { boolean: "checkbox", integer: "number", string: "text" }; -const promptProperty = (asset: { type: string }): "prompt" | "text" => (asset.type === "text-to-speech" ? "text" : "prompt"); const record = (value: unknown): Record => typeof value === "object" && value !== null && !Array.isArray(value) ? (value as Record) : {};