| 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", |
| 8 | imports: ["../sketch-tool-card.ts"], |
| 9 | |
| 10 | setup: async (container: HTMLElement) => { |
| 11 | const section = demoUtils.createDemoSection( |
| 12 | "Tool Card Components", |
| 13 | "Shows different tool card components for bash, codereview, done, patch, think, title, and multiple-choice tools", |
| 14 | ); |
| 15 | |
| 16 | // Sample tool calls from the original demo |
| 17 | const toolCalls = [ |
| 18 | { |
| 19 | name: "multiple-choice", |
| 20 | input: JSON.stringify({ |
| 21 | question: "What is your favorite programming language?", |
| 22 | choices: [ |
| 23 | "JavaScript", |
| 24 | "TypeScript", |
| 25 | "Python", |
| 26 | "Go", |
| 27 | "Rust", |
| 28 | "Java", |
| 29 | "C#", |
| 30 | "C++", |
| 31 | ], |
| 32 | }), |
| 33 | result_message: { |
| 34 | type: "tool", |
| 35 | tool_result: JSON.stringify({ |
| 36 | selected: "Go", |
| 37 | }), |
| 38 | }, |
| 39 | }, |
| 40 | { |
| 41 | name: "bash", |
| 42 | input: JSON.stringify({ |
| 43 | command: |
| 44 | "docker ps -a --format '{{.ID}} {{.Image }} {{.Names}}' | grep sketch", |
| 45 | background: true, |
| 46 | slow_ok: true, |
| 47 | }), |
| 48 | result_message: { |
| 49 | type: "tool", |
| 50 | tool_result: `Deleted Images: |
| 51 | deleted: sha256:110d4aed8bcc76cb7327412504af8aef31670b816453a3088d834bbeefd11a2c |
| 52 | deleted: sha256:042622460c913078901555a8a72de18e95228fca98b9ac388503b3baafafb683 |
| 53 | |
| 54 | Total reclaimed space: 1.426GB`, |
| 55 | }, |
| 56 | }, |
| 57 | { |
| 58 | name: "bash", |
| 59 | input: JSON.stringify({ |
| 60 | command: "sleep 200", |
| 61 | slow_ok: true, |
| 62 | }), |
| 63 | result_message: { |
| 64 | type: "tool", |
| 65 | tool_error: "the user canceled this operation", |
| 66 | }, |
| 67 | }, |
| 68 | { |
| 69 | name: "codereview", |
| 70 | input: "{}", |
| 71 | tool_call_id: "toolu_01WT5qQwHZgdogfKhkD8R9PZ", |
| 72 | result_message: { |
| 73 | type: "tool", |
| 74 | end_of_turn: false, |
| 75 | content: "", |
| 76 | tool_name: "codereview", |
| 77 | input: "{}", |
| 78 | tool_result: "OK", |
| 79 | tool_call_id: "toolu_01WT5qQwHZgdogfKhkD8R9PZ", |
| 80 | timestamp: "2025-04-14T16:33:17.575759565Z", |
| 81 | conversation_id: "xsa-8hw0", |
| 82 | start_time: "2025-04-14T16:33:07.11793816Z", |
| 83 | end_time: "2025-04-14T16:33:17.57575719Z", |
| 84 | elapsed: 10457819031, |
| 85 | idx: 45, |
| 86 | }, |
| 87 | }, |
| 88 | { |
| 89 | name: "think", |
| 90 | input: JSON.stringify({ |
| 91 | thoughts: |
| 92 | "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", |
| 93 | }), |
| 94 | tool_call_id: "toolu_01R1g5mQVgKxEJZFNp9QGvUr", |
| 95 | result_message: { |
| 96 | type: "tool", |
| 97 | end_of_turn: false, |
| 98 | content: "", |
| 99 | tool_name: "think", |
| 100 | input: JSON.stringify({ |
| 101 | thoughts: |
| 102 | "I'm going to inspect a few key components to understand their purpose and relationships", |
| 103 | }), |
| 104 | tool_result: "recorded", |
| 105 | tool_call_id: "toolu_01R1g5mQVgKxEJZFNp9QGvUr", |
| 106 | timestamp: "2025-04-14T16:32:14.12647133Z", |
| 107 | conversation_id: "xsa-8hw0", |
| 108 | start_time: "2025-04-14T16:32:14.126454329Z", |
| 109 | end_time: "2025-04-14T16:32:14.126468539Z", |
| 110 | elapsed: 14209, |
| 111 | idx: 18, |
| 112 | }, |
| 113 | }, |
| 114 | { |
| 115 | name: "patch", |
| 116 | input: JSON.stringify({ |
| 117 | path: "/app/webui/src/web-components/README.md", |
| 118 | patches: [ |
| 119 | { |
| 120 | operation: "overwrite", |
| 121 | newText: |
| 122 | "# Web Components\n\nThis directory contains custom web components...", |
| 123 | }, |
| 124 | ], |
| 125 | }), |
| 126 | tool_call_id: "toolu_01TNhLX2AWkZwsu2KCLKrpju", |
| 127 | result_message: { |
| 128 | type: "tool", |
| 129 | tool_result: "- Applied all patches\n", |
| 130 | tool_call_id: "toolu_01TNhLX2AWkZwsu2KCLKrpju", |
| 131 | }, |
| 132 | }, |
| 133 | { |
| 134 | name: "title", |
| 135 | input: JSON.stringify({ |
| 136 | title: "a new title for this sketch", |
| 137 | }), |
| 138 | }, |
| 139 | { |
| 140 | name: "done", |
| 141 | input: JSON.stringify({ |
| 142 | checklist_items: { |
| 143 | code_reviewed: { |
| 144 | status: "yes", |
| 145 | description: |
| 146 | "If any commits were made, the codereview tool was run and its output was addressed.", |
| 147 | comments: "Code review completed successfully", |
| 148 | }, |
| 149 | git_commit: { |
| 150 | status: "yes", |
| 151 | description: "Create git commits for any code changes you made.", |
| 152 | comments: "All changes committed", |
| 153 | }, |
| 154 | }, |
| 155 | }), |
| 156 | tool_call_id: "toolu_01HPgWQJF1aF9LUqkdDKWeES", |
| 157 | result_message: { |
| 158 | type: "tool", |
| 159 | tool_result: |
| 160 | "codereview tool has not been run for commit 0b1f45dc17fbe7800f5164993ec99d6564256787", |
| 161 | tool_error: true, |
| 162 | tool_call_id: "toolu_01HPgWQJF1aF9LUqkdDKWeES", |
| 163 | }, |
| 164 | }, |
| 165 | ]; |
| 166 | |
| 167 | // Create tool cards for each tool call |
| 168 | toolCalls.forEach((toolCall) => { |
| 169 | const toolSection = document.createElement("div"); |
| 170 | toolSection.style.marginBottom = "2rem"; |
| 171 | toolSection.style.border = "1px solid #eee"; |
| 172 | toolSection.style.borderRadius = "8px"; |
| 173 | toolSection.style.padding = "1rem"; |
| 174 | |
| 175 | const header = document.createElement("h3"); |
| 176 | header.textContent = `Tool: ${toolCall.name}`; |
| 177 | header.style.marginTop = "0"; |
| 178 | header.style.marginBottom = "1rem"; |
| 179 | header.style.color = "#333"; |
| 180 | toolSection.appendChild(header); |
| 181 | |
| 182 | // Create the appropriate tool card element |
| 183 | let toolCardEl; |
| 184 | switch (toolCall.name) { |
| 185 | case "bash": |
| 186 | toolCardEl = document.createElement("sketch-tool-card-bash"); |
| 187 | break; |
| 188 | case "codereview": |
| 189 | toolCardEl = document.createElement("sketch-tool-card-codereview"); |
| 190 | break; |
| 191 | case "done": |
| 192 | toolCardEl = document.createElement("sketch-tool-card-done"); |
| 193 | break; |
| 194 | case "patch": |
| 195 | toolCardEl = document.createElement("sketch-tool-card-patch"); |
| 196 | break; |
| 197 | case "think": |
| 198 | toolCardEl = document.createElement("sketch-tool-card-think"); |
| 199 | break; |
| 200 | case "title": |
| 201 | toolCardEl = document.createElement("sketch-tool-card-title"); |
| 202 | break; |
| 203 | case "multiple-choice": |
| 204 | toolCardEl = document.createElement( |
| 205 | "sketch-tool-card-multiple-choice", |
| 206 | ); |
| 207 | break; |
| 208 | default: |
| 209 | toolCardEl = document.createElement("sketch-tool-card-generic"); |
| 210 | break; |
| 211 | } |
| 212 | |
| 213 | toolCardEl.toolCall = toolCall; |
| 214 | toolCardEl.open = true; |
| 215 | |
| 216 | toolSection.appendChild(toolCardEl); |
| 217 | section.appendChild(toolSection); |
| 218 | }); |
| 219 | |
| 220 | container.appendChild(section); |
| 221 | }, |
| 222 | }; |
| 223 | |
| 224 | export default demo; |