| Sean McCullough | 618bfb2 | 2025-06-25 20:52:30 +0000 | [diff] [blame] | 1 | /** |
| 2 | * Demo module for sketch-tool-calls component |
| 3 | */ |
| 4 | |
| 5 | import { DemoModule } from "./demo-framework/types"; |
| 6 | import { |
| 7 | demoUtils, |
| 8 | sampleToolCalls, |
| 9 | multipleToolCallGroups, |
| 10 | longBashCommand, |
| 11 | } from "./demo-fixtures/index"; |
| 12 | |
| 13 | const demo: DemoModule = { |
| 14 | title: "Tool Calls Demo", |
| 15 | description: "Interactive tool call display with various tool types", |
| 16 | imports: ["../sketch-tool-calls"], |
| 17 | |
| 18 | setup: async (container: HTMLElement) => { |
| 19 | // Create demo sections |
| 20 | const basicSection = demoUtils.createDemoSection( |
| 21 | "Basic Tool Calls", |
| 22 | "Various types of tool calls with results", |
| 23 | ); |
| 24 | |
| 25 | const interactiveSection = demoUtils.createDemoSection( |
| 26 | "Interactive Examples", |
| 27 | "Tool calls that can be modified and updated", |
| 28 | ); |
| 29 | |
| 30 | const groupsSection = demoUtils.createDemoSection( |
| 31 | "Tool Call Groups", |
| 32 | "Multiple tool calls grouped together", |
| 33 | ); |
| 34 | |
| 35 | // Basic tool calls component |
| 36 | const basicToolCalls = document.createElement("sketch-tool-calls") as any; |
| 37 | basicToolCalls.toolCalls = sampleToolCalls.slice(0, 3); |
| 38 | |
| 39 | // Interactive tool calls component |
| 40 | const interactiveToolCalls = document.createElement( |
| 41 | "sketch-tool-calls", |
| 42 | ) as any; |
| 43 | interactiveToolCalls.toolCalls = [sampleToolCalls[0]]; |
| 44 | |
| 45 | // Control buttons for interaction |
| 46 | const controlsDiv = document.createElement("div"); |
| 47 | controlsDiv.style.cssText = "margin-top: 15px;"; |
| 48 | |
| 49 | const addBashButton = demoUtils.createButton("Add Bash Command", () => { |
| 50 | const currentCalls = interactiveToolCalls.toolCalls || []; |
| 51 | interactiveToolCalls.toolCalls = [...currentCalls, sampleToolCalls[2]]; |
| 52 | }); |
| 53 | |
| 54 | const addLongCommandButton = demoUtils.createButton( |
| 55 | "Add Long Command", |
| 56 | () => { |
| 57 | const currentCalls = interactiveToolCalls.toolCalls || []; |
| 58 | interactiveToolCalls.toolCalls = [...currentCalls, longBashCommand]; |
| 59 | }, |
| 60 | ); |
| 61 | |
| 62 | const clearButton = demoUtils.createButton("Clear Tool Calls", () => { |
| 63 | interactiveToolCalls.toolCalls = []; |
| 64 | }); |
| 65 | |
| 66 | const resetButton = demoUtils.createButton("Reset to Default", () => { |
| 67 | interactiveToolCalls.toolCalls = [sampleToolCalls[0]]; |
| 68 | }); |
| 69 | |
| 70 | controlsDiv.appendChild(addBashButton); |
| 71 | controlsDiv.appendChild(addLongCommandButton); |
| 72 | controlsDiv.appendChild(clearButton); |
| 73 | controlsDiv.appendChild(resetButton); |
| 74 | |
| 75 | // Tool call groups |
| 76 | const groupsContainer = document.createElement("div"); |
| 77 | multipleToolCallGroups.forEach((group, index) => { |
| 78 | const groupHeader = document.createElement("h4"); |
| 79 | groupHeader.textContent = `Group ${index + 1}`; |
| banksean | 1ee0bc6 | 2025-07-22 23:24:18 +0000 | [diff] [blame] | 80 | groupHeader.style.cssText = |
| 81 | "margin: 20px 0 10px 0; color: var(--demo-label-color);"; |
| Sean McCullough | 618bfb2 | 2025-06-25 20:52:30 +0000 | [diff] [blame] | 82 | |
| 83 | const groupToolCalls = document.createElement("sketch-tool-calls") as any; |
| 84 | groupToolCalls.toolCalls = group; |
| 85 | |
| 86 | groupsContainer.appendChild(groupHeader); |
| 87 | groupsContainer.appendChild(groupToolCalls); |
| 88 | }); |
| 89 | |
| 90 | // Progressive loading demo |
| 91 | const progressiveSection = demoUtils.createDemoSection( |
| 92 | "Progressive Loading Demo", |
| 93 | "Tool calls that appear one by one", |
| 94 | ); |
| 95 | |
| 96 | const progressiveToolCalls = document.createElement( |
| 97 | "sketch-tool-calls", |
| 98 | ) as any; |
| 99 | progressiveToolCalls.toolCalls = []; |
| 100 | |
| 101 | const startProgressiveButton = demoUtils.createButton( |
| 102 | "Start Progressive Load", |
| 103 | async () => { |
| 104 | progressiveToolCalls.toolCalls = []; |
| 105 | |
| 106 | for (let i = 0; i < sampleToolCalls.length; i++) { |
| 107 | await demoUtils.delay(1000); |
| 108 | const currentCalls = progressiveToolCalls.toolCalls || []; |
| 109 | progressiveToolCalls.toolCalls = [ |
| 110 | ...currentCalls, |
| 111 | sampleToolCalls[i], |
| 112 | ]; |
| 113 | } |
| 114 | }, |
| 115 | ); |
| 116 | |
| 117 | const progressiveControls = document.createElement("div"); |
| 118 | progressiveControls.style.cssText = "margin-top: 15px;"; |
| 119 | progressiveControls.appendChild(startProgressiveButton); |
| 120 | |
| 121 | // Assemble the demo |
| 122 | basicSection.appendChild(basicToolCalls); |
| 123 | |
| 124 | interactiveSection.appendChild(interactiveToolCalls); |
| 125 | interactiveSection.appendChild(controlsDiv); |
| 126 | |
| 127 | groupsSection.appendChild(groupsContainer); |
| 128 | |
| 129 | progressiveSection.appendChild(progressiveToolCalls); |
| 130 | progressiveSection.appendChild(progressiveControls); |
| 131 | |
| 132 | container.appendChild(basicSection); |
| 133 | container.appendChild(interactiveSection); |
| 134 | container.appendChild(groupsSection); |
| 135 | container.appendChild(progressiveSection); |
| 136 | }, |
| 137 | }; |
| 138 | |
| 139 | export default demo; |