blob: 95fc18448c9b944933acbf331c52b68e27d553dc [file] [log] [blame]
bankseand52d39d2025-07-20 14:57:38 -07001import { DemoModule } from "./demo-framework/types";
2import { demoUtils } from "./demo-fixtures/index";
3
4const demo: DemoModule = {
5 title: "Sketch Tool Card Demo",
6 description:
7 "Demonstration of different tool card components for various tool types",
banksean1ee0bc62025-07-22 23:24:18 +00008 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",
banksean1ee0bc62025-07-22 23:24:18 +000020 "../sketch-tool-card-read-image.ts",
21 "../sketch-tool-card-take-screenshot.ts",
22 ],
bankseand52d39d2025-07-20 14:57:38 -070023
24 setup: async (container: HTMLElement) => {
25 const section = demoUtils.createDemoSection(
26 "Tool Card Components",
27 "Shows different tool card components for bash, codereview, done, patch, think, title, and multiple-choice tools",
28 );
29
30 // Sample tool calls from the original demo
31 const toolCalls = [
32 {
33 name: "multiple-choice",
34 input: JSON.stringify({
35 question: "What is your favorite programming language?",
36 choices: [
37 "JavaScript",
38 "TypeScript",
39 "Python",
40 "Go",
41 "Rust",
42 "Java",
43 "C#",
44 "C++",
45 ],
46 }),
47 result_message: {
48 type: "tool",
49 tool_result: JSON.stringify({
50 selected: "Go",
51 }),
52 },
53 },
54 {
55 name: "bash",
56 input: JSON.stringify({
57 command:
58 "docker ps -a --format '{{.ID}} {{.Image }} {{.Names}}' | grep sketch",
59 background: true,
60 slow_ok: true,
61 }),
62 result_message: {
63 type: "tool",
64 tool_result: `Deleted Images:
65deleted: sha256:110d4aed8bcc76cb7327412504af8aef31670b816453a3088d834bbeefd11a2c
66deleted: sha256:042622460c913078901555a8a72de18e95228fca98b9ac388503b3baafafb683
67
68Total reclaimed space: 1.426GB`,
69 },
70 },
71 {
72 name: "bash",
73 input: JSON.stringify({
74 command: "sleep 200",
75 slow_ok: true,
76 }),
77 result_message: {
78 type: "tool",
79 tool_error: "the user canceled this operation",
80 },
81 },
82 {
83 name: "codereview",
84 input: "{}",
85 tool_call_id: "toolu_01WT5qQwHZgdogfKhkD8R9PZ",
86 result_message: {
87 type: "tool",
88 end_of_turn: false,
89 content: "",
90 tool_name: "codereview",
91 input: "{}",
92 tool_result: "OK",
93 tool_call_id: "toolu_01WT5qQwHZgdogfKhkD8R9PZ",
94 timestamp: "2025-04-14T16:33:17.575759565Z",
95 conversation_id: "xsa-8hw0",
96 start_time: "2025-04-14T16:33:07.11793816Z",
97 end_time: "2025-04-14T16:33:17.57575719Z",
98 elapsed: 10457819031,
99 idx: 45,
100 },
101 },
102 {
103 name: "think",
104 input: JSON.stringify({
105 thoughts:
106 "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",
107 }),
108 tool_call_id: "toolu_01R1g5mQVgKxEJZFNp9QGvUr",
109 result_message: {
110 type: "tool",
111 end_of_turn: false,
112 content: "",
113 tool_name: "think",
114 input: JSON.stringify({
115 thoughts:
116 "I'm going to inspect a few key components to understand their purpose and relationships",
117 }),
118 tool_result: "recorded",
119 tool_call_id: "toolu_01R1g5mQVgKxEJZFNp9QGvUr",
120 timestamp: "2025-04-14T16:32:14.12647133Z",
121 conversation_id: "xsa-8hw0",
122 start_time: "2025-04-14T16:32:14.126454329Z",
123 end_time: "2025-04-14T16:32:14.126468539Z",
124 elapsed: 14209,
125 idx: 18,
126 },
127 },
128 {
129 name: "patch",
130 input: JSON.stringify({
131 path: "/app/webui/src/web-components/README.md",
132 patches: [
133 {
134 operation: "overwrite",
135 newText:
136 "# Web Components\n\nThis directory contains custom web components...",
137 },
138 ],
139 }),
140 tool_call_id: "toolu_01TNhLX2AWkZwsu2KCLKrpju",
141 result_message: {
142 type: "tool",
143 tool_result: "- Applied all patches\n",
Josh Bleecher Snyder3dd3e412025-07-22 20:32:03 -0700144 display:
145 "@@ -1,3 +1,3 @@\n # Web Components\n \n-This directory contains the old components.\n+This directory contains custom web components...",
bankseand52d39d2025-07-20 14:57:38 -0700146 tool_call_id: "toolu_01TNhLX2AWkZwsu2KCLKrpju",
147 },
148 },
149 {
150 name: "title",
151 input: JSON.stringify({
152 title: "a new title for this sketch",
153 }),
154 },
155 {
156 name: "done",
157 input: JSON.stringify({
158 checklist_items: {
159 code_reviewed: {
160 status: "yes",
161 description:
162 "If any commits were made, the codereview tool was run and its output was addressed.",
163 comments: "Code review completed successfully",
164 },
165 git_commit: {
166 status: "yes",
167 description: "Create git commits for any code changes you made.",
168 comments: "All changes committed",
169 },
170 },
171 }),
172 tool_call_id: "toolu_01HPgWQJF1aF9LUqkdDKWeES",
173 result_message: {
174 type: "tool",
175 tool_result:
176 "codereview tool has not been run for commit 0b1f45dc17fbe7800f5164993ec99d6564256787",
177 tool_error: true,
178 tool_call_id: "toolu_01HPgWQJF1aF9LUqkdDKWeES",
179 },
180 },
banksean1ee0bc62025-07-22 23:24:18 +0000181 // About Sketch tool
182 {
183 name: "about_sketch",
184 input: "{}",
185 tool_call_id: "toolu_about_sketch",
186 result_message: {
187 type: "tool",
188 tool_result:
189 "# 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",
190 tool_call_id: "toolu_about_sketch",
191 },
192 },
193 // Browser navigation
194 {
195 name: "browser_navigate",
196 input: JSON.stringify({ url: "https://example.com" }),
197 tool_call_id: "toolu_navigate",
198 result_message: {
199 type: "tool",
200 tool_result: "Navigated to https://example.com",
201 tool_call_id: "toolu_navigate",
202 },
203 },
banksean1ee0bc62025-07-22 23:24:18 +0000204 // Browser eval
205 {
206 name: "browser_eval",
207 input: JSON.stringify({ expression: "document.title" }),
208 tool_call_id: "toolu_eval",
209 result_message: {
210 type: "tool",
211 tool_result: "Example Domain",
212 tool_call_id: "toolu_eval",
213 },
214 },
banksean1ee0bc62025-07-22 23:24:18 +0000215 // Browser clear console logs
216 {
217 name: "browser_clear_console_logs",
218 input: "{}",
219 tool_call_id: "toolu_clear_logs",
220 result_message: {
221 type: "tool",
222 tool_result: "Console logs cleared",
223 tool_call_id: "toolu_clear_logs",
224 },
225 },
226 // Browser recent console logs
227 {
228 name: "browser_recent_console_logs",
229 input: "{}",
230 tool_call_id: "toolu_recent_logs",
231 result_message: {
232 type: "tool",
233 tool_result:
234 "[INFO] Page loaded successfully\n[WARN] Deprecated API usage detected\n[ERROR] Failed to load resource: net::ERR_FAILED",
235 tool_call_id: "toolu_recent_logs",
236 },
237 },
238 // Read image
239 {
240 name: "read_image",
241 input: JSON.stringify({ path: "/tmp/screenshot.png" }),
242 tool_call_id: "toolu_read_image",
243 result_message: {
244 type: "tool",
245 tool_result:
246 "Image read successfully: /tmp/screenshot.png (1024x768, 245KB)",
247 tool_call_id: "toolu_read_image",
248 },
249 },
250 // Take screenshot
251 {
252 name: "browser_take_screenshot",
253 input: JSON.stringify({ selector: ".main-content" }),
254 tool_call_id: "toolu_screenshot",
255 result_message: {
256 type: "tool",
257 tool_result:
258 "Screenshot taken (saved as /tmp/sketch-screenshots/demo-123.png)",
259 tool_call_id: "toolu_screenshot",
260 },
261 },
bankseand52d39d2025-07-20 14:57:38 -0700262 ];
263
264 // Create tool cards for each tool call
265 toolCalls.forEach((toolCall) => {
266 const toolSection = document.createElement("div");
267 toolSection.style.marginBottom = "2rem";
268 toolSection.style.border = "1px solid #eee";
269 toolSection.style.borderRadius = "8px";
270 toolSection.style.padding = "1rem";
271
272 const header = document.createElement("h3");
273 header.textContent = `Tool: ${toolCall.name}`;
274 header.style.marginTop = "0";
275 header.style.marginBottom = "1rem";
276 header.style.color = "#333";
277 toolSection.appendChild(header);
278
279 // Create the appropriate tool card element
280 let toolCardEl;
281 switch (toolCall.name) {
282 case "bash":
283 toolCardEl = document.createElement("sketch-tool-card-bash");
284 break;
285 case "codereview":
286 toolCardEl = document.createElement("sketch-tool-card-codereview");
287 break;
288 case "done":
289 toolCardEl = document.createElement("sketch-tool-card-done");
290 break;
291 case "patch":
292 toolCardEl = document.createElement("sketch-tool-card-patch");
293 break;
294 case "think":
295 toolCardEl = document.createElement("sketch-tool-card-think");
296 break;
297 case "title":
298 toolCardEl = document.createElement("sketch-tool-card-title");
299 break;
300 case "multiple-choice":
301 toolCardEl = document.createElement(
302 "sketch-tool-card-multiple-choice",
303 );
304 break;
banksean1ee0bc62025-07-22 23:24:18 +0000305 case "about_sketch":
306 toolCardEl = document.createElement("sketch-tool-card-about-sketch");
307 break;
308 case "browser_navigate":
309 toolCardEl = document.createElement(
310 "sketch-tool-card-browser-navigate",
311 );
312 break;
banksean1ee0bc62025-07-22 23:24:18 +0000313 case "browser_eval":
314 toolCardEl = document.createElement("sketch-tool-card-browser-eval");
315 break;
banksean1ee0bc62025-07-22 23:24:18 +0000316 case "browser_clear_console_logs":
317 toolCardEl = document.createElement(
318 "sketch-tool-card-browser-clear-console-logs",
319 );
320 break;
321 case "browser_recent_console_logs":
322 toolCardEl = document.createElement(
323 "sketch-tool-card-browser-recent-console-logs",
324 );
325 break;
326 case "read_image":
327 toolCardEl = document.createElement("sketch-tool-card-read-image");
328 break;
329 case "browser_take_screenshot":
330 toolCardEl = document.createElement(
331 "sketch-tool-card-take-screenshot",
332 );
333 break;
bankseand52d39d2025-07-20 14:57:38 -0700334 default:
335 toolCardEl = document.createElement("sketch-tool-card-generic");
336 break;
337 }
338
339 toolCardEl.toolCall = toolCall;
340 toolCardEl.open = true;
341
342 toolSection.appendChild(toolCardEl);
343 section.appendChild(toolSection);
344 });
345
346 container.appendChild(section);
347 },
348};
349
350export default demo;