blob: 80eda2684aa5eb46c90d2ffe4480eed303507ac7 [file] [log] [blame]
philip.zeyliger26bc6592025-06-30 20:15:30 -07001/* eslint-disable @typescript-eslint/no-explicit-any */
Sean McCullough618bfb22025-06-25 20:52:30 +00002/**
3 * Demo module for sketch-tool-calls component
4 */
5
6import { DemoModule } from "./demo-framework/types";
7import {
8 demoUtils,
9 sampleToolCalls,
10 multipleToolCallGroups,
11 longBashCommand,
12} from "./demo-fixtures/index";
13
14const demo: DemoModule = {
15 title: "Tool Calls Demo",
16 description: "Interactive tool call display with various tool types",
17 imports: ["../sketch-tool-calls"],
18
19 setup: async (container: HTMLElement) => {
20 // Create demo sections
21 const basicSection = demoUtils.createDemoSection(
22 "Basic Tool Calls",
23 "Various types of tool calls with results",
24 );
25
26 const interactiveSection = demoUtils.createDemoSection(
27 "Interactive Examples",
28 "Tool calls that can be modified and updated",
29 );
30
31 const groupsSection = demoUtils.createDemoSection(
32 "Tool Call Groups",
33 "Multiple tool calls grouped together",
34 );
35
36 // Basic tool calls component
37 const basicToolCalls = document.createElement("sketch-tool-calls") as any;
38 basicToolCalls.toolCalls = sampleToolCalls.slice(0, 3);
39
40 // Interactive tool calls component
41 const interactiveToolCalls = document.createElement(
42 "sketch-tool-calls",
43 ) as any;
44 interactiveToolCalls.toolCalls = [sampleToolCalls[0]];
45
46 // Control buttons for interaction
47 const controlsDiv = document.createElement("div");
48 controlsDiv.style.cssText = "margin-top: 15px;";
49
50 const addBashButton = demoUtils.createButton("Add Bash Command", () => {
51 const currentCalls = interactiveToolCalls.toolCalls || [];
52 interactiveToolCalls.toolCalls = [...currentCalls, sampleToolCalls[2]];
53 });
54
55 const addLongCommandButton = demoUtils.createButton(
56 "Add Long Command",
57 () => {
58 const currentCalls = interactiveToolCalls.toolCalls || [];
59 interactiveToolCalls.toolCalls = [...currentCalls, longBashCommand];
60 },
61 );
62
63 const clearButton = demoUtils.createButton("Clear Tool Calls", () => {
64 interactiveToolCalls.toolCalls = [];
65 });
66
67 const resetButton = demoUtils.createButton("Reset to Default", () => {
68 interactiveToolCalls.toolCalls = [sampleToolCalls[0]];
69 });
70
71 controlsDiv.appendChild(addBashButton);
72 controlsDiv.appendChild(addLongCommandButton);
73 controlsDiv.appendChild(clearButton);
74 controlsDiv.appendChild(resetButton);
75
76 // Tool call groups
77 const groupsContainer = document.createElement("div");
78 multipleToolCallGroups.forEach((group, index) => {
79 const groupHeader = document.createElement("h4");
80 groupHeader.textContent = `Group ${index + 1}`;
81 groupHeader.style.cssText = "margin: 20px 0 10px 0; color: #24292f;";
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
139export default demo;