| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 1 | import { html } from "lit"; |
| Josh Bleecher Snyder | 2d08119 | 2025-05-29 13:46:04 +0000 | [diff] [blame] | 2 | import { customElement, property } from "lit/decorators.js"; |
| 3 | import { ToolCall } from "../types"; |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 4 | import { SketchTailwindElement } from "./sketch-tailwind-element"; |
| 5 | import "./sketch-tool-card-base"; |
| Josh Bleecher Snyder | 2d08119 | 2025-05-29 13:46:04 +0000 | [diff] [blame] | 6 | |
| 7 | @customElement("sketch-tool-card-browser-eval") |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 8 | export class SketchToolCardBrowserEval extends SketchTailwindElement { |
| Josh Bleecher Snyder | 2d08119 | 2025-05-29 13:46:04 +0000 | [diff] [blame] | 9 | @property() |
| 10 | toolCall: ToolCall; |
| 11 | |
| 12 | @property() |
| 13 | open: boolean; |
| 14 | |
| Josh Bleecher Snyder | 2d08119 | 2025-05-29 13:46:04 +0000 | [diff] [blame] | 15 | 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 |
| Autoformatter | 71c73b5 | 2025-05-29 20:18:43 +0000 | [diff] [blame] | 28 | const displayExpression = |
| 29 | expression.length > 50 ? expression.substring(0, 50) + "..." : expression; |
| Josh Bleecher Snyder | 2d08119 | 2025-05-29 13:46:04 +0000 | [diff] [blame] | 30 | |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 31 | 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 Snyder | 2d08119 | 2025-05-29 13:46:04 +0000 | [diff] [blame] | 49 | return html` |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 50 | <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 Snyder | 2d08119 | 2025-05-29 13:46:04 +0000 | [diff] [blame] | 58 | `; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | declare global { |
| 63 | interface HTMLElementTagNameMap { |
| 64 | "sketch-tool-card-browser-eval": SketchToolCardBrowserEval; |
| 65 | } |
| 66 | } |