| banksean | d52d39d | 2025-07-20 14:57:38 -0700 | [diff] [blame] | 1 | import { DemoModule } from "./demo-framework/types"; |
| 2 | import { demoUtils } from "./demo-fixtures/index"; |
| 3 | |
| 4 | const demo: DemoModule = { |
| 5 | title: "Sketch Tool Card Demo", |
| 6 | description: |
| 7 | "Demonstration of different tool card components for various tool types", |
| banksean | 1ee0bc6 | 2025-07-22 23:24:18 +0000 | [diff] [blame] | 8 | imports: [ |
| 9 | "../sketch-tool-card.ts", |
| 10 | "../sketch-tool-card-about-sketch.ts", |
| 11 | "../sketch-tool-card-browser-clear-console-logs.ts", |
| 12 | "../sketch-tool-card-browser-click.ts", |
| 13 | "../sketch-tool-card-browser-eval.ts", |
| 14 | "../sketch-tool-card-browser-get-text.ts", |
| 15 | "../sketch-tool-card-browser-navigate.ts", |
| 16 | "../sketch-tool-card-browser-recent-console-logs.ts", |
| 17 | "../sketch-tool-card-browser-resize.ts", |
| 18 | "../sketch-tool-card-browser-scroll-into-view.ts", |
| 19 | "../sketch-tool-card-browser-type.ts", |
| 20 | "../sketch-tool-card-browser-wait-for.ts", |
| 21 | "../sketch-tool-card-read-image.ts", |
| 22 | "../sketch-tool-card-take-screenshot.ts", |
| 23 | ], |
| banksean | d52d39d | 2025-07-20 14:57:38 -0700 | [diff] [blame] | 24 | |
| 25 | setup: async (container: HTMLElement) => { |
| 26 | const section = demoUtils.createDemoSection( |
| 27 | "Tool Card Components", |
| 28 | "Shows different tool card components for bash, codereview, done, patch, think, title, and multiple-choice tools", |
| 29 | ); |
| 30 | |
| 31 | // Sample tool calls from the original demo |
| 32 | const toolCalls = [ |
| 33 | { |
| 34 | name: "multiple-choice", |
| 35 | input: JSON.stringify({ |
| 36 | question: "What is your favorite programming language?", |
| 37 | choices: [ |
| 38 | "JavaScript", |
| 39 | "TypeScript", |
| 40 | "Python", |
| 41 | "Go", |
| 42 | "Rust", |
| 43 | "Java", |
| 44 | "C#", |
| 45 | "C++", |
| 46 | ], |
| 47 | }), |
| 48 | result_message: { |
| 49 | type: "tool", |
| 50 | tool_result: JSON.stringify({ |
| 51 | selected: "Go", |
| 52 | }), |
| 53 | }, |
| 54 | }, |
| 55 | { |
| 56 | name: "bash", |
| 57 | input: JSON.stringify({ |
| 58 | command: |
| 59 | "docker ps -a --format '{{.ID}} {{.Image }} {{.Names}}' | grep sketch", |
| 60 | background: true, |
| 61 | slow_ok: true, |
| 62 | }), |
| 63 | result_message: { |
| 64 | type: "tool", |
| 65 | tool_result: `Deleted Images: |
| 66 | deleted: sha256:110d4aed8bcc76cb7327412504af8aef31670b816453a3088d834bbeefd11a2c |
| 67 | deleted: sha256:042622460c913078901555a8a72de18e95228fca98b9ac388503b3baafafb683 |
| 68 | |
| 69 | Total reclaimed space: 1.426GB`, |
| 70 | }, |
| 71 | }, |
| 72 | { |
| 73 | name: "bash", |
| 74 | input: JSON.stringify({ |
| 75 | command: "sleep 200", |
| 76 | slow_ok: true, |
| 77 | }), |
| 78 | result_message: { |
| 79 | type: "tool", |
| 80 | tool_error: "the user canceled this operation", |
| 81 | }, |
| 82 | }, |
| 83 | { |
| 84 | name: "codereview", |
| 85 | input: "{}", |
| 86 | tool_call_id: "toolu_01WT5qQwHZgdogfKhkD8R9PZ", |
| 87 | result_message: { |
| 88 | type: "tool", |
| 89 | end_of_turn: false, |
| 90 | content: "", |
| 91 | tool_name: "codereview", |
| 92 | input: "{}", |
| 93 | tool_result: "OK", |
| 94 | tool_call_id: "toolu_01WT5qQwHZgdogfKhkD8R9PZ", |
| 95 | timestamp: "2025-04-14T16:33:17.575759565Z", |
| 96 | conversation_id: "xsa-8hw0", |
| 97 | start_time: "2025-04-14T16:33:07.11793816Z", |
| 98 | end_time: "2025-04-14T16:33:17.57575719Z", |
| 99 | elapsed: 10457819031, |
| 100 | idx: 45, |
| 101 | }, |
| 102 | }, |
| 103 | { |
| 104 | name: "think", |
| 105 | input: JSON.stringify({ |
| 106 | thoughts: |
| 107 | "I'm going to inspect a few key components to understand their purpose and relationships:\n1. sketch-app-shell.ts - Appears to be the main container component\n2. sketch-timeline.ts - Likely manages the chat timeline\n3. sketch-view-mode-select.ts - Handles switching between different views", |
| 108 | }), |
| 109 | tool_call_id: "toolu_01R1g5mQVgKxEJZFNp9QGvUr", |
| 110 | result_message: { |
| 111 | type: "tool", |
| 112 | end_of_turn: false, |
| 113 | content: "", |
| 114 | tool_name: "think", |
| 115 | input: JSON.stringify({ |
| 116 | thoughts: |
| 117 | "I'm going to inspect a few key components to understand their purpose and relationships", |
| 118 | }), |
| 119 | tool_result: "recorded", |
| 120 | tool_call_id: "toolu_01R1g5mQVgKxEJZFNp9QGvUr", |
| 121 | timestamp: "2025-04-14T16:32:14.12647133Z", |
| 122 | conversation_id: "xsa-8hw0", |
| 123 | start_time: "2025-04-14T16:32:14.126454329Z", |
| 124 | end_time: "2025-04-14T16:32:14.126468539Z", |
| 125 | elapsed: 14209, |
| 126 | idx: 18, |
| 127 | }, |
| 128 | }, |
| 129 | { |
| 130 | name: "patch", |
| 131 | input: JSON.stringify({ |
| 132 | path: "/app/webui/src/web-components/README.md", |
| 133 | patches: [ |
| 134 | { |
| 135 | operation: "overwrite", |
| 136 | newText: |
| 137 | "# Web Components\n\nThis directory contains custom web components...", |
| 138 | }, |
| 139 | ], |
| 140 | }), |
| 141 | tool_call_id: "toolu_01TNhLX2AWkZwsu2KCLKrpju", |
| 142 | result_message: { |
| 143 | type: "tool", |
| 144 | tool_result: "- Applied all patches\n", |
| Josh Bleecher Snyder | 3dd3e41 | 2025-07-22 20:32:03 -0700 | [diff] [blame] | 145 | display: |
| 146 | "@@ -1,3 +1,3 @@\n # Web Components\n \n-This directory contains the old components.\n+This directory contains custom web components...", |
| banksean | d52d39d | 2025-07-20 14:57:38 -0700 | [diff] [blame] | 147 | tool_call_id: "toolu_01TNhLX2AWkZwsu2KCLKrpju", |
| 148 | }, |
| 149 | }, |
| 150 | { |
| 151 | name: "title", |
| 152 | input: JSON.stringify({ |
| 153 | title: "a new title for this sketch", |
| 154 | }), |
| 155 | }, |
| 156 | { |
| 157 | name: "done", |
| 158 | input: JSON.stringify({ |
| 159 | checklist_items: { |
| 160 | code_reviewed: { |
| 161 | status: "yes", |
| 162 | description: |
| 163 | "If any commits were made, the codereview tool was run and its output was addressed.", |
| 164 | comments: "Code review completed successfully", |
| 165 | }, |
| 166 | git_commit: { |
| 167 | status: "yes", |
| 168 | description: "Create git commits for any code changes you made.", |
| 169 | comments: "All changes committed", |
| 170 | }, |
| 171 | }, |
| 172 | }), |
| 173 | tool_call_id: "toolu_01HPgWQJF1aF9LUqkdDKWeES", |
| 174 | result_message: { |
| 175 | type: "tool", |
| 176 | tool_result: |
| 177 | "codereview tool has not been run for commit 0b1f45dc17fbe7800f5164993ec99d6564256787", |
| 178 | tool_error: true, |
| 179 | tool_call_id: "toolu_01HPgWQJF1aF9LUqkdDKWeES", |
| 180 | }, |
| 181 | }, |
| banksean | 1ee0bc6 | 2025-07-22 23:24:18 +0000 | [diff] [blame] | 182 | // About Sketch tool |
| 183 | { |
| 184 | name: "about_sketch", |
| 185 | input: "{}", |
| 186 | tool_call_id: "toolu_about_sketch", |
| 187 | result_message: { |
| 188 | type: "tool", |
| 189 | tool_result: |
| 190 | "# Welcome to Sketch\n\nSketch is an AI-powered coding assistant that helps you implement features, debug issues, and understand codebases.\n\n## Key Features\n\n- **Autonomous coding**: I can read, write, and modify code files\n- **Command execution**: I can run shell commands and scripts\n- **Testing**: I can run tests and interpret results\n- **Code review**: I can analyze code quality and suggest improvements\n\n## Getting Started\n\n1. Describe what you want to build or fix\n2. I'll analyze your codebase and create a plan\n3. I'll implement the changes step by step\n4. You can review and provide feedback at any time", |
| 191 | tool_call_id: "toolu_about_sketch", |
| 192 | }, |
| 193 | }, |
| 194 | // Browser navigation |
| 195 | { |
| 196 | name: "browser_navigate", |
| 197 | input: JSON.stringify({ url: "https://example.com" }), |
| 198 | tool_call_id: "toolu_navigate", |
| 199 | result_message: { |
| 200 | type: "tool", |
| 201 | tool_result: "Navigated to https://example.com", |
| 202 | tool_call_id: "toolu_navigate", |
| 203 | }, |
| 204 | }, |
| 205 | // Browser click |
| 206 | { |
| 207 | name: "browser_click", |
| 208 | input: JSON.stringify({ selector: ".login-button" }), |
| 209 | tool_call_id: "toolu_click", |
| 210 | result_message: { |
| 211 | type: "tool", |
| 212 | tool_result: "Clicked element: .login-button", |
| 213 | tool_call_id: "toolu_click", |
| 214 | }, |
| 215 | }, |
| 216 | // Browser type |
| 217 | { |
| 218 | name: "browser_type", |
| 219 | input: JSON.stringify({ selector: "#username", text: "testuser" }), |
| 220 | tool_call_id: "toolu_type", |
| 221 | result_message: { |
| 222 | type: "tool", |
| 223 | tool_result: "Typed 'testuser' into #username", |
| 224 | tool_call_id: "toolu_type", |
| 225 | }, |
| 226 | }, |
| 227 | // Browser get text |
| 228 | { |
| 229 | name: "browser_get_text", |
| 230 | input: JSON.stringify({ selector: ".welcome-message" }), |
| 231 | tool_call_id: "toolu_get_text", |
| 232 | result_message: { |
| 233 | type: "tool", |
| 234 | tool_result: "Welcome to our application! Please log in to continue.", |
| 235 | tool_call_id: "toolu_get_text", |
| 236 | }, |
| 237 | }, |
| 238 | // Browser eval |
| 239 | { |
| 240 | name: "browser_eval", |
| 241 | input: JSON.stringify({ expression: "document.title" }), |
| 242 | tool_call_id: "toolu_eval", |
| 243 | result_message: { |
| 244 | type: "tool", |
| 245 | tool_result: "Example Domain", |
| 246 | tool_call_id: "toolu_eval", |
| 247 | }, |
| 248 | }, |
| 249 | // Browser wait for |
| 250 | { |
| 251 | name: "browser_wait_for", |
| 252 | input: JSON.stringify({ selector: ".loading-complete" }), |
| 253 | tool_call_id: "toolu_wait", |
| 254 | result_message: { |
| 255 | type: "tool", |
| 256 | tool_result: "Element .loading-complete is now present", |
| 257 | tool_call_id: "toolu_wait", |
| 258 | }, |
| 259 | }, |
| 260 | // Browser resize |
| 261 | { |
| 262 | name: "browser_resize", |
| 263 | input: JSON.stringify({ width: 1024, height: 768 }), |
| 264 | tool_call_id: "toolu_resize", |
| 265 | result_message: { |
| 266 | type: "tool", |
| 267 | tool_result: "Browser resized to 1024x768", |
| 268 | tool_call_id: "toolu_resize", |
| 269 | }, |
| 270 | }, |
| 271 | // Browser scroll into view |
| 272 | { |
| 273 | name: "browser_scroll_into_view", |
| 274 | input: JSON.stringify({ selector: "#bottom-section" }), |
| 275 | tool_call_id: "toolu_scroll", |
| 276 | result_message: { |
| 277 | type: "tool", |
| 278 | tool_result: "Scrolled element #bottom-section into view", |
| 279 | tool_call_id: "toolu_scroll", |
| 280 | }, |
| 281 | }, |
| 282 | // Browser clear console logs |
| 283 | { |
| 284 | name: "browser_clear_console_logs", |
| 285 | input: "{}", |
| 286 | tool_call_id: "toolu_clear_logs", |
| 287 | result_message: { |
| 288 | type: "tool", |
| 289 | tool_result: "Console logs cleared", |
| 290 | tool_call_id: "toolu_clear_logs", |
| 291 | }, |
| 292 | }, |
| 293 | // Browser recent console logs |
| 294 | { |
| 295 | name: "browser_recent_console_logs", |
| 296 | input: "{}", |
| 297 | tool_call_id: "toolu_recent_logs", |
| 298 | result_message: { |
| 299 | type: "tool", |
| 300 | tool_result: |
| 301 | "[INFO] Page loaded successfully\n[WARN] Deprecated API usage detected\n[ERROR] Failed to load resource: net::ERR_FAILED", |
| 302 | tool_call_id: "toolu_recent_logs", |
| 303 | }, |
| 304 | }, |
| 305 | // Read image |
| 306 | { |
| 307 | name: "read_image", |
| 308 | input: JSON.stringify({ path: "/tmp/screenshot.png" }), |
| 309 | tool_call_id: "toolu_read_image", |
| 310 | result_message: { |
| 311 | type: "tool", |
| 312 | tool_result: |
| 313 | "Image read successfully: /tmp/screenshot.png (1024x768, 245KB)", |
| 314 | tool_call_id: "toolu_read_image", |
| 315 | }, |
| 316 | }, |
| 317 | // Take screenshot |
| 318 | { |
| 319 | name: "browser_take_screenshot", |
| 320 | input: JSON.stringify({ selector: ".main-content" }), |
| 321 | tool_call_id: "toolu_screenshot", |
| 322 | result_message: { |
| 323 | type: "tool", |
| 324 | tool_result: |
| 325 | "Screenshot taken (saved as /tmp/sketch-screenshots/demo-123.png)", |
| 326 | tool_call_id: "toolu_screenshot", |
| 327 | }, |
| 328 | }, |
| banksean | d52d39d | 2025-07-20 14:57:38 -0700 | [diff] [blame] | 329 | ]; |
| 330 | |
| 331 | // Create tool cards for each tool call |
| 332 | toolCalls.forEach((toolCall) => { |
| 333 | const toolSection = document.createElement("div"); |
| 334 | toolSection.style.marginBottom = "2rem"; |
| 335 | toolSection.style.border = "1px solid #eee"; |
| 336 | toolSection.style.borderRadius = "8px"; |
| 337 | toolSection.style.padding = "1rem"; |
| 338 | |
| 339 | const header = document.createElement("h3"); |
| 340 | header.textContent = `Tool: ${toolCall.name}`; |
| 341 | header.style.marginTop = "0"; |
| 342 | header.style.marginBottom = "1rem"; |
| 343 | header.style.color = "#333"; |
| 344 | toolSection.appendChild(header); |
| 345 | |
| 346 | // Create the appropriate tool card element |
| 347 | let toolCardEl; |
| 348 | switch (toolCall.name) { |
| 349 | case "bash": |
| 350 | toolCardEl = document.createElement("sketch-tool-card-bash"); |
| 351 | break; |
| 352 | case "codereview": |
| 353 | toolCardEl = document.createElement("sketch-tool-card-codereview"); |
| 354 | break; |
| 355 | case "done": |
| 356 | toolCardEl = document.createElement("sketch-tool-card-done"); |
| 357 | break; |
| 358 | case "patch": |
| 359 | toolCardEl = document.createElement("sketch-tool-card-patch"); |
| 360 | break; |
| 361 | case "think": |
| 362 | toolCardEl = document.createElement("sketch-tool-card-think"); |
| 363 | break; |
| 364 | case "title": |
| 365 | toolCardEl = document.createElement("sketch-tool-card-title"); |
| 366 | break; |
| 367 | case "multiple-choice": |
| 368 | toolCardEl = document.createElement( |
| 369 | "sketch-tool-card-multiple-choice", |
| 370 | ); |
| 371 | break; |
| banksean | 1ee0bc6 | 2025-07-22 23:24:18 +0000 | [diff] [blame] | 372 | case "about_sketch": |
| 373 | toolCardEl = document.createElement("sketch-tool-card-about-sketch"); |
| 374 | break; |
| 375 | case "browser_navigate": |
| 376 | toolCardEl = document.createElement( |
| 377 | "sketch-tool-card-browser-navigate", |
| 378 | ); |
| 379 | break; |
| 380 | case "browser_click": |
| 381 | toolCardEl = document.createElement("sketch-tool-card-browser-click"); |
| 382 | break; |
| 383 | case "browser_type": |
| 384 | toolCardEl = document.createElement("sketch-tool-card-browser-type"); |
| 385 | break; |
| 386 | case "browser_get_text": |
| 387 | toolCardEl = document.createElement( |
| 388 | "sketch-tool-card-browser-get-text", |
| 389 | ); |
| 390 | break; |
| 391 | case "browser_eval": |
| 392 | toolCardEl = document.createElement("sketch-tool-card-browser-eval"); |
| 393 | break; |
| 394 | case "browser_wait_for": |
| 395 | toolCardEl = document.createElement( |
| 396 | "sketch-tool-card-browser-wait-for", |
| 397 | ); |
| 398 | break; |
| 399 | case "browser_resize": |
| 400 | toolCardEl = document.createElement( |
| 401 | "sketch-tool-card-browser-resize", |
| 402 | ); |
| 403 | break; |
| 404 | case "browser_scroll_into_view": |
| 405 | toolCardEl = document.createElement( |
| 406 | "sketch-tool-card-browser-scroll-into-view", |
| 407 | ); |
| 408 | break; |
| 409 | case "browser_clear_console_logs": |
| 410 | toolCardEl = document.createElement( |
| 411 | "sketch-tool-card-browser-clear-console-logs", |
| 412 | ); |
| 413 | break; |
| 414 | case "browser_recent_console_logs": |
| 415 | toolCardEl = document.createElement( |
| 416 | "sketch-tool-card-browser-recent-console-logs", |
| 417 | ); |
| 418 | break; |
| 419 | case "read_image": |
| 420 | toolCardEl = document.createElement("sketch-tool-card-read-image"); |
| 421 | break; |
| 422 | case "browser_take_screenshot": |
| 423 | toolCardEl = document.createElement( |
| 424 | "sketch-tool-card-take-screenshot", |
| 425 | ); |
| 426 | break; |
| banksean | d52d39d | 2025-07-20 14:57:38 -0700 | [diff] [blame] | 427 | default: |
| 428 | toolCardEl = document.createElement("sketch-tool-card-generic"); |
| 429 | break; |
| 430 | } |
| 431 | |
| 432 | toolCardEl.toolCall = toolCall; |
| 433 | toolCardEl.open = true; |
| 434 | |
| 435 | toolSection.appendChild(toolCardEl); |
| 436 | section.appendChild(toolSection); |
| 437 | }); |
| 438 | |
| 439 | container.appendChild(section); |
| 440 | }, |
| 441 | }; |
| 442 | |
| 443 | export default demo; |