| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 1 | import { html } from "lit"; |
| Josh Bleecher Snyder | 31785ae | 2025-05-06 01:50:58 +0000 | [diff] [blame] | 2 | import { unsafeHTML } from "lit/directives/unsafe-html.js"; |
| 3 | import { customElement, property } from "lit/decorators.js"; |
| 4 | import { ToolCall } from "../types"; |
| 5 | import { marked } from "marked"; |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 6 | import { SketchTailwindElement } from "./sketch-tailwind-element"; |
| 7 | import "./sketch-tool-card-base"; |
| Josh Bleecher Snyder | 31785ae | 2025-05-06 01:50:58 +0000 | [diff] [blame] | 8 | |
| 9 | // Safely renders markdown with fallback to plain text on failure |
| 10 | function renderMarkdown(markdownContent: string): string { |
| 11 | try { |
| 12 | return marked.parse(markdownContent, { |
| 13 | gfm: true, |
| 14 | breaks: true, |
| 15 | async: false, |
| 16 | }) as string; |
| 17 | } catch (error) { |
| 18 | console.error("Error rendering markdown:", error); |
| 19 | return markdownContent; |
| 20 | } |
| 21 | } |
| 22 | |
| Josh Bleecher Snyder | 74d690e | 2025-05-14 18:16:03 -0700 | [diff] [blame] | 23 | @customElement("sketch-tool-card-about-sketch") |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 24 | export class SketchToolCardAboutSketch extends SketchTailwindElement { |
| Josh Bleecher Snyder | 31785ae | 2025-05-06 01:50:58 +0000 | [diff] [blame] | 25 | @property() toolCall: ToolCall; |
| 26 | @property() open: boolean; |
| 27 | |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 28 | // Styles now handled by Tailwind classes in template |
| Josh Bleecher Snyder | 31785ae | 2025-05-06 01:50:58 +0000 | [diff] [blame] | 29 | |
| 30 | render() { |
| Josh Bleecher Snyder | 31785ae | 2025-05-06 01:50:58 +0000 | [diff] [blame] | 31 | const resultText = this.toolCall?.result_message?.tool_result || ""; |
| Autoformatter | 7fb3499 | 2025-05-13 02:23:55 +0000 | [diff] [blame] | 32 | |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 33 | const summaryContent = html`<span class="italic"> |
| 34 | <span class="mr-1.5">📚</span> About Sketch |
| 35 | </span>`; |
| 36 | const inputContent = html`<div> |
| banksean | 1ee0bc6 | 2025-07-22 23:24:18 +0000 | [diff] [blame] | 37 | <span class="font-bold text-gray-800 dark:text-gray-200"></span> |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 38 | </div>`; |
| 39 | const resultContent = this.toolCall?.result_message?.tool_result |
| 40 | ? html`<div |
| banksean | 1ee0bc6 | 2025-07-22 23:24:18 +0000 | [diff] [blame] | 41 | class="bg-gray-50 dark:bg-gray-700 rounded-md p-3 mt-2.5 max-h-[300px] overflow-y-auto border border-gray-200 dark:border-gray-600 text-gray-900 dark:text-gray-100" |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 42 | > |
| 43 | ${unsafeHTML(renderMarkdown(resultText))} |
| 44 | </div>` |
| 45 | : ""; |
| 46 | |
| Josh Bleecher Snyder | 31785ae | 2025-05-06 01:50:58 +0000 | [diff] [blame] | 47 | return html` |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 48 | <sketch-tool-card-base |
| 49 | .open=${this.open} |
| 50 | .toolCall=${this.toolCall} |
| 51 | .summaryContent=${summaryContent} |
| 52 | .inputContent=${inputContent} |
| 53 | .resultContent=${resultContent} |
| 54 | > |
| 55 | </sketch-tool-card-base> |
| Josh Bleecher Snyder | 31785ae | 2025-05-06 01:50:58 +0000 | [diff] [blame] | 56 | `; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | declare global { |
| 61 | interface HTMLElementTagNameMap { |
| Josh Bleecher Snyder | 74d690e | 2025-05-14 18:16:03 -0700 | [diff] [blame] | 62 | "sketch-tool-card-about-sketch": SketchToolCardAboutSketch; |
| Josh Bleecher Snyder | 31785ae | 2025-05-06 01:50:58 +0000 | [diff] [blame] | 63 | } |
| 64 | } |