import { icon } from "@mariozechner/mini-lit"; import { html } from "lit"; import { ref } from "lit/directives/ref.js"; import { ChevronsUpDown, ChevronUp, Loader } from "lucide"; // Registry of tool renderers export const toolRenderers = new Map(); /** * Register a custom tool renderer */ export function registerToolRenderer(toolName, renderer) { toolRenderers.set(toolName, renderer); } /** * Get a tool renderer by name */ export function getToolRenderer(toolName) { return toolRenderers.get(toolName); } /** * Helper to render a header for tool renderers * Shows icon on left when complete/error, spinner on right when in progress */ export function renderHeader(state, toolIcon, text) { const statusIcon = (iconComponent, color) => html `${icon(iconComponent, "sm")}`; switch (state) { case "inprogress": return html `
${statusIcon(toolIcon, "text-foreground")} ${text}
${statusIcon(Loader, "text-foreground animate-spin")}
`; case "complete": return html `
${statusIcon(toolIcon, "text-green-600 dark:text-green-500")} ${text}
`; case "error": return html `
${statusIcon(toolIcon, "text-destructive")} ${text}
`; } } /** * Helper to render a collapsible header for tool renderers * Same as renderHeader but with a chevron button that toggles visibility of content */ export function renderCollapsibleHeader(state, toolIcon, text, contentRef, chevronRef, defaultExpanded = false) { const statusIcon = (iconComponent, color) => html `${icon(iconComponent, "sm")}`; const toggleContent = (e) => { e.preventDefault(); const content = contentRef.value; const chevron = chevronRef.value; if (content && chevron) { const isCollapsed = content.classList.contains("max-h-0"); if (isCollapsed) { content.classList.remove("max-h-0"); content.classList.add("max-h-[2000px]", "mt-3"); // Show ChevronUp, hide ChevronsUpDown const upIcon = chevron.querySelector(".chevron-up"); const downIcon = chevron.querySelector(".chevrons-up-down"); if (upIcon && downIcon) { upIcon.classList.remove("hidden"); downIcon.classList.add("hidden"); } } else { content.classList.remove("max-h-[2000px]", "mt-3"); content.classList.add("max-h-0"); // Show ChevronsUpDown, hide ChevronUp const upIcon = chevron.querySelector(".chevron-up"); const downIcon = chevron.querySelector(".chevrons-up-down"); if (upIcon && downIcon) { upIcon.classList.add("hidden"); downIcon.classList.remove("hidden"); } } } }; const toolIconColor = state === "complete" ? "text-green-600 dark:text-green-500" : state === "error" ? "text-destructive" : "text-foreground"; return html ` `; } //# sourceMappingURL=renderer-registry.js.map