blob: 9461d6dd41a1902cfc24b9c5cb9012ac220a35c3 [file] [log] [blame]
Sean McCullough86b56862025-04-18 13:04:03 -07001import { css, html, LitElement } from "lit";
Sean McCullough86b56862025-04-18 13:04:03 -07002import { customElement, property } from "lit/decorators.js";
Sean McCulloughd9f13372025-04-21 15:08:49 -07003import { ToolCall } from "../types";
Sean McCulloughec3ad1a2025-04-18 13:55:16 -07004import "./sketch-tool-card";
Sean McCullough86b56862025-04-18 13:04:03 -07005
6@customElement("sketch-tool-calls")
7export class SketchToolCalls extends LitElement {
8 @property()
9 toolCalls: ToolCall[] = [];
10
Sean McCullough86b56862025-04-18 13:04:03 -070011 static styles = css`
12 /* Tool calls container styles */
13 .tool-calls-container {
Sean McCulloughec3ad1a2025-04-18 13:55:16 -070014 /* Container for all tool calls */
Sean McCullough86b56862025-04-18 13:04:03 -070015 }
16
Sean McCulloughec3ad1a2025-04-18 13:55:16 -070017 /* Header for tool calls section */
Sean McCullough86b56862025-04-18 13:04:03 -070018 .tool-calls-header {
19 /* Empty header - just small spacing */
20 }
21
Sean McCulloughec3ad1a2025-04-18 13:55:16 -070022 /* Card container */
Sean McCullough86b56862025-04-18 13:04:03 -070023 .tool-call-card {
24 display: flex;
25 flex-direction: column;
26 background-color: white;
27 overflow: hidden;
28 cursor: pointer;
29 }
30
Sean McCulloughec3ad1a2025-04-18 13:55:16 -070031 /* Status indicators for tool calls */
Sean McCullough86b56862025-04-18 13:04:03 -070032 .tool-call-status {
33 margin-right: 4px;
34 text-align: center;
35 }
36
37 .tool-call-status.spinner {
38 animation: spin 1s infinite linear;
39 display: inline-block;
40 width: 1em;
41 }
42
Sean McCullough86b56862025-04-18 13:04:03 -070043 @keyframes spin {
44 0% {
45 transform: rotate(0deg);
46 }
47 100% {
48 transform: rotate(360deg);
49 }
50 }
Sean McCullough86b56862025-04-18 13:04:03 -070051 `;
52
53 constructor() {
54 super();
55 }
56
Sean McCullough86b56862025-04-18 13:04:03 -070057 connectedCallback() {
58 super.connectedCallback();
59 }
60
Sean McCullough86b56862025-04-18 13:04:03 -070061 disconnectedCallback() {
62 super.disconnectedCallback();
63 }
64
Sean McCulloughec3ad1a2025-04-18 13:55:16 -070065 cardForToolCall(toolCall: ToolCall, open: boolean) {
Sean McCullough86b56862025-04-18 13:04:03 -070066 switch (toolCall.name) {
Sean McCullough86b56862025-04-18 13:04:03 -070067 case "bash":
Sean McCulloughec3ad1a2025-04-18 13:55:16 -070068 return html`<sketch-tool-card-bash
69 .open=${open}
70 .toolCall=${toolCall}
71 ></sketch-tool-card-bash>`;
Sean McCullough86b56862025-04-18 13:04:03 -070072 case "codereview":
Sean McCulloughec3ad1a2025-04-18 13:55:16 -070073 return html`<sketch-tool-card-codereview
74 .open=${open}
75 .toolCall=${toolCall}
76 ></sketch-tool-card-codereview>`;
Sean McCullough86b56862025-04-18 13:04:03 -070077 case "done":
Sean McCulloughec3ad1a2025-04-18 13:55:16 -070078 return html`<sketch-tool-card-done
79 .open=${open}
80 .toolCall=${toolCall}
81 ></sketch-tool-card-done>`;
82 case "patch":
83 return html`<sketch-tool-card-patch
84 .open=${open}
85 .toolCall=${toolCall}
86 ></sketch-tool-card-patch>`;
87 case "think":
88 return html`<sketch-tool-card-think
89 .open=${open}
90 .toolCall=${toolCall}
91 ></sketch-tool-card-think>`;
92 case "title":
93 return html`<sketch-tool-card-title
94 .open=${open}
95 .toolCall=${toolCall}
96 ></sketch-tool-card-title>`;
Sean McCullough86b56862025-04-18 13:04:03 -070097 }
Sean McCulloughec3ad1a2025-04-18 13:55:16 -070098 return html`<sketch-tool-card-generic
99 .open=${open}
100 .toolCall=${toolCall}
101 ></sketch-tool-card-generic>`;
Sean McCullough86b56862025-04-18 13:04:03 -0700102 }
Sean McCulloughec3ad1a2025-04-18 13:55:16 -0700103
Sean McCullough86b56862025-04-18 13:04:03 -0700104 render() {
Sean McCulloughec3ad1a2025-04-18 13:55:16 -0700105 return html`<div class="tool-calls-container">
Sean McCullough86b56862025-04-18 13:04:03 -0700106 <div class="tool-calls-header"></div>
107 <div class="tool-call-cards-container">
Sean McCulloughec3ad1a2025-04-18 13:55:16 -0700108 ${this.toolCalls?.map((toolCall, idx) => {
109 let lastCall = false;
110 if (idx == this.toolCalls?.length - 1) {
111 lastCall = true;
112 }
113 return html`<div
114 id="${toolCall.tool_call_id}"
115 class="tool-call-card ${toolCall.name}"
116 >
117 ${this.cardForToolCall(toolCall, lastCall)}
Sean McCullough86b56862025-04-18 13:04:03 -0700118 </div>`;
119 })}
120 </div>
121 </div>`;
122 }
123}
124
125declare global {
126 interface HTMLElementTagNameMap {
127 "sketch-tool-calls": SketchToolCalls;
128 }
129}