blob: 8a1ec547351827c6499b07d647c8fa80ab3a559c [file] [log] [blame]
Josh Bleecher Snyder2d081192025-05-29 13:46:04 +00001import { css, html, LitElement } from "lit";
2import { customElement, property } from "lit/decorators.js";
3import { ToolCall } from "../types";
4
5@customElement("sketch-tool-card-browser-eval")
6export class SketchToolCardBrowserEval extends LitElement {
7 @property()
8 toolCall: ToolCall;
9
10 @property()
11 open: boolean;
12
13 static styles = css`
14 .summary-text {
15 font-family: monospace;
16 color: #444;
17 word-break: break-all;
18 }
Autoformatter71c73b52025-05-29 20:18:43 +000019
Josh Bleecher Snyder2d081192025-05-29 13:46:04 +000020 .expression-input {
21 font-family: monospace;
22 background: rgba(0, 0, 0, 0.05);
23 padding: 4px 8px;
24 border-radius: 4px;
25 display: inline-block;
26 word-break: break-all;
27 }
28 `;
29
30 render() {
31 // Parse the input to get expression
32 let expression = "";
33 try {
34 if (this.toolCall?.input) {
35 const input = JSON.parse(this.toolCall.input);
36 expression = input.expression || "";
37 }
38 } catch (e) {
39 console.error("Error parsing eval input:", e);
40 }
41
42 // Truncate expression for summary if too long
Autoformatter71c73b52025-05-29 20:18:43 +000043 const displayExpression =
44 expression.length > 50 ? expression.substring(0, 50) + "..." : expression;
Josh Bleecher Snyder2d081192025-05-29 13:46:04 +000045
46 return html`
47 <sketch-tool-card .open=${this.open} .toolCall=${this.toolCall}>
48 <span slot="summary" class="summary-text">
49 📱 ${displayExpression}
50 </span>
51 <div slot="input">
Autoformatter71c73b52025-05-29 20:18:43 +000052 <div>
53 Evaluate: <span class="expression-input">${expression}</span>
54 </div>
Josh Bleecher Snyder2d081192025-05-29 13:46:04 +000055 </div>
56 <div slot="result">
57 ${this.toolCall?.result_message?.tool_result
58 ? html`<pre>${this.toolCall.result_message.tool_result}</pre>`
59 : ""}
60 </div>
61 </sketch-tool-card>
62 `;
63 }
64}
65
66declare global {
67 interface HTMLElementTagNameMap {
68 "sketch-tool-card-browser-eval": SketchToolCardBrowserEval;
69 }
70}