| Pokey Rule | ef58e06 | 2025-05-07 13:32:58 +0100 | [diff] [blame^] | 1 | import { LitElement, css, html } from "lit"; |
| 2 | import { customElement, property } from "lit/decorators.js"; |
| 3 | import { ToolCall } from "../types"; |
| 4 | |
| 5 | // Common styles shared across all tool cards |
| 6 | export const commonStyles = css` |
| 7 | pre { |
| 8 | background: rgb(236, 236, 236); |
| 9 | color: black; |
| 10 | padding: 0.5em; |
| 11 | border-radius: 4px; |
| 12 | white-space: pre-wrap; |
| 13 | word-break: break-word; |
| 14 | max-width: 100%; |
| 15 | width: 100%; |
| 16 | box-sizing: border-box; |
| 17 | overflow-wrap: break-word; |
| 18 | } |
| 19 | .summary-text { |
| 20 | overflow: hidden; |
| 21 | text-overflow: ellipsis; |
| 22 | white-space: nowrap; |
| 23 | max-width: 100%; |
| 24 | font-family: monospace; |
| 25 | } |
| 26 | `; |
| 27 | |
| 28 | @customElement("sketch-tool-card-bash") |
| 29 | export class SketchToolCardBash extends LitElement { |
| 30 | @property() toolCall: ToolCall; |
| 31 | @property() open: boolean; |
| 32 | |
| 33 | static styles = [ |
| 34 | commonStyles, |
| 35 | css` |
| 36 | .input { |
| 37 | display: flex; |
| 38 | width: 100%; |
| 39 | flex-direction: column; |
| 40 | } |
| 41 | .input pre { |
| 42 | width: 100%; |
| 43 | margin-bottom: 0; |
| 44 | border-radius: 4px 4px 0 0; |
| 45 | box-sizing: border-box; |
| 46 | } |
| 47 | .result pre { |
| 48 | margin-top: 0; |
| 49 | color: #555; |
| 50 | border-radius: 0 0 4px 4px; |
| 51 | width: 100%; |
| 52 | box-sizing: border-box; |
| 53 | } |
| 54 | .result pre.scrollable-on-hover { |
| 55 | max-height: 300px; |
| 56 | overflow-y: auto; |
| 57 | } |
| 58 | .tool-call-result-container { |
| 59 | width: 100%; |
| 60 | position: relative; |
| 61 | } |
| 62 | .background-badge { |
| 63 | display: inline-block; |
| 64 | background-color: #6200ea; |
| 65 | color: white; |
| 66 | font-size: 10px; |
| 67 | font-weight: bold; |
| 68 | padding: 2px 6px; |
| 69 | border-radius: 10px; |
| 70 | margin-left: 8px; |
| 71 | vertical-align: middle; |
| 72 | } |
| 73 | .command-wrapper { |
| 74 | display: inline-block; |
| 75 | max-width: 100%; |
| 76 | overflow: hidden; |
| 77 | text-overflow: ellipsis; |
| 78 | white-space: nowrap; |
| 79 | } |
| 80 | `, |
| 81 | ]; |
| 82 | |
| 83 | render() { |
| 84 | const inputData = JSON.parse(this.toolCall?.input || "{}"); |
| 85 | const isBackground = inputData?.background === true; |
| 86 | const backgroundIcon = isBackground ? "🔄 " : ""; |
| 87 | |
| 88 | return html` <sketch-tool-card |
| 89 | .open=${this.open} |
| 90 | .toolCall=${this.toolCall} |
| 91 | > |
| 92 | <span slot="summary" class="summary-text"> |
| 93 | <div class="command-wrapper"> |
| 94 | ${backgroundIcon}${inputData?.command} |
| 95 | </div> |
| 96 | </span> |
| 97 | <div slot="input" class="input"> |
| 98 | <div class="tool-call-result-container"> |
| 99 | <pre>${backgroundIcon}${inputData?.command}</pre> |
| 100 | </div> |
| 101 | </div> |
| 102 | ${this.toolCall?.result_message?.tool_result |
| 103 | ? html`<div slot="result" class="result"> |
| 104 | <div class="tool-call-result-container"> |
| 105 | <pre class="tool-call-result"> |
| 106 | ${this.toolCall?.result_message.tool_result}</pre |
| 107 | > |
| 108 | </div> |
| 109 | </div>` |
| 110 | : ""} |
| 111 | </sketch-tool-card>`; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | declare global { |
| 116 | interface HTMLElementTagNameMap { |
| 117 | "sketch-tool-card-bash": SketchToolCardBash; |
| 118 | } |
| 119 | } |