import { formatAdaptiveNumber, formatDurationMs } from "../utils/format.js";
import { buildCompactPreviewLines } from "../utils/tool_preview.js";
export function truncateOutputLines(lines, maxLines) {
    if (maxLines <= 0)
        return [];
    if (lines.length <= maxLines)
        return lines;
    const keptCount = Math.max(0, maxLines - 1);
    const remaining = Math.max(1, lines.length - keptCount);
    const marker = `…${remaining} more lines…`;
    return [...lines.slice(0, keptCount), marker];
}
export function buildSubagentUiText({ output, statusText, maxOutputLines, maxPreviewLines, fullText, }) {
    const trimmed = output.trimEnd();
    const outputLines = trimmed ? trimmed.split("\n") : [];
    const truncatedLines = typeof maxOutputLines === "number"
        ? truncateOutputLines(outputLines, maxOutputLines)
        : outputLines;
    const previewLimit = maxPreviewLines ?? maxOutputLines ?? truncatedLines.length;
    const preview = buildCompactPreviewLines(truncatedLines, {
        maxLines: previewLimit,
        totalLines: truncatedLines.length,
        unitLabel: "lines",
        indent: 0,
    });
    const previewLines = preview ? preview.split("\n").map((text) => ({ text })) : [];
    const trimmedFullText = fullText?.trimEnd();
    const fullLines = trimmedFullText
        ? trimmedFullText.split("\n").map((text) => ({ text }))
        : truncatedLines.map((text) => ({ text }));
    const statusLine = statusText || undefined;
    return {
        previewLines,
        statusLine,
        fullLines,
    };
}
export function formatSubagentStatusLine({ costTotal, durationMs }) {
    const cost = `$${formatAdaptiveNumber(costTotal, 2, 5)}`;
    const duration = formatDurationMs(durationMs);
    return `cost ${cost} · duration ${duration}`;
}
//# sourceMappingURL=subagent_ui.js.map