import { isProgress, type PiToolShell, type ToolContext } from "../../types.ts"; import { toolCallStatus } from "../tool-call.ts"; import { toolExpandHint } from "../tool-labels.ts"; import { toolProgressView, toolProgressLayout } from "../tool-progress.ts"; import { toolResource } from "../tool-resource.ts"; import { muted as toolMuted, renderText as toolText } from "../tui.ts"; import type { RenderComponent, RenderTheme } from "../types.ts"; export function renderWebMapResult( result: PiToolShell, expanded = false, theme?: RenderTheme, ): RenderComponent { const envelope = result.details as Partial< ToolContext<{ urls?: { url: string; source?: string; title?: string }[] }> >; if (isProgress(envelope)) return toolProgressView("web_map", envelope, theme, { allowIcons: false }); const urls = Array.isArray(envelope.data?.urls) ? envelope.data.urls : []; const summary = toolCallStatus(`${urls.length} URL(s)`, [!expanded && toolExpandHint], theme); if (urls.length === 0) return toolText(`${summary}\n\n${toolMuted("No URLs discovered.", theme)}`, { padToWidth: true, }); return toolProgressLayout({ renderContent(width) { const rows = urls .slice(0, expanded ? 50 : 12) .map((entry) => toolResource({ url: entry.url, badge: entry.source, width, theme })); if (urls.length > rows.length) rows.push(toolMuted(`… ${urls.length - rows.length} more urls`, theme)); return `${summary}\n${rows.join("\n")}`; }, expanded, responseId: envelope.responseId, padToWidth: true, }); }