blob: 15fcc16f03fd3e5b6b21aaa9d447dace59597273 [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 }
19
20 .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
43 const displayExpression = expression.length > 50 ? expression.substring(0, 50) + "..." : expression;
44
45 return html`
46 <sketch-tool-card .open=${this.open} .toolCall=${this.toolCall}>
47 <span slot="summary" class="summary-text">
48 📱 ${displayExpression}
49 </span>
50 <div slot="input">
51 <div>Evaluate: <span class="expression-input">${expression}</span></div>
52 </div>
53 <div slot="result">
54 ${this.toolCall?.result_message?.tool_result
55 ? html`<pre>${this.toolCall.result_message.tool_result}</pre>`
56 : ""}
57 </div>
58 </sketch-tool-card>
59 `;
60 }
61}
62
63declare global {
64 interface HTMLElementTagNameMap {
65 "sketch-tool-card-browser-eval": SketchToolCardBrowserEval;
66 }
67}