/**
 * Multimodal content-block builders for helper LLM calls.
 *
 * Normal Shortcut proxy helper LLM calls send provider-family blocks to the
 * shared helper stream proxy:
 * - Claude/Haiku: Anthropic-native image/document blocks.
 * - Gemini/non-Anthropic: LangChain multimodal blocks (`image_url`, `media`).
 *
 * Private-gateway helper calls instead ask for PI semantic blocks so the worker
 * can serialize the same attachment into Anthropic/OpenAI provider APIs.
 */
import { SANDBOX_LLM_HAIKU_MODEL, SANDBOX_LLM_IMAGE_EXTENSIONS, SANDBOX_LLM_TEXT_EXTENSIONS } from '../sandbox-llm/index.js';
import { bytesToBase64, bytesToUtf8 } from './base64.js';
import { lowerExt } from './sandbox-paths.js';
export const MultimodalContentBlockFormat = {
    Anthropic: 'anthropic',
    ByModel: 'by_model',
    Ai: 'ai'
};
/** Normal Shortcut proxy Gemini/non-Anthropic shape: LangChain multimodal blocks. */
export function buildGeminiBlock(input) {
    const ext = lowerExt(input.filePath);
    const imageMedia = SANDBOX_LLM_IMAGE_EXTENSIONS[ext];
    if (ext === '.pdf') {
        return {
            type: 'media',
            mime_type: 'application/pdf',
            data: bytesToBase64(input.bytes)
        };
    }
    if (imageMedia) {
        return {
            type: 'image_url',
            image_url: { url: `data:${imageMedia};base64,${bytesToBase64(input.bytes)}` }
        };
    }
    if (SANDBOX_LLM_TEXT_EXTENSIONS.has(ext)) {
        return { type: 'text', text: `--- ${input.filePath} ---\n${bytesToUtf8(input.bytes)}` };
    }
    return { error: `Unsupported file type for ${input.filePath}` };
}
/** Normal Shortcut proxy Claude/Haiku shape: Anthropic-native multimodal blocks. */
export function buildAnthropicBlock(input) {
    const ext = lowerExt(input.filePath);
    const imageMedia = SANDBOX_LLM_IMAGE_EXTENSIONS[ext];
    if (ext === '.pdf') {
        return {
            type: 'document',
            source: {
                type: 'base64',
                media_type: 'application/pdf',
                data: bytesToBase64(input.bytes)
            }
        };
    }
    if (imageMedia) {
        return {
            type: 'image',
            source: {
                type: 'base64',
                media_type: imageMedia,
                data: bytesToBase64(input.bytes)
            }
        };
    }
    if (SANDBOX_LLM_TEXT_EXTENSIONS.has(ext)) {
        return { type: 'text', text: `--- ${input.filePath} ---\n${bytesToUtf8(input.bytes)}` };
    }
    return { error: `Unsupported file type for ${input.filePath}` };
}
/** Private-gateway worker shape: provider-neutral PI blocks before transport conversion. */
export function buildAiBlock(input) {
    const ext = lowerExt(input.filePath);
    const imageMedia = SANDBOX_LLM_IMAGE_EXTENSIONS[ext];
    if (imageMedia) {
        return {
            type: 'image',
            data: bytesToBase64(input.bytes),
            mimeType: imageMedia
        };
    }
    if (SANDBOX_LLM_TEXT_EXTENSIONS.has(ext)) {
        return { type: 'text', text: `--- ${input.filePath} ---\n${bytesToUtf8(input.bytes)}` };
    }
    if (ext === '.pdf') {
        return {
            data: bytesToBase64(input.bytes),
            mimeType: 'application/pdf',
            type: 'document'
        };
    }
    return { error: `Unsupported file type for ${input.filePath}` };
}
/** Dispatch normal proxy blocks by model id: Haiku -> Anthropic, everything else -> Gemini. */
export function buildContentBlock(model, input, format = MultimodalContentBlockFormat.ByModel) {
    if (format === MultimodalContentBlockFormat.Ai) {
        return buildAiBlock(input);
    }
    if (format === MultimodalContentBlockFormat.Anthropic) {
        return buildAnthropicBlock(input);
    }
    return model === SANDBOX_LLM_HAIKU_MODEL ? buildAnthropicBlock(input) : buildGeminiBlock(input);
}
//# sourceMappingURL=multimodal.js.map