import path from "node:path";
import { resolveModelAttempts } from "../../../application/model-attempts.js";
import { buildPathSummaryPrompt } from "../../../prompts/index.js";
import { ensureCliAttachmentPath } from "../../attachments.js";
export async function buildAssetModelAttempts({ ctx, kind, promptTokensForAuto, requiresVideoUnderstanding, lastSuccessfulCliProvider, }) {
    if (ctx.isFallbackModel) {
        const catalog = await ctx.getLiteLlmCatalog();
        return resolveModelAttempts({
            requestedModel: ctx.requestedModel,
            kind,
            promptTokens: promptTokensForAuto,
            desiredOutputTokens: ctx.desiredOutputTokens,
            requiresVideoUnderstanding,
            envForAuto: ctx.envForAuto,
            configForModelSelection: ctx.configForModelSelection,
            catalog,
            openrouterProvidersFromEnv: null,
            cliAvailability: ctx.cliAvailability,
            isImplicitAutoSelection: ctx.isImplicitAutoSelection,
            allowAutoCliFallback: ctx.allowAutoCliFallback,
            lastSuccessfulCliProvider,
            providerRuntime: ctx.summaryEngine.providerRuntime,
        });
    }
    /* v8 ignore next */
    if (!ctx.fixedModelSpec) {
        throw new Error("Internal error: missing fixed model spec");
    }
    return resolveModelAttempts({
        requestedModel: { kind: "fixed", ...ctx.fixedModelSpec },
        kind,
        promptTokens: promptTokensForAuto,
        desiredOutputTokens: ctx.desiredOutputTokens,
        requiresVideoUnderstanding,
        envForAuto: ctx.envForAuto,
        configForModelSelection: ctx.configForModelSelection,
        catalog: null,
        openrouterProvidersFromEnv: null,
        cliAvailability: ctx.cliAvailability,
        providerRuntime: ctx.summaryEngine.providerRuntime,
    });
}
export async function buildAssetCliContext({ ctx, args, attempts, attachmentsCount, summaryLengthTarget, }) {
    if (!attempts.some((attempt) => attempt.transport === "cli"))
        return null;
    if (attachmentsCount === 0)
        return null;
    const needsPathPrompt = args.attachment.kind === "image" || args.attachment.kind === "file";
    if (!needsPathPrompt)
        return null;
    const filePath = await ensureCliAttachmentPath({
        sourceKind: args.sourceKind,
        sourceLabel: args.sourceLabel,
        attachment: args.attachment,
    });
    const dir = path.dirname(filePath);
    const extraArgsByProvider = {
        gemini: ["--include-directories", dir],
        codex: args.attachment.kind === "image" ? ["-i", filePath] : undefined,
        opencode: ["--file", filePath],
    };
    return {
        promptOverride: buildPathSummaryPrompt({
            kindLabel: args.attachment.kind === "image" ? "image" : "file",
            filePath,
            filename: args.attachment.filename,
            mediaType: args.attachment.mediaType,
            summaryLength: summaryLengthTarget,
            outputLanguage: ctx.outputLanguage,
            promptOverride: ctx.promptOverride ?? null,
            lengthInstruction: ctx.lengthInstruction ?? null,
            languageInstruction: ctx.languageInstruction ?? null,
        }),
        allowTools: true,
        cwd: dir,
        extraArgsByProvider,
    };
}
//# sourceMappingURL=summary-attempts.js.map