
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="0a28e6df-2e68-5d06-bc63-e142990cfd0d")}catch(e){}}();
import { mkdtemp, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { basename, extname, join } from "node:path";
const IMAGE_EXTENSION_BY_MIME_TYPE = {
    "image/gif": ".gif",
    "image/jpeg": ".jpg",
    "image/png": ".png",
    "image/svg+xml": ".svg",
    "image/webp": ".webp",
};
function sanitizeFileNameSegment(value) {
    const normalized = value.normalize("NFKD").replaceAll(/[^A-Za-z0-9._-]+/g, "-");
    const trimmed = normalized.replaceAll(/^-+|-+$/g, "");
    return trimmed.length > 0 ? trimmed : "image";
}
function resolveTaskImageExtension(image) {
    const name = image.name?.trim();
    const nameExtension = name ? extname(name).toLowerCase() : "";
    if (nameExtension) {
        return nameExtension;
    }
    return IMAGE_EXTENSION_BY_MIME_TYPE[image.mimeType.toLowerCase()] ?? "";
}
function buildTaskImageFileName(image, index) {
    const displayName = image.name?.trim();
    const extension = resolveTaskImageExtension(image);
    const baseName = displayName
        ? basename(displayName, extname(displayName))
        : `image-${index + 1}`;
    return `${String(index + 1).padStart(2, "0")}-${sanitizeFileNameSegment(baseName)}${extension}`;
}
function buildTaskPromptWithImagePaths(prompt, imageFileEntries) {
    const lines = [
        "Attached reference images:",
        ...imageFileEntries.map((entry, index) => {
            const displaySuffix = entry.name?.trim() ? ` (${entry.name.trim()})` : "";
            return `${index + 1}. ${entry.path}${displaySuffix}`;
        }),
    ];
    const trimmedPrompt = prompt.trim();
    if (!trimmedPrompt) {
        return lines.join("\n");
    }
    return [...lines, "", "Task:", trimmedPrompt].join("\n");
}
export async function prepareTaskPromptWithImages(input) {
    const images = input.images?.filter((image) => image.data.trim().length > 0) ?? [];
    if (images.length === 0) {
        return input.prompt;
    }
    const tempDir = await mkdtemp(join(tmpdir(), "kanban-task-images-"));
    const imageFileEntries = await Promise.all(images.map(async (image, index) => {
        const filePath = join(tempDir, buildTaskImageFileName(image, index));
        await writeFile(filePath, Buffer.from(image.data, "base64"));
        return {
            path: filePath,
            name: image.name,
        };
    }));
    return buildTaskPromptWithImagePaths(input.prompt, imageFileEntries);
}
//# sourceMappingURL=task-image-prompt.js.map
//# debugId=0a28e6df-2e68-5d06-bc63-e142990cfd0d
