blob: 2b4c426de2f001bc3404b43c29f04ed8a13958ab [file] [log] [blame]
Sean McCullough86b56862025-04-18 13:04:03 -07001import { css, html, LitElement } from "lit";
Sean McCullough86b56862025-04-18 13:04:03 -07002import { repeat } from "lit/directives/repeat.js";
3import { customElement, property } from "lit/decorators.js";
4import { State, ToolCall } from "../types";
5import { marked, MarkedOptions } from "marked";
Sean McCulloughec3ad1a2025-04-18 13:55:16 -07006import "./sketch-tool-card";
Sean McCullough86b56862025-04-18 13:04:03 -07007
8@customElement("sketch-tool-calls")
9export class SketchToolCalls extends LitElement {
10 @property()
11 toolCalls: ToolCall[] = [];
12
Sean McCullough86b56862025-04-18 13:04:03 -070013 static styles = css`
14 /* Tool calls container styles */
15 .tool-calls-container {
Sean McCulloughec3ad1a2025-04-18 13:55:16 -070016 /* Container for all tool calls */
Sean McCullough86b56862025-04-18 13:04:03 -070017 }
18
Sean McCulloughec3ad1a2025-04-18 13:55:16 -070019 /* Header for tool calls section */
Sean McCullough86b56862025-04-18 13:04:03 -070020 .tool-calls-header {
21 /* Empty header - just small spacing */
22 }
23
Sean McCulloughec3ad1a2025-04-18 13:55:16 -070024 /* Card container */
Sean McCullough86b56862025-04-18 13:04:03 -070025 .tool-call-card {
26 display: flex;
27 flex-direction: column;
28 background-color: white;
29 overflow: hidden;
30 cursor: pointer;
31 }
32
Sean McCulloughec3ad1a2025-04-18 13:55:16 -070033 /* Status indicators for tool calls */
Sean McCullough86b56862025-04-18 13:04:03 -070034 .tool-call-status {
35 margin-right: 4px;
36 text-align: center;
37 }
38
39 .tool-call-status.spinner {
40 animation: spin 1s infinite linear;
41 display: inline-block;
42 width: 1em;
43 }
44
Sean McCullough86b56862025-04-18 13:04:03 -070045 @keyframes spin {
46 0% {
47 transform: rotate(0deg);
48 }
49 100% {
50 transform: rotate(360deg);
51 }
52 }
Sean McCullough86b56862025-04-18 13:04:03 -070053 `;
54
55 constructor() {
56 super();
57 }
58
Sean McCullough86b56862025-04-18 13:04:03 -070059 connectedCallback() {
60 super.connectedCallback();
61 }
62
Sean McCullough86b56862025-04-18 13:04:03 -070063 disconnectedCallback() {
64 super.disconnectedCallback();
65 }
66
Sean McCulloughec3ad1a2025-04-18 13:55:16 -070067 cardForToolCall(toolCall: ToolCall, open: boolean) {
Sean McCullough86b56862025-04-18 13:04:03 -070068 switch (toolCall.name) {
Sean McCullough86b56862025-04-18 13:04:03 -070069 case "bash":
Sean McCulloughec3ad1a2025-04-18 13:55:16 -070070 return html`<sketch-tool-card-bash
71 .open=${open}
72 .toolCall=${toolCall}
73 ></sketch-tool-card-bash>`;
Sean McCullough86b56862025-04-18 13:04:03 -070074 case "codereview":
Sean McCulloughec3ad1a2025-04-18 13:55:16 -070075 return html`<sketch-tool-card-codereview
76 .open=${open}
77 .toolCall=${toolCall}
78 ></sketch-tool-card-codereview>`;
Sean McCullough86b56862025-04-18 13:04:03 -070079 case "done":
Sean McCulloughec3ad1a2025-04-18 13:55:16 -070080 return html`<sketch-tool-card-done
81 .open=${open}
82 .toolCall=${toolCall}
83 ></sketch-tool-card-done>`;
84 case "patch":
85 return html`<sketch-tool-card-patch
86 .open=${open}
87 .toolCall=${toolCall}
88 ></sketch-tool-card-patch>`;
89 case "think":
90 return html`<sketch-tool-card-think
91 .open=${open}
92 .toolCall=${toolCall}
93 ></sketch-tool-card-think>`;
94 case "title":
95 return html`<sketch-tool-card-title
96 .open=${open}
97 .toolCall=${toolCall}
98 ></sketch-tool-card-title>`;
Sean McCullough86b56862025-04-18 13:04:03 -070099 }
Sean McCulloughec3ad1a2025-04-18 13:55:16 -0700100 return html`<sketch-tool-card-generic
101 .open=${open}
102 .toolCall=${toolCall}
103 ></sketch-tool-card-generic>`;
Sean McCullough86b56862025-04-18 13:04:03 -0700104 }
Sean McCulloughec3ad1a2025-04-18 13:55:16 -0700105
Sean McCullough86b56862025-04-18 13:04:03 -0700106 render() {
Sean McCulloughec3ad1a2025-04-18 13:55:16 -0700107 return html`<div class="tool-calls-container">
Sean McCullough86b56862025-04-18 13:04:03 -0700108 <div class="tool-calls-header"></div>
109 <div class="tool-call-cards-container">
Sean McCulloughec3ad1a2025-04-18 13:55:16 -0700110 ${this.toolCalls?.map((toolCall, idx) => {
111 let lastCall = false;
112 if (idx == this.toolCalls?.length - 1) {
113 lastCall = true;
114 }
115 return html`<div
116 id="${toolCall.tool_call_id}"
117 class="tool-call-card ${toolCall.name}"
118 >
119 ${this.cardForToolCall(toolCall, lastCall)}
Sean McCullough86b56862025-04-18 13:04:03 -0700120 </div>`;
121 })}
122 </div>
123 </div>`;
124 }
125}
126
127declare global {
128 interface HTMLElementTagNameMap {
129 "sketch-tool-calls": SketchToolCalls;
130 }
131}