blob: b480568d063b7a6e3dd151055fc38e0eca5da301 [file] [log] [blame]
Josh Bleecher Snyder31785ae2025-05-06 01:50:58 +00001import { css, html, LitElement } from "lit";
2import { unsafeHTML } from "lit/directives/unsafe-html.js";
3import { customElement, property } from "lit/decorators.js";
4import { ToolCall } from "../types";
5import { marked } from "marked";
6
7// Safely renders markdown with fallback to plain text on failure
8function renderMarkdown(markdownContent: string): string {
9 try {
10 return marked.parse(markdownContent, {
11 gfm: true,
12 breaks: true,
13 async: false,
14 }) as string;
15 } catch (error) {
16 console.error("Error rendering markdown:", error);
17 return markdownContent;
18 }
19}
20
Josh Bleecher Snyder74d690e2025-05-14 18:16:03 -070021@customElement("sketch-tool-card-about-sketch")
22export class SketchToolCardAboutSketch extends LitElement {
Josh Bleecher Snyder31785ae2025-05-06 01:50:58 +000023 @property() toolCall: ToolCall;
24 @property() open: boolean;
25
26 static styles = css`
27 .summary-text {
28 font-style: italic;
29 }
Josh Bleecher Snyder74d690e2025-05-14 18:16:03 -070030 .about-sketch-content {
Josh Bleecher Snyder31785ae2025-05-06 01:50:58 +000031 background: rgb(246, 248, 250);
32 border-radius: 6px;
33 padding: 12px;
34 margin-top: 10px;
35 max-height: 300px;
36 overflow-y: auto;
37 border: 1px solid #e1e4e8;
38 }
Josh Bleecher Snyder74d690e2025-05-14 18:16:03 -070039 .sketch-label {
Josh Bleecher Snyder31785ae2025-05-06 01:50:58 +000040 font-weight: bold;
41 color: #24292e;
42 }
43 .icon {
44 margin-right: 6px;
45 }
46 `;
47
48 render() {
Josh Bleecher Snyder31785ae2025-05-06 01:50:58 +000049 const resultText = this.toolCall?.result_message?.tool_result || "";
Autoformatter7fb34992025-05-13 02:23:55 +000050
Josh Bleecher Snyder31785ae2025-05-06 01:50:58 +000051 return html`
52 <sketch-tool-card .open=${this.open} .toolCall=${this.toolCall}>
53 <span slot="summary" class="summary-text">
Josh Bleecher Snyder74d690e2025-05-14 18:16:03 -070054 <span class="icon">📚</span> About Sketch
Josh Bleecher Snyder31785ae2025-05-06 01:50:58 +000055 </span>
56 <div slot="input">
Josh Bleecher Snyder74d690e2025-05-14 18:16:03 -070057 <div><span class="sketch-label"></span></div>
Josh Bleecher Snyder31785ae2025-05-06 01:50:58 +000058 </div>
59 ${this.toolCall?.result_message?.tool_result
60 ? html`<div slot="result">
Josh Bleecher Snyder74d690e2025-05-14 18:16:03 -070061 <div class="about-sketch-content">
Josh Bleecher Snyder31785ae2025-05-06 01:50:58 +000062 ${unsafeHTML(renderMarkdown(resultText))}
63 </div>
64 </div>`
65 : ""}
66 </sketch-tool-card>
67 `;
68 }
69}
70
71declare global {
72 interface HTMLElementTagNameMap {
Josh Bleecher Snyder74d690e2025-05-14 18:16:03 -070073 "sketch-tool-card-about-sketch": SketchToolCardAboutSketch;
Josh Bleecher Snyder31785ae2025-05-06 01:50:58 +000074 }
75}