| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 1 | import { css, html, LitElement } from "lit"; |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 2 | import { unsafeHTML } from "lit/directives/unsafe-html.js"; |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 3 | import { customElement, property, state } from "lit/decorators.js"; |
| Autoformatter | 7e5fe3c | 2025-06-04 22:24:53 +0000 | [diff] [blame] | 4 | import { |
| 5 | ToolCall, |
| 6 | MultipleChoiceOption, |
| 7 | MultipleChoiceParams, |
| 8 | State, |
| 9 | } from "../types"; |
| Philip Zeyliger | 53ab245 | 2025-06-04 17:49:33 +0000 | [diff] [blame] | 10 | import { marked, MarkedOptions, Renderer } from "marked"; |
| 11 | import DOMPurify from "dompurify"; |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 12 | |
| Philip Zeyliger | 53ab245 | 2025-06-04 17:49:33 +0000 | [diff] [blame] | 13 | // Shared utility function for markdown rendering with DOMPurify sanitization |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 14 | function renderMarkdown(markdownContent: string): string { |
| 15 | try { |
| Philip Zeyliger | 53ab245 | 2025-06-04 17:49:33 +0000 | [diff] [blame] | 16 | // Parse markdown with default settings |
| 17 | const htmlOutput = marked.parse(markdownContent, { |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 18 | gfm: true, |
| 19 | breaks: true, |
| 20 | async: false, |
| 21 | }) as string; |
| Philip Zeyliger | 53ab245 | 2025-06-04 17:49:33 +0000 | [diff] [blame] | 22 | |
| 23 | // Sanitize the output HTML with DOMPurify |
| 24 | return DOMPurify.sanitize(htmlOutput, { |
| 25 | // Allow common safe HTML elements |
| 26 | ALLOWED_TAGS: [ |
| 27 | "p", |
| 28 | "br", |
| 29 | "strong", |
| 30 | "em", |
| 31 | "b", |
| 32 | "i", |
| 33 | "u", |
| 34 | "s", |
| 35 | "code", |
| 36 | "pre", |
| 37 | "h1", |
| 38 | "h2", |
| 39 | "h3", |
| 40 | "h4", |
| 41 | "h5", |
| 42 | "h6", |
| 43 | "ul", |
| 44 | "ol", |
| 45 | "li", |
| 46 | "blockquote", |
| 47 | "a", |
| 48 | ], |
| 49 | ALLOWED_ATTR: [ |
| 50 | "href", |
| 51 | "title", |
| 52 | "target", |
| 53 | "rel", // For links |
| 54 | "class", // For basic styling |
| 55 | ], |
| 56 | // Keep content formatting |
| 57 | KEEP_CONTENT: true, |
| 58 | }); |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 59 | } catch (error) { |
| 60 | console.error("Error rendering markdown:", error); |
| Philip Zeyliger | 53ab245 | 2025-06-04 17:49:33 +0000 | [diff] [blame] | 61 | // Fallback to sanitized plain text if markdown parsing fails |
| 62 | return DOMPurify.sanitize(markdownContent); |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | |
| 66 | // Common styles shared across all tool cards |
| 67 | const commonStyles = css` |
| Philip Zeyliger | e31d2a9 | 2025-05-11 15:22:35 -0700 | [diff] [blame] | 68 | :host { |
| 69 | display: block; |
| 70 | max-width: 100%; |
| 71 | width: 100%; |
| 72 | box-sizing: border-box; |
| 73 | overflow: hidden; |
| 74 | } |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 75 | pre { |
| 76 | background: rgb(236, 236, 236); |
| 77 | color: black; |
| 78 | padding: 0.5em; |
| 79 | border-radius: 4px; |
| 80 | white-space: pre-wrap; |
| 81 | word-break: break-word; |
| 82 | max-width: 100%; |
| 83 | width: 100%; |
| 84 | box-sizing: border-box; |
| 85 | overflow-wrap: break-word; |
| 86 | } |
| 87 | .summary-text { |
| Philip Zeyliger | e31d2a9 | 2025-05-11 15:22:35 -0700 | [diff] [blame] | 88 | overflow: hidden !important; |
| 89 | text-overflow: ellipsis !important; |
| 90 | white-space: nowrap !important; |
| 91 | max-width: 100% !important; |
| 92 | width: 100% !important; |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 93 | font-family: monospace; |
| Philip Zeyliger | e31d2a9 | 2025-05-11 15:22:35 -0700 | [diff] [blame] | 94 | display: block; |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 95 | } |
| 96 | `; |
| Pokey Rule | 5e8aead | 2025-05-06 16:21:57 +0100 | [diff] [blame] | 97 | |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 98 | @customElement("sketch-tool-card") |
| 99 | export class SketchToolCard extends LitElement { |
| Pokey Rule | 5e8aead | 2025-05-06 16:21:57 +0100 | [diff] [blame] | 100 | @property() toolCall: ToolCall; |
| 101 | @property() open: boolean; |
| 102 | @state() detailsVisible: boolean = false; |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 103 | |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 104 | static styles = css` |
| 105 | .tool-call { |
| 106 | display: flex; |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 107 | flex-direction: column; |
| 108 | width: 100%; |
| 109 | } |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 110 | .tool-row { |
| 111 | display: flex; |
| 112 | width: 100%; |
| 113 | box-sizing: border-box; |
| 114 | padding: 6px 8px 6px 12px; |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 115 | align-items: center; |
| Pokey Rule | 5e8aead | 2025-05-06 16:21:57 +0100 | [diff] [blame] | 116 | gap: 8px; |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 117 | cursor: pointer; |
| 118 | border-radius: 4px; |
| 119 | position: relative; |
| Pokey Rule | 5e8aead | 2025-05-06 16:21:57 +0100 | [diff] [blame] | 120 | overflow: hidden; |
| Philip Zeyliger | e31d2a9 | 2025-05-11 15:22:35 -0700 | [diff] [blame] | 121 | flex-wrap: wrap; |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 122 | } |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 123 | .tool-row:hover { |
| 124 | background-color: rgba(0, 0, 0, 0.02); |
| 125 | } |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 126 | .tool-name { |
| 127 | font-family: monospace; |
| 128 | font-weight: 500; |
| 129 | color: #444; |
| 130 | background-color: rgba(0, 0, 0, 0.05); |
| 131 | border-radius: 3px; |
| 132 | padding: 2px 6px; |
| 133 | flex-shrink: 0; |
| 134 | min-width: 45px; |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 135 | font-size: 12px; |
| 136 | text-align: center; |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 137 | white-space: nowrap; |
| 138 | } |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 139 | .tool-success { |
| 140 | color: #5cb85c; |
| 141 | font-size: 14px; |
| 142 | } |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 143 | .tool-error { |
| Josh Bleecher Snyder | e750ec9 | 2025-05-05 23:01:57 +0000 | [diff] [blame] | 144 | color: #6c757d; |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 145 | font-size: 14px; |
| 146 | } |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 147 | .tool-pending { |
| 148 | color: #f0ad4e; |
| 149 | font-size: 14px; |
| 150 | } |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 151 | .summary-text { |
| Philip Zeyliger | e31d2a9 | 2025-05-11 15:22:35 -0700 | [diff] [blame] | 152 | white-space: normal; |
| 153 | overflow-wrap: break-word; |
| 154 | word-break: break-word; |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 155 | flex-grow: 1; |
| 156 | flex-shrink: 1; |
| 157 | color: #444; |
| 158 | font-family: monospace; |
| 159 | font-size: 12px; |
| 160 | padding: 0 4px; |
| 161 | min-width: 50px; |
| Philip Zeyliger | e31d2a9 | 2025-05-11 15:22:35 -0700 | [diff] [blame] | 162 | max-width: calc(100% - 150px); |
| Pokey Rule | 5e8aead | 2025-05-06 16:21:57 +0100 | [diff] [blame] | 163 | display: inline-block; |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 164 | } |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 165 | .tool-status { |
| 166 | display: flex; |
| 167 | align-items: center; |
| 168 | gap: 12px; |
| 169 | margin-left: auto; |
| 170 | flex-shrink: 0; |
| Pokey Rule | 5e8aead | 2025-05-06 16:21:57 +0100 | [diff] [blame] | 171 | min-width: 120px; |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 172 | justify-content: flex-end; |
| 173 | padding-right: 8px; |
| 174 | } |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 175 | .tool-call-status { |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 176 | display: flex; |
| 177 | align-items: center; |
| 178 | justify-content: center; |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 179 | } |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 180 | .tool-call-status.spinner { |
| 181 | animation: spin 1s infinite linear; |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 182 | } |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 183 | @keyframes spin { |
| 184 | 0% { |
| 185 | transform: rotate(0deg); |
| 186 | } |
| 187 | 100% { |
| 188 | transform: rotate(360deg); |
| 189 | } |
| 190 | } |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 191 | .elapsed { |
| 192 | font-size: 11px; |
| 193 | color: #777; |
| 194 | white-space: nowrap; |
| 195 | min-width: 40px; |
| 196 | text-align: right; |
| 197 | } |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 198 | .tool-details { |
| 199 | padding: 8px; |
| 200 | background-color: rgba(0, 0, 0, 0.02); |
| 201 | margin-top: 1px; |
| 202 | border-top: 1px solid rgba(0, 0, 0, 0.05); |
| 203 | display: none; |
| 204 | font-family: monospace; |
| 205 | font-size: 12px; |
| 206 | color: #333; |
| 207 | border-radius: 0 0 4px 4px; |
| 208 | max-width: 100%; |
| 209 | width: 100%; |
| 210 | box-sizing: border-box; |
| Pokey Rule | 5e8aead | 2025-05-06 16:21:57 +0100 | [diff] [blame] | 211 | overflow: hidden; |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 212 | } |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 213 | .tool-details.visible { |
| 214 | display: block; |
| 215 | } |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 216 | .cancel-button { |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 217 | cursor: pointer; |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 218 | color: white; |
| 219 | background-color: #d9534f; |
| 220 | border: none; |
| 221 | border-radius: 3px; |
| 222 | font-size: 11px; |
| 223 | padding: 2px 6px; |
| 224 | white-space: nowrap; |
| 225 | min-width: 50px; |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 226 | } |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 227 | .cancel-button:hover { |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 228 | background-color: #c9302c; |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 229 | } |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 230 | .cancel-button[disabled] { |
| 231 | background-color: #999; |
| 232 | cursor: not-allowed; |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 233 | } |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 234 | `; |
| 235 | |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 236 | _cancelToolCall = async (tool_call_id: string, button: HTMLButtonElement) => { |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 237 | button.innerText = "Cancelling"; |
| 238 | button.disabled = true; |
| 239 | try { |
| 240 | const response = await fetch("cancel", { |
| 241 | method: "POST", |
| Pokey Rule | 5e8aead | 2025-05-06 16:21:57 +0100 | [diff] [blame] | 242 | headers: { "Content-Type": "application/json" }, |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 243 | body: JSON.stringify({ |
| 244 | tool_call_id: tool_call_id, |
| 245 | reason: "user requested cancellation", |
| 246 | }), |
| 247 | }); |
| 248 | if (response.ok) { |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 249 | button.parentElement.removeChild(button); |
| 250 | } else { |
| 251 | button.innerText = "Cancel"; |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 252 | } |
| 253 | } catch (e) { |
| 254 | console.error("cancel", tool_call_id, e); |
| 255 | } |
| 256 | }; |
| 257 | |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 258 | _toggleDetails(e: Event) { |
| 259 | e.stopPropagation(); |
| 260 | this.detailsVisible = !this.detailsVisible; |
| 261 | } |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 262 | |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 263 | render() { |
| Pokey Rule | 5e8aead | 2025-05-06 16:21:57 +0100 | [diff] [blame] | 264 | // Status indicator based on result |
| 265 | let statusIcon = html`<span class="tool-call-status spinner tool-pending" |
| 266 | >⏳</span |
| 267 | >`; |
| 268 | if (this.toolCall?.result_message) { |
| 269 | statusIcon = this.toolCall?.result_message.tool_error |
| Josh Bleecher Snyder | c3c2023 | 2025-05-07 05:46:04 -0700 | [diff] [blame] | 270 | ? html`<span class="tool-call-status tool-error">〰️</span>` |
| Pokey Rule | 5e8aead | 2025-05-06 16:21:57 +0100 | [diff] [blame] | 271 | : html`<span class="tool-call-status tool-success">✓</span>`; |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | // Cancel button for pending operations |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 275 | const cancelButton = this.toolCall?.result_message |
| 276 | ? "" |
| 277 | : html`<button |
| 278 | class="cancel-button" |
| 279 | title="Cancel this operation" |
| 280 | @click=${(e: Event) => { |
| 281 | e.stopPropagation(); |
| Pokey Rule | 5e8aead | 2025-05-06 16:21:57 +0100 | [diff] [blame] | 282 | this._cancelToolCall( |
| 283 | this.toolCall?.tool_call_id, |
| 284 | e.target as HTMLButtonElement, |
| 285 | ); |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 286 | }} |
| 287 | > |
| 288 | Cancel |
| 289 | </button>`; |
| 290 | |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 291 | // Elapsed time display |
| 292 | const elapsed = this.toolCall?.result_message?.elapsed |
| Sean McCullough | 2deac84 | 2025-04-21 18:17:57 -0700 | [diff] [blame] | 293 | ? html`<span class="elapsed" |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 294 | >${(this.toolCall?.result_message?.elapsed / 1e9).toFixed(1)}s</span |
| Sean McCullough | 2deac84 | 2025-04-21 18:17:57 -0700 | [diff] [blame] | 295 | >` |
| Pokey Rule | 5e8aead | 2025-05-06 16:21:57 +0100 | [diff] [blame] | 296 | : html`<span class="elapsed"></span>`; |
| Sean McCullough | 2deac84 | 2025-04-21 18:17:57 -0700 | [diff] [blame] | 297 | |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 298 | // Initialize details visibility based on open property |
| 299 | if (this.open && !this.detailsVisible) { |
| 300 | this.detailsVisible = true; |
| 301 | } |
| 302 | |
| 303 | return html`<div class="tool-call"> |
| 304 | <div class="tool-row" @click=${this._toggleDetails}> |
| 305 | <span class="tool-name">${this.toolCall?.name}</span> |
| 306 | <span class="summary-text"><slot name="summary"></slot></span> |
| 307 | <div class="tool-status">${statusIcon} ${elapsed} ${cancelButton}</div> |
| 308 | </div> |
| 309 | <div class="tool-details ${this.detailsVisible ? "visible" : ""}"> |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 310 | <slot name="input"></slot> |
| 311 | <slot name="result"></slot> |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 312 | </div> |
| 313 | </div>`; |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 317 | @customElement("sketch-tool-card-bash") |
| 318 | export class SketchToolCardBash extends LitElement { |
| 319 | @property() toolCall: ToolCall; |
| 320 | @property() open: boolean; |
| 321 | |
| 322 | static styles = [ |
| 323 | commonStyles, |
| 324 | css` |
| Philip Zeyliger | e31d2a9 | 2025-05-11 15:22:35 -0700 | [diff] [blame] | 325 | :host { |
| 326 | max-width: 100%; |
| 327 | display: block; |
| 328 | } |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 329 | .input { |
| 330 | display: flex; |
| 331 | width: 100%; |
| Philip Zeyliger | e31d2a9 | 2025-05-11 15:22:35 -0700 | [diff] [blame] | 332 | max-width: 100%; |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 333 | flex-direction: column; |
| Philip Zeyliger | e31d2a9 | 2025-05-11 15:22:35 -0700 | [diff] [blame] | 334 | overflow-wrap: break-word; |
| 335 | word-break: break-word; |
| 336 | } |
| 337 | .command-wrapper { |
| 338 | max-width: 100%; |
| 339 | overflow: hidden; |
| 340 | text-overflow: ellipsis; |
| 341 | white-space: nowrap; |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 342 | } |
| 343 | .input pre { |
| 344 | width: 100%; |
| 345 | margin-bottom: 0; |
| 346 | border-radius: 4px 4px 0 0; |
| 347 | box-sizing: border-box; |
| 348 | } |
| 349 | .result pre { |
| 350 | margin-top: 0; |
| 351 | color: #555; |
| 352 | border-radius: 0 0 4px 4px; |
| 353 | width: 100%; |
| 354 | box-sizing: border-box; |
| 355 | } |
| 356 | .result pre.scrollable-on-hover { |
| 357 | max-height: 300px; |
| 358 | overflow-y: auto; |
| 359 | } |
| 360 | .tool-call-result-container { |
| 361 | width: 100%; |
| 362 | position: relative; |
| 363 | } |
| 364 | .background-badge { |
| 365 | display: inline-block; |
| 366 | background-color: #6200ea; |
| 367 | color: white; |
| 368 | font-size: 10px; |
| 369 | font-weight: bold; |
| 370 | padding: 2px 6px; |
| 371 | border-radius: 10px; |
| 372 | margin-left: 8px; |
| 373 | vertical-align: middle; |
| 374 | } |
| 375 | .command-wrapper { |
| 376 | display: inline-block; |
| 377 | max-width: 100%; |
| 378 | overflow: hidden; |
| 379 | text-overflow: ellipsis; |
| 380 | white-space: nowrap; |
| 381 | } |
| 382 | `, |
| 383 | ]; |
| 384 | |
| 385 | render() { |
| 386 | const inputData = JSON.parse(this.toolCall?.input || "{}"); |
| 387 | const isBackground = inputData?.background === true; |
| 388 | const backgroundIcon = isBackground ? "🔄 " : ""; |
| 389 | |
| Philip Zeyliger | e31d2a9 | 2025-05-11 15:22:35 -0700 | [diff] [blame] | 390 | // Truncate the command if it's too long to display nicely |
| 391 | const command = inputData?.command || ""; |
| 392 | const displayCommand = |
| 393 | command.length > 80 ? command.substring(0, 80) + "..." : command; |
| 394 | |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 395 | return html` <sketch-tool-card |
| 396 | .open=${this.open} |
| 397 | .toolCall=${this.toolCall} |
| 398 | > |
| Philip Zeyliger | e31d2a9 | 2025-05-11 15:22:35 -0700 | [diff] [blame] | 399 | <span |
| 400 | slot="summary" |
| 401 | class="summary-text" |
| 402 | style="display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;" |
| 403 | > |
| 404 | <div |
| 405 | class="command-wrapper" |
| 406 | style="max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;" |
| 407 | > |
| 408 | ${backgroundIcon}${displayCommand} |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 409 | </div> |
| 410 | </span> |
| 411 | <div slot="input" class="input"> |
| 412 | <div class="tool-call-result-container"> |
| 413 | <pre>${backgroundIcon}${inputData?.command}</pre> |
| 414 | </div> |
| 415 | </div> |
| 416 | ${this.toolCall?.result_message?.tool_result |
| 417 | ? html`<div slot="result" class="result"> |
| 418 | <div class="tool-call-result-container"> |
| 419 | <pre class="tool-call-result"> |
| 420 | ${this.toolCall?.result_message.tool_result}</pre |
| 421 | > |
| 422 | </div> |
| 423 | </div>` |
| 424 | : ""} |
| 425 | </sketch-tool-card>`; |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | @customElement("sketch-tool-card-codereview") |
| 430 | export class SketchToolCardCodeReview extends LitElement { |
| 431 | @property() toolCall: ToolCall; |
| 432 | @property() open: boolean; |
| 433 | |
| 434 | // Determine the status icon based on the content of the result message |
| 435 | getStatusIcon(resultText: string): string { |
| 436 | if (!resultText) return ""; |
| 437 | if (resultText === "OK") return "✔️"; |
| 438 | if (resultText.includes("# Errors")) return "⚠️"; |
| 439 | if (resultText.includes("# Info")) return "ℹ️"; |
| 440 | if (resultText.includes("uncommitted changes in repo")) return "🧹"; |
| 441 | if (resultText.includes("no new commits have been added")) return "🐣"; |
| 442 | if (resultText.includes("git repo is not clean")) return "🧼"; |
| 443 | return "❓"; |
| 444 | } |
| 445 | |
| 446 | render() { |
| 447 | const resultText = this.toolCall?.result_message?.tool_result || ""; |
| 448 | const statusIcon = this.getStatusIcon(resultText); |
| 449 | |
| 450 | return html`<sketch-tool-card .open=${this.open} .toolCall=${this.toolCall}> |
| 451 | <span slot="summary" class="summary-text">${statusIcon}</span> |
| 452 | <div slot="result"><pre>${resultText}</pre></div> |
| 453 | </sketch-tool-card>`; |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | @customElement("sketch-tool-card-done") |
| 458 | export class SketchToolCardDone extends LitElement { |
| 459 | @property() toolCall: ToolCall; |
| 460 | @property() open: boolean; |
| 461 | |
| 462 | render() { |
| 463 | const doneInput = JSON.parse(this.toolCall.input); |
| 464 | return html`<sketch-tool-card .open=${this.open} .toolCall=${this.toolCall}> |
| 465 | <span slot="summary" class="summary-text"></span> |
| 466 | <div slot="result"> |
| 467 | ${Object.keys(doneInput.checklist_items).map((key) => { |
| 468 | const item = doneInput.checklist_items[key]; |
| Josh Bleecher Snyder | fbbf83b | 2025-05-15 10:55:55 -0700 | [diff] [blame] | 469 | let statusIcon = "〰️"; |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 470 | if (item.status == "yes") { |
| Josh Bleecher Snyder | fbbf83b | 2025-05-15 10:55:55 -0700 | [diff] [blame] | 471 | statusIcon = "✅"; |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 472 | } else if (item.status == "not applicable") { |
| Josh Bleecher Snyder | fbbf83b | 2025-05-15 10:55:55 -0700 | [diff] [blame] | 473 | statusIcon = "🤷"; |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 474 | } |
| 475 | return html`<div> |
| 476 | <span>${statusIcon}</span> ${key}:${item.status} |
| 477 | </div>`; |
| 478 | })} |
| 479 | </div> |
| 480 | </sketch-tool-card>`; |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | @customElement("sketch-tool-card-patch") |
| 485 | export class SketchToolCardPatch extends LitElement { |
| 486 | @property() toolCall: ToolCall; |
| 487 | @property() open: boolean; |
| 488 | |
| 489 | static styles = css` |
| 490 | .summary-text { |
| 491 | color: #555; |
| 492 | font-family: monospace; |
| 493 | overflow: hidden; |
| 494 | text-overflow: ellipsis; |
| 495 | white-space: nowrap; |
| 496 | border-radius: 3px; |
| 497 | } |
| 498 | `; |
| 499 | |
| 500 | render() { |
| 501 | const patchInput = JSON.parse(this.toolCall?.input); |
| 502 | return html`<sketch-tool-card .open=${this.open} .toolCall=${this.toolCall}> |
| 503 | <span slot="summary" class="summary-text"> |
| 504 | ${patchInput?.path}: ${patchInput.patches.length} |
| 505 | edit${patchInput.patches.length > 1 ? "s" : ""} |
| 506 | </span> |
| 507 | <div slot="input"> |
| 508 | ${patchInput.patches.map((patch) => { |
| 509 | return html`Patch operation: <b>${patch.operation}</b> |
| 510 | <pre>${patch.newText}</pre>`; |
| 511 | })} |
| 512 | </div> |
| 513 | <div slot="result"> |
| 514 | <pre>${this.toolCall?.result_message?.tool_result}</pre> |
| 515 | </div> |
| 516 | </sketch-tool-card>`; |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | @customElement("sketch-tool-card-think") |
| 521 | export class SketchToolCardThink extends LitElement { |
| 522 | @property() toolCall: ToolCall; |
| 523 | @property() open: boolean; |
| 524 | |
| 525 | static styles = css` |
| 526 | .thought-bubble { |
| 527 | overflow-x: auto; |
| 528 | margin-bottom: 3px; |
| 529 | font-family: monospace; |
| 530 | padding: 3px 5px; |
| 531 | background: rgb(236, 236, 236); |
| 532 | border-radius: 6px; |
| 533 | user-select: text; |
| 534 | cursor: text; |
| 535 | -webkit-user-select: text; |
| 536 | -moz-user-select: text; |
| 537 | -ms-user-select: text; |
| 538 | font-size: 13px; |
| 539 | line-height: 1.3; |
| 540 | } |
| 541 | .summary-text { |
| 542 | overflow: hidden; |
| 543 | text-overflow: ellipsis; |
| 544 | font-family: monospace; |
| 545 | } |
| 546 | `; |
| 547 | |
| 548 | render() { |
| 549 | return html` |
| 550 | <sketch-tool-card .open=${this.open} .toolCall=${this.toolCall}> |
| 551 | <span slot="summary" class="summary-text"> |
| 552 | ${JSON.parse(this.toolCall?.input)?.thoughts?.split("\n")[0]} |
| 553 | </span> |
| 554 | <div slot="input" class="thought-bubble"> |
| 555 | <div class="markdown-content"> |
| 556 | ${unsafeHTML( |
| 557 | renderMarkdown(JSON.parse(this.toolCall?.input)?.thoughts), |
| 558 | )} |
| 559 | </div> |
| 560 | </div> |
| 561 | </sketch-tool-card> |
| 562 | `; |
| 563 | } |
| 564 | } |
| 565 | |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 566 | @customElement("sketch-tool-card-set-slug") |
| 567 | export class SketchToolCardSetSlug extends LitElement { |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 568 | @property() toolCall: ToolCall; |
| 569 | @property() open: boolean; |
| 570 | |
| 571 | static styles = css` |
| 572 | .summary-text { |
| 573 | font-style: italic; |
| 574 | } |
| 575 | pre { |
| 576 | display: inline; |
| 577 | font-family: monospace; |
| 578 | background: rgb(236, 236, 236); |
| 579 | padding: 2px 4px; |
| 580 | border-radius: 2px; |
| 581 | margin: 0; |
| 582 | } |
| 583 | `; |
| 584 | |
| 585 | render() { |
| 586 | const inputData = JSON.parse(this.toolCall?.input || "{}"); |
| 587 | return html` |
| 588 | <sketch-tool-card .open=${this.open} .toolCall=${this.toolCall}> |
| 589 | <span slot="summary" class="summary-text"> |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 590 | Slug: "${inputData.slug}" |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 591 | </span> |
| 592 | <div slot="input"> |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 593 | <div>Set slug to: <b>${inputData.slug}</b></div> |
| Josh Bleecher Snyder | a2a3150 | 2025-05-07 12:37:18 +0000 | [diff] [blame] | 594 | </div> |
| 595 | </sketch-tool-card> |
| 596 | `; |
| 597 | } |
| 598 | } |
| 599 | |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 600 | @customElement("sketch-tool-card-commit-message-style") |
| 601 | export class SketchToolCardCommitMessageStyle extends LitElement { |
| Josh Bleecher Snyder | a2a3150 | 2025-05-07 12:37:18 +0000 | [diff] [blame] | 602 | @property() |
| 603 | toolCall: ToolCall; |
| 604 | |
| 605 | @property() |
| 606 | open: boolean; |
| 607 | |
| Philip Zeyliger | be7802a | 2025-06-04 20:15:25 +0000 | [diff] [blame] | 608 | @property() |
| 609 | state: State; |
| 610 | |
| Josh Bleecher Snyder | a2a3150 | 2025-05-07 12:37:18 +0000 | [diff] [blame] | 611 | static styles = css` |
| 612 | .summary-text { |
| 613 | font-style: italic; |
| 614 | } |
| 615 | pre { |
| 616 | display: inline; |
| 617 | font-family: monospace; |
| 618 | background: rgb(236, 236, 236); |
| 619 | padding: 2px 4px; |
| 620 | border-radius: 2px; |
| 621 | margin: 0; |
| 622 | } |
| 623 | `; |
| 624 | constructor() { |
| 625 | super(); |
| 626 | } |
| 627 | |
| 628 | connectedCallback() { |
| 629 | super.connectedCallback(); |
| 630 | } |
| 631 | |
| 632 | disconnectedCallback() { |
| 633 | super.disconnectedCallback(); |
| 634 | } |
| 635 | |
| 636 | render() { |
| Josh Bleecher Snyder | a2a3150 | 2025-05-07 12:37:18 +0000 | [diff] [blame] | 637 | return html` |
| 638 | <sketch-tool-card .open=${this.open} .toolCall=${this.toolCall}> |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 639 | </sketch-tool-card> |
| 640 | `; |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | @customElement("sketch-tool-card-multiple-choice") |
| 645 | export class SketchToolCardMultipleChoice extends LitElement { |
| 646 | @property() toolCall: ToolCall; |
| 647 | @property() open: boolean; |
| 648 | @property() selectedOption: MultipleChoiceOption = null; |
| 649 | |
| 650 | static styles = css` |
| 651 | .options-container { |
| 652 | display: flex; |
| 653 | flex-direction: row; |
| 654 | flex-wrap: wrap; |
| 655 | gap: 8px; |
| 656 | margin: 10px 0; |
| 657 | } |
| 658 | .option { |
| 659 | display: inline-flex; |
| 660 | align-items: center; |
| 661 | padding: 8px 12px; |
| 662 | border-radius: 4px; |
| 663 | background-color: #f5f5f5; |
| 664 | cursor: pointer; |
| 665 | transition: all 0.2s; |
| 666 | border: 1px solid transparent; |
| 667 | user-select: none; |
| 668 | } |
| 669 | .option:hover { |
| 670 | background-color: #e0e0e0; |
| 671 | border-color: #ccc; |
| 672 | transform: translateY(-1px); |
| 673 | box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); |
| 674 | } |
| 675 | .option:active { |
| 676 | transform: translateY(0); |
| 677 | box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1); |
| 678 | background-color: #d5d5d5; |
| 679 | } |
| 680 | .option.selected { |
| 681 | background-color: #e3f2fd; |
| 682 | border-color: #2196f3; |
| 683 | border-width: 1px; |
| 684 | border-style: solid; |
| 685 | } |
| 686 | .option-checkmark { |
| 687 | margin-left: 6px; |
| 688 | color: #2196f3; |
| 689 | } |
| 690 | .summary-text { |
| 691 | font-style: italic; |
| 692 | padding: 0.5em; |
| 693 | } |
| 694 | .summary-text strong { |
| 695 | font-style: normal; |
| 696 | color: #2196f3; |
| 697 | font-weight: 600; |
| 698 | } |
| 699 | `; |
| 700 | |
| 701 | connectedCallback() { |
| 702 | super.connectedCallback(); |
| 703 | this.updateSelectedOption(); |
| 704 | } |
| 705 | |
| 706 | updated(changedProps) { |
| 707 | if (changedProps.has("toolCall")) { |
| 708 | this.updateSelectedOption(); |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | updateSelectedOption() { |
| 713 | if (this.toolCall?.result_message?.tool_result) { |
| 714 | try { |
| 715 | this.selectedOption = JSON.parse( |
| 716 | this.toolCall.result_message.tool_result, |
| 717 | ).selected; |
| 718 | } catch (e) { |
| 719 | console.error("Error parsing result:", e); |
| 720 | } |
| 721 | } else { |
| 722 | this.selectedOption = null; |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | async handleOptionClick(choice) { |
| 727 | this.selectedOption = this.selectedOption === choice ? null : choice; |
| 728 | |
| 729 | const event = new CustomEvent("multiple-choice-selected", { |
| 730 | detail: { |
| 731 | responseText: this.selectedOption.responseText, |
| 732 | toolCall: this.toolCall, |
| 733 | }, |
| 734 | bubbles: true, |
| 735 | composed: true, |
| 736 | }); |
| 737 | this.dispatchEvent(event); |
| 738 | } |
| 739 | |
| 740 | render() { |
| 741 | let choices = []; |
| 742 | let question = ""; |
| 743 | try { |
| 744 | const inputData = JSON.parse( |
| 745 | this.toolCall?.input || "{}", |
| 746 | ) as MultipleChoiceParams; |
| 747 | choices = inputData.responseOptions || []; |
| 748 | question = inputData.question || "Please select an option:"; |
| 749 | } catch (e) { |
| 750 | console.error("Error parsing multiple-choice input:", e); |
| 751 | } |
| 752 | |
| 753 | const summaryContent = |
| 754 | this.selectedOption !== null |
| 755 | ? html`<span class="summary-text"> |
| 756 | ${question}: <strong>${this.selectedOption.caption}</strong> |
| 757 | </span>` |
| 758 | : html`<span class="summary-text">${question}</span>`; |
| 759 | |
| 760 | return html` |
| 761 | <div class="multiple-choice-card"> |
| 762 | ${summaryContent} |
| 763 | <div class="options-container"> |
| 764 | ${choices.map((choice) => { |
| 765 | const isSelected = |
| 766 | this.selectedOption !== null && this.selectedOption === choice; |
| 767 | return html` |
| 768 | <div |
| 769 | class="option ${isSelected ? "selected" : ""}" |
| 770 | @click=${() => this.handleOptionClick(choice)} |
| 771 | title="${choice.responseText}" |
| 772 | > |
| 773 | <span class="option-label">${choice.caption}</span> |
| 774 | ${isSelected |
| 775 | ? html`<span class="option-checkmark">✓</span>` |
| 776 | : ""} |
| 777 | </div> |
| 778 | `; |
| 779 | })} |
| 780 | </div> |
| 781 | </div> |
| 782 | `; |
| 783 | } |
| 784 | } |
| 785 | |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 786 | @customElement("sketch-tool-card-todo-write") |
| 787 | export class SketchToolCardTodoWrite extends LitElement { |
| 788 | @property() toolCall: ToolCall; |
| 789 | @property() open: boolean; |
| 790 | |
| 791 | static styles = css` |
| 792 | .summary-text { |
| 793 | font-style: italic; |
| 794 | color: #666; |
| 795 | } |
| 796 | `; |
| 797 | |
| 798 | render() { |
| 799 | const inputData = JSON.parse(this.toolCall?.input || "{}"); |
| 800 | const tasks = inputData.tasks || []; |
| Josh Bleecher Snyder | 991164f | 2025-05-29 05:02:10 +0000 | [diff] [blame] | 801 | |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 802 | // Generate circles based on task status |
| Josh Bleecher Snyder | 991164f | 2025-05-29 05:02:10 +0000 | [diff] [blame] | 803 | const circles = tasks |
| 804 | .map((task) => { |
| 805 | switch (task.status) { |
| 806 | case "completed": |
| 807 | return "●"; // full circle |
| 808 | case "in-progress": |
| 809 | return "◐"; // half circle |
| 810 | case "queued": |
| 811 | default: |
| 812 | return "○"; // empty circle |
| 813 | } |
| 814 | }) |
| 815 | .join(" "); |
| 816 | |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 817 | return html`<sketch-tool-card .open=${this.open} .toolCall=${this.toolCall}> |
| Josh Bleecher Snyder | 991164f | 2025-05-29 05:02:10 +0000 | [diff] [blame] | 818 | <span slot="summary" class="summary-text"> ${circles} </span> |
| 819 | <div slot="result"> |
| 820 | <pre>${this.toolCall?.result_message?.tool_result}</pre> |
| 821 | </div> |
| 822 | </sketch-tool-card>`; |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | @customElement("sketch-tool-card-keyword-search") |
| 827 | export class SketchToolCardKeywordSearch extends LitElement { |
| 828 | @property() toolCall: ToolCall; |
| 829 | @property() open: boolean; |
| 830 | |
| 831 | static styles = css` |
| 832 | .summary-container { |
| 833 | display: flex; |
| 834 | flex-direction: column; |
| 835 | gap: 2px; |
| 836 | width: 100%; |
| 837 | max-width: 100%; |
| 838 | overflow: hidden; |
| 839 | } |
| 840 | .query-line { |
| 841 | color: #333; |
| 842 | font-family: inherit; |
| 843 | font-size: 12px; |
| 844 | font-weight: normal; |
| 845 | white-space: normal; |
| 846 | word-wrap: break-word; |
| 847 | word-break: break-word; |
| 848 | overflow-wrap: break-word; |
| 849 | line-height: 1.2; |
| 850 | } |
| 851 | .keywords-line { |
| 852 | color: #666; |
| 853 | font-family: inherit; |
| 854 | font-size: 11px; |
| 855 | font-weight: normal; |
| 856 | white-space: normal; |
| 857 | word-wrap: break-word; |
| 858 | word-break: break-word; |
| 859 | overflow-wrap: break-word; |
| 860 | line-height: 1.2; |
| 861 | margin-top: 1px; |
| 862 | } |
| 863 | `; |
| 864 | |
| 865 | render() { |
| 866 | const inputData = JSON.parse(this.toolCall?.input || "{}"); |
| 867 | const query = inputData.query || ""; |
| 868 | const searchTerms = inputData.search_terms || []; |
| 869 | |
| 870 | return html`<sketch-tool-card .open=${this.open} .toolCall=${this.toolCall}> |
| 871 | <div slot="summary" class="summary-container"> |
| 872 | <div class="query-line">🔍 ${query}</div> |
| 873 | <div class="keywords-line">🗝️ ${searchTerms.join(", ")}</div> |
| 874 | </div> |
| 875 | <div slot="input"> |
| 876 | <div><strong>Query:</strong> ${query}</div> |
| 877 | <div><strong>Search terms:</strong> ${searchTerms.join(", ")}</div> |
| 878 | </div> |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 879 | <div slot="result"> |
| 880 | <pre>${this.toolCall?.result_message?.tool_result}</pre> |
| 881 | </div> |
| 882 | </sketch-tool-card>`; |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | @customElement("sketch-tool-card-todo-read") |
| 887 | export class SketchToolCardTodoRead extends LitElement { |
| 888 | @property() toolCall: ToolCall; |
| 889 | @property() open: boolean; |
| 890 | |
| 891 | static styles = css` |
| 892 | .summary-text { |
| 893 | font-style: italic; |
| 894 | color: #666; |
| 895 | } |
| 896 | `; |
| 897 | |
| 898 | render() { |
| 899 | return html`<sketch-tool-card .open=${this.open} .toolCall=${this.toolCall}> |
| Josh Bleecher Snyder | 991164f | 2025-05-29 05:02:10 +0000 | [diff] [blame] | 900 | <span slot="summary" class="summary-text"> Read todo list </span> |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 901 | <div slot="result"> |
| 902 | <pre>${this.toolCall?.result_message?.tool_result}</pre> |
| 903 | </div> |
| 904 | </sketch-tool-card>`; |
| 905 | } |
| 906 | } |
| 907 | |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 908 | @customElement("sketch-tool-card-generic") |
| 909 | export class SketchToolCardGeneric extends LitElement { |
| 910 | @property() toolCall: ToolCall; |
| 911 | @property() open: boolean; |
| 912 | |
| 913 | render() { |
| 914 | return html`<sketch-tool-card .open=${this.open} .toolCall=${this.toolCall}> |
| Philip Zeyliger | e31d2a9 | 2025-05-11 15:22:35 -0700 | [diff] [blame] | 915 | <span |
| 916 | slot="summary" |
| 917 | style="display: block; white-space: normal; word-break: break-word; overflow-wrap: break-word; max-width: 100%; width: 100%;" |
| 918 | >${this.toolCall?.input}</span |
| 919 | > |
| 920 | <div |
| 921 | slot="input" |
| 922 | style="max-width: 100%; overflow-wrap: break-word; word-break: break-word;" |
| 923 | > |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 924 | Input: |
| Philip Zeyliger | e31d2a9 | 2025-05-11 15:22:35 -0700 | [diff] [blame] | 925 | <pre |
| 926 | style="max-width: 100%; white-space: pre-wrap; overflow-wrap: break-word; word-break: break-word;" |
| 927 | > |
| 928 | ${this.toolCall?.input}</pre |
| 929 | > |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 930 | </div> |
| Philip Zeyliger | e31d2a9 | 2025-05-11 15:22:35 -0700 | [diff] [blame] | 931 | <div |
| 932 | slot="result" |
| 933 | style="max-width: 100%; overflow-wrap: break-word; word-break: break-word;" |
| 934 | > |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 935 | Result: |
| 936 | ${this.toolCall?.result_message?.tool_result |
| 937 | ? html`<pre>${this.toolCall?.result_message.tool_result}</pre>` |
| 938 | : ""} |
| 939 | </div> |
| 940 | </sketch-tool-card>`; |
| 941 | } |
| 942 | } |
| 943 | |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 944 | declare global { |
| 945 | interface HTMLElementTagNameMap { |
| 946 | "sketch-tool-card": SketchToolCard; |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 947 | "sketch-tool-card-generic": SketchToolCardGeneric; |
| 948 | "sketch-tool-card-bash": SketchToolCardBash; |
| 949 | "sketch-tool-card-codereview": SketchToolCardCodeReview; |
| 950 | "sketch-tool-card-done": SketchToolCardDone; |
| 951 | "sketch-tool-card-patch": SketchToolCardPatch; |
| 952 | "sketch-tool-card-think": SketchToolCardThink; |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 953 | "sketch-tool-card-set-slug": SketchToolCardSetSlug; |
| 954 | "sketch-tool-card-commit-message-style": SketchToolCardCommitMessageStyle; |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 955 | "sketch-tool-card-multiple-choice": SketchToolCardMultipleChoice; |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 956 | "sketch-tool-card-todo-write": SketchToolCardTodoWrite; |
| 957 | "sketch-tool-card-todo-read": SketchToolCardTodoRead; |
| Josh Bleecher Snyder | 991164f | 2025-05-29 05:02:10 +0000 | [diff] [blame] | 958 | "sketch-tool-card-keyword-search": SketchToolCardKeywordSearch; |
| Philip Zeyliger | 84a8ae6 | 2025-05-13 16:36:01 -0700 | [diff] [blame] | 959 | // TODO: We haven't implemented this for browser tools. |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 960 | } |
| 961 | } |