/**
 * Tool HTML renderer for custom tools in HTML export.
 *
 * Renders custom tool calls and results to HTML by invoking their TUI renderers
 * and converting the ANSI output to HTML.
 */
import { reportShellRenderError } from '../render-errors.js';
import { getToolPresentation } from '../tools/presentation/index.js';
import { ansiLinesToHtml } from './ansi-to-html.js';
export function createToolHtmlRenderer(deps) {
    const { getToolDefinition, theme, width = 100 } = deps;
    return {
        renderCall(toolName, args) {
            try {
                const toolDef = getToolDefinition(toolName);
                const presentation = getToolPresentation(toolDef);
                if (!presentation?.renderCall) {
                    return undefined;
                }
                const component = presentation.renderCall(args, { expanded: true, isPartial: false }, theme);
                if (!component) {
                    return undefined;
                }
                return ansiLinesToHtml(component.render(width));
            }
            catch (error) {
                reportShellRenderError(`html-tool-call:${toolName}`, error);
                return undefined;
            }
        },
        renderResult(toolName, result, details, isError) {
            try {
                const toolDef = getToolDefinition(toolName);
                const presentation = getToolPresentation(toolDef);
                if (!presentation?.renderResult) {
                    return undefined;
                }
                const agentToolResult = {
                    content: result,
                    details,
                    isError
                };
                const component = presentation.renderResult(agentToolResult, { expanded: true, isPartial: false }, theme);
                if (!component) {
                    return undefined;
                }
                return ansiLinesToHtml(component.render(width));
            }
            catch (error) {
                reportShellRenderError(`html-tool-result:${toolName}`, error);
                return undefined;
            }
        }
    };
}
//# sourceMappingURL=tool-renderer.js.map