| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 1 | import { html } from "lit"; |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 2 | import { unsafeHTML } from "lit/directives/unsafe-html.js"; |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 3 | import { customElement, property } from "lit/decorators.js"; |
| Josh Bleecher Snyder | beaa86a | 2025-07-23 03:37:21 +0000 | [diff] [blame] | 4 | import { ToolCall } from "../types"; |
| philip.zeyliger | 26bc659 | 2025-06-30 20:15:30 -0700 | [diff] [blame] | 5 | import { marked } from "marked"; |
| Philip Zeyliger | 53ab245 | 2025-06-04 17:49:33 +0000 | [diff] [blame] | 6 | import DOMPurify from "dompurify"; |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 7 | import { SketchTailwindElement } from "./sketch-tailwind-element"; |
| 8 | import "./sketch-tool-card-base"; |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 9 | |
| Philip Zeyliger | 53ab245 | 2025-06-04 17:49:33 +0000 | [diff] [blame] | 10 | // Shared utility function for markdown rendering with DOMPurify sanitization |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 11 | function renderMarkdown(markdownContent: string): string { |
| 12 | try { |
| Philip Zeyliger | 53ab245 | 2025-06-04 17:49:33 +0000 | [diff] [blame] | 13 | // Parse markdown with default settings |
| 14 | const htmlOutput = marked.parse(markdownContent, { |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 15 | gfm: true, |
| 16 | breaks: true, |
| 17 | async: false, |
| 18 | }) as string; |
| Philip Zeyliger | 53ab245 | 2025-06-04 17:49:33 +0000 | [diff] [blame] | 19 | |
| 20 | // Sanitize the output HTML with DOMPurify |
| 21 | return DOMPurify.sanitize(htmlOutput, { |
| 22 | // Allow common safe HTML elements |
| 23 | ALLOWED_TAGS: [ |
| 24 | "p", |
| 25 | "br", |
| 26 | "strong", |
| 27 | "em", |
| 28 | "b", |
| 29 | "i", |
| 30 | "u", |
| 31 | "s", |
| 32 | "code", |
| 33 | "pre", |
| 34 | "h1", |
| 35 | "h2", |
| 36 | "h3", |
| 37 | "h4", |
| 38 | "h5", |
| 39 | "h6", |
| 40 | "ul", |
| 41 | "ol", |
| 42 | "li", |
| 43 | "blockquote", |
| 44 | "a", |
| 45 | ], |
| 46 | ALLOWED_ATTR: [ |
| 47 | "href", |
| 48 | "title", |
| 49 | "target", |
| 50 | "rel", // For links |
| 51 | "class", // For basic styling |
| 52 | ], |
| 53 | // Keep content formatting |
| 54 | KEEP_CONTENT: true, |
| 55 | }); |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 56 | } catch (error) { |
| 57 | console.error("Error rendering markdown:", error); |
| Philip Zeyliger | 53ab245 | 2025-06-04 17:49:33 +0000 | [diff] [blame] | 58 | // Fallback to sanitized plain text if markdown parsing fails |
| 59 | return DOMPurify.sanitize(markdownContent); |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 63 | // Shared utility function for creating Tailwind pre elements |
| 64 | function createPreElement(content: string, additionalClasses: string = "") { |
| 65 | return html`<pre |
| banksean | 3d1308e | 2025-07-29 17:20:10 +0000 | [diff] [blame] | 66 | 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 overflow-wrap-break-word ${additionalClasses}" |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 67 | > |
| 68 | ${content}</pre |
| 69 | >`; |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 72 | @customElement("sketch-tool-card-bash") |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 73 | export class SketchToolCardBash extends SketchTailwindElement { |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 74 | @property() toolCall: ToolCall; |
| 75 | @property() open: boolean; |
| 76 | |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 77 | render() { |
| 78 | const inputData = JSON.parse(this.toolCall?.input || "{}"); |
| 79 | const isBackground = inputData?.background === true; |
| Josh Bleecher Snyder | 17b2fd9 | 2025-07-09 22:47:13 +0000 | [diff] [blame] | 80 | const isSlowOk = inputData?.slow_ok === true; |
| Autoformatter | 9d9c812 | 2025-07-18 03:37:23 +0000 | [diff] [blame] | 81 | const backgroundIcon = isBackground |
| 82 | ? html`<span title="Running in background">🥷</span> ` |
| 83 | : ""; |
| 84 | const slowIcon = isSlowOk |
| 85 | ? html`<span title="Extended timeouts">🐢</span> ` |
| 86 | : ""; |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 87 | |
| Philip Zeyliger | e31d2a9 | 2025-05-11 15:22:35 -0700 | [diff] [blame] | 88 | // Truncate the command if it's too long to display nicely |
| 89 | const command = inputData?.command || ""; |
| 90 | const displayCommand = |
| 91 | command.length > 80 ? command.substring(0, 80) + "..." : command; |
| 92 | |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 93 | const summaryContent = html`<div |
| 94 | class="max-w-full overflow-hidden text-ellipsis whitespace-nowrap" |
| 95 | > |
| 96 | ${backgroundIcon}${slowIcon}${displayCommand} |
| 97 | </div>`; |
| 98 | |
| 99 | const inputContent = html`<div |
| 100 | class="flex w-full max-w-full flex-col overflow-wrap-break-word break-words" |
| 101 | > |
| 102 | <div class="w-full relative"> |
| Josh Bleecher Snyder | 4594388 | 2025-07-18 02:13:31 +0000 | [diff] [blame] | 103 | <pre |
| banksean | 3d1308e | 2025-07-29 17:20:10 +0000 | [diff] [blame] | 104 | 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 overflow-wrap-break-word w-full mb-0 rounded-t rounded-b-none box-border" |
| Josh Bleecher Snyder | 4594388 | 2025-07-18 02:13:31 +0000 | [diff] [blame] | 105 | > |
| Autoformatter | 9d9c812 | 2025-07-18 03:37:23 +0000 | [diff] [blame] | 106 | ${backgroundIcon}${slowIcon}${inputData?.command}</pre |
| 107 | > |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 108 | </div> |
| 109 | </div>`; |
| 110 | |
| 111 | const resultContent = this.toolCall?.result_message?.tool_result |
| 112 | ? html`<div class="w-full relative"> |
| 113 | ${createPreElement( |
| 114 | this.toolCall.result_message.tool_result, |
| 115 | "mt-0 text-gray-600 rounded-t-none rounded-b w-full box-border max-h-[300px] overflow-y-auto", |
| 116 | )} |
| 117 | </div>` |
| 118 | : ""; |
| 119 | |
| 120 | return html`<sketch-tool-card-base |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 121 | .open=${this.open} |
| 122 | .toolCall=${this.toolCall} |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 123 | .summaryContent=${summaryContent} |
| 124 | .inputContent=${inputContent} |
| 125 | .resultContent=${resultContent} |
| 126 | ></sketch-tool-card-base>`; |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
| 130 | @customElement("sketch-tool-card-codereview") |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 131 | export class SketchToolCardCodeReview extends SketchTailwindElement { |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 132 | @property() toolCall: ToolCall; |
| 133 | @property() open: boolean; |
| 134 | |
| 135 | // Determine the status icon based on the content of the result message |
| 136 | getStatusIcon(resultText: string): string { |
| 137 | if (!resultText) return ""; |
| 138 | if (resultText === "OK") return "✔️"; |
| 139 | if (resultText.includes("# Errors")) return "⚠️"; |
| 140 | if (resultText.includes("# Info")) return "ℹ️"; |
| 141 | if (resultText.includes("uncommitted changes in repo")) return "🧹"; |
| 142 | if (resultText.includes("no new commits have been added")) return "🐣"; |
| 143 | if (resultText.includes("git repo is not clean")) return "🧼"; |
| 144 | return "❓"; |
| 145 | } |
| 146 | |
| 147 | render() { |
| 148 | const resultText = this.toolCall?.result_message?.tool_result || ""; |
| 149 | const statusIcon = this.getStatusIcon(resultText); |
| 150 | |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 151 | const summaryContent = html`<span>${statusIcon}</span>`; |
| 152 | const resultContent = resultText ? createPreElement(resultText) : ""; |
| 153 | |
| 154 | return html`<sketch-tool-card-base |
| 155 | .open=${this.open} |
| 156 | .toolCall=${this.toolCall} |
| 157 | .summaryContent=${summaryContent} |
| 158 | .resultContent=${resultContent} |
| 159 | ></sketch-tool-card-base>`; |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | |
| 163 | @customElement("sketch-tool-card-done") |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 164 | export class SketchToolCardDone extends SketchTailwindElement { |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 165 | @property() toolCall: ToolCall; |
| 166 | @property() open: boolean; |
| 167 | |
| 168 | render() { |
| 169 | const doneInput = JSON.parse(this.toolCall.input); |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 170 | |
| 171 | const summaryContent = html`<span></span>`; |
| 172 | |
| 173 | const resultContent = html`<div> |
| 174 | ${Object.keys(doneInput.checklist_items).map((key) => { |
| 175 | const item = doneInput.checklist_items[key]; |
| 176 | let statusIcon = "〰️"; |
| 177 | if (item.status == "yes") { |
| 178 | statusIcon = "✅"; |
| 179 | } else if (item.status == "not applicable") { |
| 180 | statusIcon = "🤷"; |
| 181 | } |
| 182 | return html`<div class="mb-1"> |
| 183 | <span>${statusIcon}</span> ${key}:${item.status} |
| 184 | </div>`; |
| 185 | })} |
| 186 | </div>`; |
| 187 | |
| 188 | return html`<sketch-tool-card-base |
| 189 | .open=${this.open} |
| 190 | .toolCall=${this.toolCall} |
| 191 | .summaryContent=${summaryContent} |
| 192 | .resultContent=${resultContent} |
| 193 | ></sketch-tool-card-base>`; |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
| 197 | @customElement("sketch-tool-card-patch") |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 198 | export class SketchToolCardPatch extends SketchTailwindElement { |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 199 | @property() toolCall: ToolCall; |
| 200 | @property() open: boolean; |
| 201 | |
| Josh Bleecher Snyder | 3dd3e41 | 2025-07-22 20:32:03 -0700 | [diff] [blame] | 202 | // Render a diff with syntax highlighting |
| 203 | renderDiff(diff: string) { |
| 204 | // Remove ---/+++ header lines and trim leading/trailing blank lines |
| 205 | const lines = diff |
| 206 | .split("\n") |
| 207 | .filter((line) => !line.startsWith("---") && !line.startsWith("+++")) |
| 208 | .join("\n") |
| 209 | .trim() |
| 210 | .split("\n"); |
| 211 | |
| 212 | const coloredLines = lines.map((line) => { |
| 213 | if (line.startsWith("+")) { |
| Josh Bleecher Snyder | 6b1ceb1 | 2025-07-30 12:09:43 -0700 | [diff] [blame] | 214 | // prettier-ignore |
| 215 | return html`<div class="text-green-600 dark:text-green-400 bg-green-50 dark:bg-green-900/20">${line}</div>`; |
| Josh Bleecher Snyder | 3dd3e41 | 2025-07-22 20:32:03 -0700 | [diff] [blame] | 216 | } else if (line.startsWith("-")) { |
| Josh Bleecher Snyder | 6b1ceb1 | 2025-07-30 12:09:43 -0700 | [diff] [blame] | 217 | // prettier-ignore |
| 218 | return html`<div class="text-red-600 dark:text-red-400 bg-red-50 dark:bg-red-900/20">${line}</div>`; |
| Josh Bleecher Snyder | 3dd3e41 | 2025-07-22 20:32:03 -0700 | [diff] [blame] | 219 | } else if (line.startsWith("@@")) { |
| 220 | // prettier-ignore |
| banksean | 3d1308e | 2025-07-29 17:20:10 +0000 | [diff] [blame] | 221 | return html`<div class="text-cyan-600 dark:text-cyan-400 bg-cyan-50 dark:bg-cyan-900/20 font-semibold">${line}</div>`; |
| Josh Bleecher Snyder | 3dd3e41 | 2025-07-22 20:32:03 -0700 | [diff] [blame] | 222 | } else { |
| Josh Bleecher Snyder | 6b1ceb1 | 2025-07-30 12:09:43 -0700 | [diff] [blame] | 223 | // prettier-ignore |
| 224 | return html`<div class="text-gray-800 dark:text-gray-200">${line}</div>`; |
| Josh Bleecher Snyder | 3dd3e41 | 2025-07-22 20:32:03 -0700 | [diff] [blame] | 225 | } |
| 226 | }); |
| 227 | |
| Josh Bleecher Snyder | 6b1ceb1 | 2025-07-30 12:09:43 -0700 | [diff] [blame] | 228 | // prettier-ignore |
| 229 | return html`<pre class="bg-gray-100 dark:bg-gray-800 text-xs p-2 rounded whitespace-pre-wrap break-words max-w-full w-full box-border overflow-x-auto font-mono text-gray-900 dark:text-gray-100">${coloredLines}</pre>`; |
| Josh Bleecher Snyder | 3dd3e41 | 2025-07-22 20:32:03 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 232 | render() { |
| 233 | const patchInput = JSON.parse(this.toolCall?.input); |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 234 | |
| Autoformatter | 2c3e02c | 2025-07-31 00:41:49 +0000 | [diff] [blame^] | 235 | const toolFailed = this.toolCall?.result_message?.tool_error; |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 236 | const summaryContent = html`<span |
| 237 | class="text-gray-600 font-mono overflow-hidden text-ellipsis whitespace-nowrap rounded" |
| 238 | > |
| Autoformatter | 2c3e02c | 2025-07-31 00:41:49 +0000 | [diff] [blame^] | 239 | ${toolFailed |
| Josh Bleecher Snyder | 10bd3a6 | 2025-07-30 23:55:50 +0000 | [diff] [blame] | 240 | ? `${patchInput?.path}: failed` |
| Autoformatter | 2c3e02c | 2025-07-31 00:41:49 +0000 | [diff] [blame^] | 241 | : `${patchInput?.path}: ${patchInput.patches.length} edit${patchInput.patches.length > 1 ? "s" : ""}`} |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 242 | </span>`; |
| 243 | |
| Josh Bleecher Snyder | 3dd3e41 | 2025-07-22 20:32:03 -0700 | [diff] [blame] | 244 | const inputContent = html``; |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 245 | |
| Josh Bleecher Snyder | 3dd3e41 | 2025-07-22 20:32:03 -0700 | [diff] [blame] | 246 | // Show diff if available, otherwise show the regular result |
| 247 | let resultContent; |
| 248 | if ( |
| 249 | this.toolCall?.result_message?.display && |
| 250 | typeof this.toolCall.result_message.display === "string" |
| 251 | ) { |
| 252 | // Render the diff with syntax highlighting |
| 253 | resultContent = html`<div class="w-full relative"> |
| 254 | ${this.renderDiff(this.toolCall.result_message.display)} |
| 255 | </div>`; |
| 256 | } else if (this.toolCall?.result_message?.tool_result) { |
| 257 | resultContent = createPreElement( |
| 258 | this.toolCall.result_message.tool_result, |
| 259 | ); |
| 260 | } else { |
| 261 | resultContent = ""; |
| 262 | } |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 263 | |
| 264 | return html`<sketch-tool-card-base |
| 265 | .open=${this.open} |
| 266 | .toolCall=${this.toolCall} |
| 267 | .summaryContent=${summaryContent} |
| 268 | .inputContent=${inputContent} |
| 269 | .resultContent=${resultContent} |
| 270 | ></sketch-tool-card-base>`; |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | |
| 274 | @customElement("sketch-tool-card-think") |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 275 | export class SketchToolCardThink extends SketchTailwindElement { |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 276 | @property() toolCall: ToolCall; |
| 277 | @property() open: boolean; |
| 278 | |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 279 | render() { |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 280 | const thoughts = JSON.parse(this.toolCall?.input)?.thoughts || ""; |
| 281 | |
| 282 | const summaryContent = html`<span |
| 283 | class="overflow-hidden text-ellipsis font-mono" |
| 284 | > |
| 285 | ${thoughts.split("\n")[0]} |
| 286 | </span>`; |
| 287 | |
| 288 | const inputContent = html`<div |
| banksean | 3d1308e | 2025-07-29 17:20:10 +0000 | [diff] [blame] | 289 | class="overflow-x-auto mb-1 font-mono px-2 py-1 bg-gray-200 dark:bg-gray-700 rounded select-text cursor-text text-sm leading-relaxed text-gray-900 dark:text-gray-100" |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 290 | > |
| 291 | <div class="markdown-content"> |
| 292 | ${unsafeHTML(renderMarkdown(thoughts))} |
| 293 | </div> |
| 294 | </div>`; |
| 295 | |
| 296 | return html`<sketch-tool-card-base |
| 297 | .open=${this.open} |
| 298 | .toolCall=${this.toolCall} |
| 299 | .summaryContent=${summaryContent} |
| 300 | .inputContent=${inputContent} |
| 301 | ></sketch-tool-card-base>`; |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 305 | @customElement("sketch-tool-card-todo-write") |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 306 | export class SketchToolCardTodoWrite extends SketchTailwindElement { |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 307 | @property() toolCall: ToolCall; |
| 308 | @property() open: boolean; |
| 309 | |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 310 | render() { |
| 311 | const inputData = JSON.parse(this.toolCall?.input || "{}"); |
| 312 | const tasks = inputData.tasks || []; |
| Josh Bleecher Snyder | 991164f | 2025-05-29 05:02:10 +0000 | [diff] [blame] | 313 | |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 314 | // Generate circles based on task status |
| Josh Bleecher Snyder | 991164f | 2025-05-29 05:02:10 +0000 | [diff] [blame] | 315 | const circles = tasks |
| 316 | .map((task) => { |
| 317 | switch (task.status) { |
| 318 | case "completed": |
| 319 | return "●"; // full circle |
| 320 | case "in-progress": |
| 321 | return "◐"; // half circle |
| 322 | case "queued": |
| 323 | default: |
| 324 | return "○"; // empty circle |
| 325 | } |
| 326 | }) |
| 327 | .join(" "); |
| 328 | |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 329 | const summaryContent = html`<span class="italic text-gray-600"> |
| 330 | ${circles} |
| 331 | </span>`; |
| 332 | const resultContent = this.toolCall?.result_message?.tool_result |
| 333 | ? createPreElement(this.toolCall.result_message.tool_result) |
| 334 | : ""; |
| 335 | |
| 336 | return html`<sketch-tool-card-base |
| 337 | .open=${this.open} |
| 338 | .toolCall=${this.toolCall} |
| 339 | .summaryContent=${summaryContent} |
| 340 | .resultContent=${resultContent} |
| 341 | ></sketch-tool-card-base>`; |
| Josh Bleecher Snyder | 991164f | 2025-05-29 05:02:10 +0000 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | |
| 345 | @customElement("sketch-tool-card-keyword-search") |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 346 | export class SketchToolCardKeywordSearch extends SketchTailwindElement { |
| Josh Bleecher Snyder | 991164f | 2025-05-29 05:02:10 +0000 | [diff] [blame] | 347 | @property() toolCall: ToolCall; |
| 348 | @property() open: boolean; |
| 349 | |
| Josh Bleecher Snyder | 991164f | 2025-05-29 05:02:10 +0000 | [diff] [blame] | 350 | render() { |
| 351 | const inputData = JSON.parse(this.toolCall?.input || "{}"); |
| 352 | const query = inputData.query || ""; |
| 353 | const searchTerms = inputData.search_terms || []; |
| 354 | |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 355 | const summaryContent = html`<div |
| 356 | class="flex flex-col gap-0.5 w-full max-w-full overflow-hidden" |
| 357 | > |
| 358 | <div |
| 359 | class="text-gray-800 text-xs normal-case whitespace-normal break-words leading-tight" |
| 360 | > |
| 361 | 🔍 ${query} |
| Josh Bleecher Snyder | 991164f | 2025-05-29 05:02:10 +0000 | [diff] [blame] | 362 | </div> |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 363 | <div |
| 364 | class="text-gray-600 text-xs normal-case whitespace-normal break-words leading-tight mt-px" |
| 365 | > |
| 366 | 🗝️ ${searchTerms.join(", ")} |
| Josh Bleecher Snyder | 991164f | 2025-05-29 05:02:10 +0000 | [diff] [blame] | 367 | </div> |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 368 | </div>`; |
| 369 | |
| 370 | const inputContent = html`<div> |
| 371 | <div><strong>Query:</strong> ${query}</div> |
| 372 | <div><strong>Search terms:</strong> ${searchTerms.join(", ")}</div> |
| 373 | </div>`; |
| 374 | |
| 375 | const resultContent = this.toolCall?.result_message?.tool_result |
| 376 | ? createPreElement(this.toolCall.result_message.tool_result) |
| 377 | : ""; |
| 378 | |
| 379 | return html`<sketch-tool-card-base |
| 380 | .open=${this.open} |
| 381 | .toolCall=${this.toolCall} |
| 382 | .summaryContent=${summaryContent} |
| 383 | .inputContent=${inputContent} |
| 384 | .resultContent=${resultContent} |
| 385 | ></sketch-tool-card-base>`; |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | |
| 389 | @customElement("sketch-tool-card-todo-read") |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 390 | export class SketchToolCardTodoRead extends SketchTailwindElement { |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 391 | @property() toolCall: ToolCall; |
| 392 | @property() open: boolean; |
| 393 | |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 394 | render() { |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 395 | const summaryContent = html`<span class="italic text-gray-600"> |
| 396 | Read todo list |
| 397 | </span>`; |
| 398 | const resultContent = this.toolCall?.result_message?.tool_result |
| 399 | ? createPreElement(this.toolCall.result_message.tool_result) |
| 400 | : ""; |
| 401 | |
| 402 | return html`<sketch-tool-card-base |
| 403 | .open=${this.open} |
| 404 | .toolCall=${this.toolCall} |
| 405 | .summaryContent=${summaryContent} |
| 406 | .resultContent=${resultContent} |
| 407 | ></sketch-tool-card-base>`; |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 411 | @customElement("sketch-tool-card-generic") |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 412 | export class SketchToolCardGeneric extends SketchTailwindElement { |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 413 | @property() toolCall: ToolCall; |
| 414 | @property() open: boolean; |
| 415 | |
| 416 | render() { |
| banksean | 333aa67 | 2025-07-13 19:49:21 +0000 | [diff] [blame] | 417 | const summaryContent = html`<span |
| 418 | class="block whitespace-normal break-words max-w-full w-full" |
| 419 | > |
| 420 | ${this.toolCall?.input} |
| 421 | </span>`; |
| 422 | |
| 423 | const inputContent = html`<div class="max-w-full break-words"> |
| 424 | Input: |
| 425 | ${createPreElement( |
| 426 | this.toolCall?.input || "", |
| 427 | "max-w-full whitespace-pre-wrap break-words", |
| 428 | )} |
| 429 | </div>`; |
| 430 | |
| 431 | const resultContent = this.toolCall?.result_message?.tool_result |
| 432 | ? html`<div class="max-w-full break-words"> |
| 433 | Result: ${createPreElement(this.toolCall.result_message.tool_result)} |
| 434 | </div>` |
| 435 | : ""; |
| 436 | |
| 437 | return html`<sketch-tool-card-base |
| 438 | .open=${this.open} |
| 439 | .toolCall=${this.toolCall} |
| 440 | .summaryContent=${summaryContent} |
| 441 | .inputContent=${inputContent} |
| 442 | .resultContent=${resultContent} |
| 443 | ></sketch-tool-card-base>`; |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 447 | declare global { |
| 448 | interface HTMLElementTagNameMap { |
| Pokey Rule | 7ac5ed0 | 2025-05-07 15:26:10 +0100 | [diff] [blame] | 449 | "sketch-tool-card-generic": SketchToolCardGeneric; |
| 450 | "sketch-tool-card-bash": SketchToolCardBash; |
| 451 | "sketch-tool-card-codereview": SketchToolCardCodeReview; |
| 452 | "sketch-tool-card-done": SketchToolCardDone; |
| 453 | "sketch-tool-card-patch": SketchToolCardPatch; |
| 454 | "sketch-tool-card-think": SketchToolCardThink; |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 455 | "sketch-tool-card-todo-write": SketchToolCardTodoWrite; |
| 456 | "sketch-tool-card-todo-read": SketchToolCardTodoRead; |
| Josh Bleecher Snyder | 991164f | 2025-05-29 05:02:10 +0000 | [diff] [blame] | 457 | "sketch-tool-card-keyword-search": SketchToolCardKeywordSearch; |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 458 | } |
| 459 | } |