export interface ProblemFramingImageFallbackOptions { hasReferenceImages: boolean execute: (useImages: boolean) => Promise shouldRetryWithoutImages: (error: unknown) => boolean onImageFallback?: (error: unknown) => void } export async function executeProblemFramingWithImageFallback( options: ProblemFramingImageFallbackOptions, ): Promise { try { return await options.execute(options.hasReferenceImages) } catch (error) { if (!options.hasReferenceImages || !options.shouldRetryWithoutImages(error)) { throw error } options.onImageFallback?.(error) return options.execute(false) } }