| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1 | import { css, html, LitElement } from "lit"; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 2 | import { customElement, property } from "lit/decorators.js"; |
| Sean McCullough | d9f1337 | 2025-04-21 15:08:49 -0700 | [diff] [blame^] | 3 | import { ToolCall } from "../types"; |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 4 | import "./sketch-tool-card"; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 5 | |
| 6 | @customElement("sketch-tool-calls") |
| 7 | export class SketchToolCalls extends LitElement { |
| 8 | @property() |
| 9 | toolCalls: ToolCall[] = []; |
| 10 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 11 | static styles = css` |
| 12 | /* Tool calls container styles */ |
| 13 | .tool-calls-container { |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 14 | /* Container for all tool calls */ |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 15 | } |
| 16 | |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 17 | /* Header for tool calls section */ |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 18 | .tool-calls-header { |
| 19 | /* Empty header - just small spacing */ |
| 20 | } |
| 21 | |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 22 | /* Card container */ |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 23 | .tool-call-card { |
| 24 | display: flex; |
| 25 | flex-direction: column; |
| 26 | background-color: white; |
| 27 | overflow: hidden; |
| 28 | cursor: pointer; |
| 29 | } |
| 30 | |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 31 | /* Status indicators for tool calls */ |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 32 | .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 McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 43 | @keyframes spin { |
| 44 | 0% { |
| 45 | transform: rotate(0deg); |
| 46 | } |
| 47 | 100% { |
| 48 | transform: rotate(360deg); |
| 49 | } |
| 50 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 51 | `; |
| 52 | |
| 53 | constructor() { |
| 54 | super(); |
| 55 | } |
| 56 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 57 | connectedCallback() { |
| 58 | super.connectedCallback(); |
| 59 | } |
| 60 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 61 | disconnectedCallback() { |
| 62 | super.disconnectedCallback(); |
| 63 | } |
| 64 | |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 65 | cardForToolCall(toolCall: ToolCall, open: boolean) { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 66 | switch (toolCall.name) { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 67 | case "bash": |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 68 | return html`<sketch-tool-card-bash |
| 69 | .open=${open} |
| 70 | .toolCall=${toolCall} |
| 71 | ></sketch-tool-card-bash>`; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 72 | case "codereview": |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 73 | return html`<sketch-tool-card-codereview |
| 74 | .open=${open} |
| 75 | .toolCall=${toolCall} |
| 76 | ></sketch-tool-card-codereview>`; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 77 | case "done": |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 78 | 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 McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 97 | } |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 98 | return html`<sketch-tool-card-generic |
| 99 | .open=${open} |
| 100 | .toolCall=${toolCall} |
| 101 | ></sketch-tool-card-generic>`; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 102 | } |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 103 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 104 | render() { |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 105 | return html`<div class="tool-calls-container"> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 106 | <div class="tool-calls-header"></div> |
| 107 | <div class="tool-call-cards-container"> |
| Sean McCullough | ec3ad1a | 2025-04-18 13:55:16 -0700 | [diff] [blame] | 108 | ${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 McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 118 | </div>`; |
| 119 | })} |
| 120 | </div> |
| 121 | </div>`; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | declare global { |
| 126 | interface HTMLElementTagNameMap { |
| 127 | "sketch-tool-calls": SketchToolCalls; |
| 128 | } |
| 129 | } |