blob: 935b5e2024bcf0216decf7eb84072786fb988346 [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
banksean1ee0bc62025-07-22 23:24:18 +000031 const summaryContent = html`<span
32 class="font-mono text-gray-700 dark:text-gray-300 break-all"
33 >
banksean333aa672025-07-13 19:49:21 +000034 📱 ${displayExpression}
35 </span>`;
36 const inputContent = html`<div>
37 Evaluate:
38 <span
banksean1ee0bc62025-07-22 23:24:18 +000039 class="font-mono bg-black/[0.05] dark:bg-white/[0.1] dark:bg-white/[0.1] px-2 py-1 rounded inline-block break-all"
banksean333aa672025-07-13 19:49:21 +000040 >${expression}</span
41 >
42 </div>`;
43 const resultContent = this.toolCall?.result_message?.tool_result
44 ? html`<pre
banksean1ee0bc62025-07-22 23:24:18 +000045 class="bg-gray-200 dark:bg-gray-700 text-black dark:text-gray-100 p-2 rounded whitespace-pre-wrap break-words max-w-full w-full box-border"
banksean333aa672025-07-13 19:49:21 +000046 >
47${this.toolCall.result_message.tool_result}</pre
48 >`
49 : "";
50
Josh Bleecher Snyder2d081192025-05-29 13:46:04 +000051 return html`
banksean333aa672025-07-13 19:49:21 +000052 <sketch-tool-card-base
53 .open=${this.open}
54 .toolCall=${this.toolCall}
55 .summaryContent=${summaryContent}
56 .inputContent=${inputContent}
57 .resultContent=${resultContent}
58 >
59 </sketch-tool-card-base>
Josh Bleecher Snyder2d081192025-05-29 13:46:04 +000060 `;
61 }
62}
63
64declare global {
65 interface HTMLElementTagNameMap {
66 "sketch-tool-card-browser-eval": SketchToolCardBrowserEval;
67 }
68}