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