blob: 4030b02b747d38e80c6466478355af5814128148 [file] [log] [blame]
banksean333aa672025-07-13 19:49:21 +00001import { html } from "lit";
Josh Bleecher Snyder2d081192025-05-29 13:46:04 +00002import { customElement, property } from "lit/decorators.js";
3import { ToolCall } from "../types";
banksean333aa672025-07-13 19:49:21 +00004import { SketchTailwindElement } from "./sketch-tailwind-element";
5import "./sketch-tool-card-base";
Josh Bleecher Snyder2d081192025-05-29 13:46:04 +00006
7@customElement("sketch-tool-card-browser-eval")
banksean333aa672025-07-13 19:49:21 +00008export class SketchToolCardBrowserEval extends SketchTailwindElement {
Josh Bleecher Snyder2d081192025-05-29 13:46:04 +00009 @property()
10 toolCall: ToolCall;
11
12 @property()
13 open: boolean;
14
Josh Bleecher Snyder2d081192025-05-29 13:46:04 +000015 render() {
16 // Parse the input to get expression
17 let expression = "";
18 try {
19 if (this.toolCall?.input) {
20 const input = JSON.parse(this.toolCall.input);
21 expression = input.expression || "";
22 }
23 } catch (e) {
24 console.error("Error parsing eval input:", e);
25 }
26
27 // Truncate expression for summary if too long
Autoformatter71c73b52025-05-29 20:18:43 +000028 const displayExpression =
29 expression.length > 50 ? expression.substring(0, 50) + "..." : expression;
Josh Bleecher Snyder2d081192025-05-29 13:46:04 +000030
banksean333aa672025-07-13 19:49:21 +000031 const summaryContent = html`<span class="font-mono text-gray-700 break-all">
32 📱 ${displayExpression}
33 </span>`;
34 const inputContent = html`<div>
35 Evaluate:
36 <span
37 class="font-mono bg-black/[0.05] px-2 py-1 rounded inline-block break-all"
38 >${expression}</span
39 >
40 </div>`;
41 const resultContent = this.toolCall?.result_message?.tool_result
42 ? html`<pre
43 class="bg-gray-200 text-black p-2 rounded whitespace-pre-wrap break-words max-w-full w-full box-border"
44 >
45${this.toolCall.result_message.tool_result}</pre
46 >`
47 : "";
48
Josh Bleecher Snyder2d081192025-05-29 13:46:04 +000049 return html`
banksean333aa672025-07-13 19:49:21 +000050 <sketch-tool-card-base
51 .open=${this.open}
52 .toolCall=${this.toolCall}
53 .summaryContent=${summaryContent}
54 .inputContent=${inputContent}
55 .resultContent=${resultContent}
56 >
57 </sketch-tool-card-base>
Josh Bleecher Snyder2d081192025-05-29 13:46:04 +000058 `;
59 }
60}
61
62declare global {
63 interface HTMLElementTagNameMap {
64 "sketch-tool-card-browser-eval": SketchToolCardBrowserEval;
65 }
66}