| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 1 | import { css, html, LitElement } from "lit"; |
| 2 | import { customElement, property } from "lit/decorators.js"; |
| Philip Zeyliger | c2b6bdf | 2025-04-29 11:17:47 -0700 | [diff] [blame] | 3 | import { unsafeHTML } from "lit/directives/unsafe-html.js"; |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 4 | |
| 5 | @customElement("sketch-call-status") |
| 6 | export class SketchCallStatus extends LitElement { |
| Philip Zeyliger | c2b6bdf | 2025-04-29 11:17:47 -0700 | [diff] [blame] | 7 | @property() |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 8 | llmCalls: number = 0; |
| 9 | |
| Philip Zeyliger | c2b6bdf | 2025-04-29 11:17:47 -0700 | [diff] [blame] | 10 | @property() |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 11 | toolCalls: string[] = []; |
| 12 | |
| Sean McCullough | d9d4581 | 2025-04-30 16:53:41 -0700 | [diff] [blame] | 13 | @property() |
| 14 | agentState: string | null = null; |
| 15 | |
| Philip Zeyliger | 7231839 | 2025-05-14 02:56:07 +0000 | [diff] [blame] | 16 | @property() |
| 17 | isIdle: boolean = false; |
| Autoformatter | 8c46362 | 2025-05-16 21:54:17 +0000 | [diff] [blame] | 18 | |
| Philip Zeyliger | 5e35702 | 2025-05-16 04:50:34 +0000 | [diff] [blame] | 19 | @property() |
| 20 | isDisconnected: boolean = false; |
| Philip Zeyliger | 7231839 | 2025-05-14 02:56:07 +0000 | [diff] [blame] | 21 | |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 22 | static styles = css` |
| Josh Bleecher Snyder | e81233f | 2025-04-30 04:05:41 +0000 | [diff] [blame] | 23 | @keyframes gentle-pulse { |
| 24 | 0% { |
| 25 | transform: scale(1); |
| 26 | opacity: 1; |
| 27 | } |
| 28 | 50% { |
| 29 | transform: scale(1.15); |
| 30 | opacity: 0.8; |
| 31 | } |
| 32 | 100% { |
| 33 | transform: scale(1); |
| 34 | opacity: 1; |
| 35 | } |
| 36 | } |
| 37 | |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 38 | .call-status-container { |
| 39 | display: flex; |
| Philip Zeyliger | bd7b625 | 2025-05-15 16:21:36 +0000 | [diff] [blame] | 40 | position: relative; |
| 41 | align-items: center; |
| 42 | padding: 0 10px; |
| 43 | } |
| 44 | |
| 45 | .indicators-container { |
| 46 | display: flex; |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 47 | align-items: center; |
| 48 | gap: 10px; |
| Philip Zeyliger | bd7b625 | 2025-05-15 16:21:36 +0000 | [diff] [blame] | 49 | position: relative; |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | .indicator { |
| 53 | display: flex; |
| Philip Zeyliger | c2b6bdf | 2025-04-29 11:17:47 -0700 | [diff] [blame] | 54 | justify-content: center; |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 55 | align-items: center; |
| Philip Zeyliger | c2b6bdf | 2025-04-29 11:17:47 -0700 | [diff] [blame] | 56 | width: 32px; |
| 57 | height: 32px; |
| 58 | border-radius: 4px; |
| 59 | transition: all 0.2s ease; |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 60 | position: relative; |
| 61 | } |
| 62 | |
| Philip Zeyliger | c2b6bdf | 2025-04-29 11:17:47 -0700 | [diff] [blame] | 63 | /* LLM indicator (lightbulb) */ |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 64 | .llm-indicator { |
| Philip Zeyliger | c2b6bdf | 2025-04-29 11:17:47 -0700 | [diff] [blame] | 65 | background-color: transparent; |
| Autoformatter | 570c3f8 | 2025-04-29 18:26:50 +0000 | [diff] [blame] | 66 | color: #9ca3af; /* Gray when inactive */ |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | .llm-indicator.active { |
| Autoformatter | 570c3f8 | 2025-04-29 18:26:50 +0000 | [diff] [blame] | 70 | background-color: #fef3c7; /* Light yellow */ |
| 71 | color: #f59e0b; /* Yellow/amber when active */ |
| Josh Bleecher Snyder | e81233f | 2025-04-30 04:05:41 +0000 | [diff] [blame] | 72 | animation: gentle-pulse 1.5s infinite ease-in-out; |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| Philip Zeyliger | c2b6bdf | 2025-04-29 11:17:47 -0700 | [diff] [blame] | 75 | /* Tool indicator (wrench) */ |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 76 | .tool-indicator { |
| Philip Zeyliger | c2b6bdf | 2025-04-29 11:17:47 -0700 | [diff] [blame] | 77 | background-color: transparent; |
| Autoformatter | 570c3f8 | 2025-04-29 18:26:50 +0000 | [diff] [blame] | 78 | color: #9ca3af; /* Gray when inactive */ |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | .tool-indicator.active { |
| Autoformatter | 570c3f8 | 2025-04-29 18:26:50 +0000 | [diff] [blame] | 82 | background-color: #dbeafe; /* Light blue */ |
| 83 | color: #3b82f6; /* Blue when active */ |
| Josh Bleecher Snyder | e81233f | 2025-04-30 04:05:41 +0000 | [diff] [blame] | 84 | animation: gentle-pulse 1.5s infinite ease-in-out; |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| Philip Zeyliger | c2b6bdf | 2025-04-29 11:17:47 -0700 | [diff] [blame] | 87 | svg { |
| 88 | width: 20px; |
| 89 | height: 20px; |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 90 | } |
| Philip Zeyliger | 7231839 | 2025-05-14 02:56:07 +0000 | [diff] [blame] | 91 | |
| 92 | .status-banner { |
| Philip Zeyliger | bd7b625 | 2025-05-15 16:21:36 +0000 | [diff] [blame] | 93 | position: absolute; |
| Philip Zeyliger | 7231839 | 2025-05-14 02:56:07 +0000 | [diff] [blame] | 94 | padding: 2px 5px; |
| 95 | border-radius: 3px; |
| 96 | font-size: 10px; |
| 97 | font-weight: bold; |
| 98 | text-align: center; |
| 99 | letter-spacing: 0.5px; |
| Philip Zeyliger | 5e35702 | 2025-05-16 04:50:34 +0000 | [diff] [blame] | 100 | width: 104px; /* Wider to accommodate DISCONNECTED text */ |
| Philip Zeyliger | bd7b625 | 2025-05-15 16:21:36 +0000 | [diff] [blame] | 101 | left: 50%; |
| 102 | transform: translateX(-50%); |
| 103 | top: 60%; /* Position a little below center */ |
| 104 | z-index: 10; /* Ensure it appears above the icons */ |
| Philip Zeyliger | 5e35702 | 2025-05-16 04:50:34 +0000 | [diff] [blame] | 105 | opacity: 0.9; |
| Philip Zeyliger | 7231839 | 2025-05-14 02:56:07 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | .status-working { |
| 109 | background-color: #ffeecc; |
| 110 | color: #e65100; |
| 111 | } |
| 112 | |
| 113 | .status-idle { |
| 114 | background-color: #e6f4ea; |
| 115 | color: #0d652d; |
| 116 | } |
| Autoformatter | 8c46362 | 2025-05-16 21:54:17 +0000 | [diff] [blame] | 117 | |
| Philip Zeyliger | 5e35702 | 2025-05-16 04:50:34 +0000 | [diff] [blame] | 118 | .status-disconnected { |
| 119 | background-color: #ffebee; /* Light red */ |
| 120 | color: #d32f2f; /* Red */ |
| 121 | font-weight: bold; |
| 122 | } |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 123 | `; |
| 124 | |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 125 | render() { |
| Philip Zeyliger | c2b6bdf | 2025-04-29 11:17:47 -0700 | [diff] [blame] | 126 | const lightbulbSVG = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> |
| 127 | <path d="M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5"></path> |
| 128 | <path d="M9 18h6"></path> |
| 129 | <path d="M10 22h4"></path> |
| 130 | </svg>`; |
| 131 | |
| 132 | const wrenchSVG = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> |
| 133 | <path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"></path> |
| 134 | </svg>`; |
| 135 | |
| Sean McCullough | d9d4581 | 2025-04-30 16:53:41 -0700 | [diff] [blame] | 136 | const agentState = `${this.agentState ? " (" + this.agentState + ")" : ""}`; |
| 137 | |
| Philip Zeyliger | 5e35702 | 2025-05-16 04:50:34 +0000 | [diff] [blame] | 138 | // Determine state - disconnected takes precedence, then working vs idle |
| 139 | let statusClass = "status-idle"; |
| 140 | let statusText = "IDLE"; |
| Autoformatter | 8c46362 | 2025-05-16 21:54:17 +0000 | [diff] [blame] | 141 | |
| Philip Zeyliger | 5e35702 | 2025-05-16 04:50:34 +0000 | [diff] [blame] | 142 | if (this.isDisconnected) { |
| 143 | statusClass = "status-disconnected"; |
| 144 | statusText = "DISCONNECTED"; |
| 145 | } else if (!this.isIdle) { |
| 146 | statusClass = "status-working"; |
| 147 | statusText = "WORKING"; |
| 148 | } |
| Philip Zeyliger | 7231839 | 2025-05-14 02:56:07 +0000 | [diff] [blame] | 149 | |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 150 | return html` |
| 151 | <div class="call-status-container"> |
| Philip Zeyliger | bd7b625 | 2025-05-15 16:21:36 +0000 | [diff] [blame] | 152 | <div class="indicators-container"> |
| 153 | <div |
| 154 | class="indicator llm-indicator ${this.llmCalls > 0 ? "active" : ""}" |
| 155 | title="${this.llmCalls > 0 |
| 156 | ? `${this.llmCalls} LLM ${this.llmCalls === 1 ? "call" : "calls"} in progress` |
| 157 | : "No LLM calls in progress"}${agentState}" |
| 158 | > |
| 159 | ${unsafeHTML(lightbulbSVG)} |
| 160 | </div> |
| 161 | <div |
| 162 | class="indicator tool-indicator ${this.toolCalls.length > 0 |
| 163 | ? "active" |
| 164 | : ""}" |
| 165 | title="${this.toolCalls.length > 0 |
| 166 | ? `${this.toolCalls.length} tool ${this.toolCalls.length === 1 ? "call" : "calls"} in progress: ${this.toolCalls.join(", ")}` |
| 167 | : "No tool calls in progress"}${agentState}" |
| 168 | > |
| 169 | ${unsafeHTML(wrenchSVG)} |
| 170 | </div> |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 171 | </div> |
| Autoformatter | 8c46362 | 2025-05-16 21:54:17 +0000 | [diff] [blame] | 172 | <div class="status-banner ${statusClass}">${statusText}</div> |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 173 | </div> |
| 174 | `; |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | declare global { |
| 179 | interface HTMLElementTagNameMap { |
| 180 | "sketch-call-status": SketchCallStatus; |
| 181 | } |
| 182 | } |