blob: fc0fe09b77b88ebc9083babf6e3d894b01d95734 [file] [log] [blame]
Pokey Ruleef58e062025-05-07 13:32:58 +01001import { LitElement, css, html } from "lit";
2import { customElement, property } from "lit/decorators.js";
3import { unsafeHTML } from "lit/directives/unsafe-html.js";
4import { marked } from "marked";
5import { ToolCall } from "../types";
6
7@customElement("sketch-tool-card-think")
8export class SketchToolCardThink extends LitElement {
9 @property() toolCall: ToolCall;
10 @property() open: boolean;
11
12 static styles = css`
13 .thought-bubble {
14 overflow-x: auto;
15 margin-bottom: 3px;
16 font-family: monospace;
17 padding: 3px 5px;
18 background: rgb(236, 236, 236);
19 border-radius: 6px;
20 user-select: text;
21 cursor: text;
22 -webkit-user-select: text;
23 -moz-user-select: text;
24 -ms-user-select: text;
25 font-size: 13px;
26 line-height: 1.3;
27 }
28 .summary-text {
29 overflow: hidden;
30 text-overflow: ellipsis;
31 font-family: monospace;
32 }
33 `;
34
35 render() {
36 return html`
37 <sketch-tool-card .open=${this.open} .toolCall=${this.toolCall}>
38 <span slot="summary" class="summary-text">
39 ${JSON.parse(this.toolCall?.input)?.thoughts?.split("\n")[0]}
40 </span>
41 <div slot="input" class="thought-bubble">
42 <div class="markdown-content">
43 ${unsafeHTML(
44 renderMarkdown(JSON.parse(this.toolCall?.input)?.thoughts),
45 )}
46 </div>
47 </div>
48 </sketch-tool-card>
49 `;
50 }
51}
52
53declare global {
54 interface HTMLElementTagNameMap {
55 "sketch-tool-card-think": SketchToolCardThink;
56 }
57}
58
59function renderMarkdown(markdownContent: string): string {
60 try {
61 return marked.parse(markdownContent, {
62 gfm: true,
63 breaks: true,
64 async: false,
65 }) as string;
66 } catch (error) {
67 console.error("Error rendering markdown:", error);
68 return markdownContent;
69 }
70}