| banksean | 659b983 | 2025-06-27 00:50:41 +0000 | [diff] [blame] | 1 | import { html } from "lit"; |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 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"; |
| banksean | 659b983 | 2025-06-27 00:50:41 +0000 | [diff] [blame] | 4 | import { SketchTailwindElement } from "./sketch-tailwind-element.js"; |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 5 | |
| 6 | @customElement("sketch-call-status") |
| banksean | 659b983 | 2025-06-27 00:50:41 +0000 | [diff] [blame] | 7 | export class SketchCallStatus extends SketchTailwindElement { |
| Philip Zeyliger | c2b6bdf | 2025-04-29 11:17:47 -0700 | [diff] [blame] | 8 | @property() |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 9 | llmCalls: number = 0; |
| 10 | |
| Philip Zeyliger | c2b6bdf | 2025-04-29 11:17:47 -0700 | [diff] [blame] | 11 | @property() |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 12 | toolCalls: string[] = []; |
| 13 | |
| Sean McCullough | d9d4581 | 2025-04-30 16:53:41 -0700 | [diff] [blame] | 14 | @property() |
| 15 | agentState: string | null = null; |
| 16 | |
| Philip Zeyliger | 7231839 | 2025-05-14 02:56:07 +0000 | [diff] [blame] | 17 | @property() |
| 18 | isIdle: boolean = false; |
| Autoformatter | 8c46362 | 2025-05-16 21:54:17 +0000 | [diff] [blame] | 19 | |
| Philip Zeyliger | 5e35702 | 2025-05-16 04:50:34 +0000 | [diff] [blame] | 20 | @property() |
| 21 | isDisconnected: boolean = false; |
| Philip Zeyliger | 7231839 | 2025-05-14 02:56:07 +0000 | [diff] [blame] | 22 | |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 23 | render() { |
| Philip Zeyliger | c2b6bdf | 2025-04-29 11:17:47 -0700 | [diff] [blame] | 24 | 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"> |
| 25 | <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> |
| 26 | <path d="M9 18h6"></path> |
| 27 | <path d="M10 22h4"></path> |
| 28 | </svg>`; |
| 29 | |
| 30 | 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"> |
| 31 | <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> |
| 32 | </svg>`; |
| 33 | |
| Sean McCullough | d9d4581 | 2025-04-30 16:53:41 -0700 | [diff] [blame] | 34 | const agentState = `${this.agentState ? " (" + this.agentState + ")" : ""}`; |
| 35 | |
| Philip Zeyliger | 5e35702 | 2025-05-16 04:50:34 +0000 | [diff] [blame] | 36 | // Determine state - disconnected takes precedence, then working vs idle |
| 37 | let statusClass = "status-idle"; |
| 38 | let statusText = "IDLE"; |
| Autoformatter | 8c46362 | 2025-05-16 21:54:17 +0000 | [diff] [blame] | 39 | |
| Philip Zeyliger | 5e35702 | 2025-05-16 04:50:34 +0000 | [diff] [blame] | 40 | if (this.isDisconnected) { |
| 41 | statusClass = "status-disconnected"; |
| 42 | statusText = "DISCONNECTED"; |
| 43 | } else if (!this.isIdle) { |
| 44 | statusClass = "status-working"; |
| 45 | statusText = "WORKING"; |
| 46 | } |
| Philip Zeyliger | 7231839 | 2025-05-14 02:56:07 +0000 | [diff] [blame] | 47 | |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 48 | return html` |
| banksean | 659b983 | 2025-06-27 00:50:41 +0000 | [diff] [blame] | 49 | <style> |
| 50 | @keyframes gentle-pulse { |
| 51 | 0% { |
| 52 | transform: scale(1); |
| 53 | opacity: 1; |
| 54 | } |
| 55 | 50% { |
| 56 | transform: scale(1.15); |
| 57 | opacity: 0.8; |
| 58 | } |
| 59 | 100% { |
| 60 | transform: scale(1); |
| 61 | opacity: 1; |
| 62 | } |
| 63 | } |
| 64 | .animate-gentle-pulse { |
| 65 | animation: gentle-pulse 1.5s infinite ease-in-out; |
| 66 | } |
| 67 | </style> |
| 68 | <div class="flex relative items-center px-2.5"> |
| 69 | <div class="flex items-center gap-2.5 relative"> |
| Philip Zeyliger | bd7b625 | 2025-05-15 16:21:36 +0000 | [diff] [blame] | 70 | <div |
| banksean | 659b983 | 2025-06-27 00:50:41 +0000 | [diff] [blame] | 71 | class="llm-indicator flex justify-center items-center w-8 h-8 rounded transition-all duration-200 relative ${this |
| 72 | .llmCalls > 0 |
| banksean | 3eaa433 | 2025-07-19 02:19:06 +0000 | [diff] [blame] | 73 | ? "bg-yellow-100 dark:bg-yellow-900 text-amber-500 dark:text-amber-400 animate-gentle-pulse active" |
| 74 | : "bg-transparent text-gray-400 dark:text-gray-500"}" |
| Philip Zeyliger | bd7b625 | 2025-05-15 16:21:36 +0000 | [diff] [blame] | 75 | title="${this.llmCalls > 0 |
| 76 | ? `${this.llmCalls} LLM ${this.llmCalls === 1 ? "call" : "calls"} in progress` |
| 77 | : "No LLM calls in progress"}${agentState}" |
| 78 | > |
| banksean | 659b983 | 2025-06-27 00:50:41 +0000 | [diff] [blame] | 79 | <div class="w-5 h-5">${unsafeHTML(lightbulbSVG)}</div> |
| Philip Zeyliger | bd7b625 | 2025-05-15 16:21:36 +0000 | [diff] [blame] | 80 | </div> |
| 81 | <div |
| banksean | 659b983 | 2025-06-27 00:50:41 +0000 | [diff] [blame] | 82 | class="tool-indicator flex justify-center items-center w-8 h-8 rounded transition-all duration-200 relative ${this |
| 83 | .toolCalls.length > 0 |
| banksean | 3eaa433 | 2025-07-19 02:19:06 +0000 | [diff] [blame] | 84 | ? "bg-blue-100 dark:bg-blue-900 text-blue-500 dark:text-blue-400 animate-gentle-pulse active" |
| 85 | : "bg-transparent text-gray-400 dark:text-gray-500"}" |
| Philip Zeyliger | bd7b625 | 2025-05-15 16:21:36 +0000 | [diff] [blame] | 86 | title="${this.toolCalls.length > 0 |
| 87 | ? `${this.toolCalls.length} tool ${this.toolCalls.length === 1 ? "call" : "calls"} in progress: ${this.toolCalls.join(", ")}` |
| 88 | : "No tool calls in progress"}${agentState}" |
| 89 | > |
| banksean | 659b983 | 2025-06-27 00:50:41 +0000 | [diff] [blame] | 90 | <div class="w-5 h-5">${unsafeHTML(wrenchSVG)}</div> |
| Philip Zeyliger | bd7b625 | 2025-05-15 16:21:36 +0000 | [diff] [blame] | 91 | </div> |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 92 | </div> |
| banksean | 659b983 | 2025-06-27 00:50:41 +0000 | [diff] [blame] | 93 | <div |
| 94 | class="status-banner absolute py-0.5 px-1.5 rounded text-xs font-bold text-center tracking-wider w-26 left-1/2 transform -translate-x-1/2 top-3/5 z-10 opacity-90 ${statusClass} ${this |
| 95 | .isDisconnected |
| banksean | 3eaa433 | 2025-07-19 02:19:06 +0000 | [diff] [blame] | 96 | ? "bg-red-50 dark:bg-red-900 text-red-600 dark:text-red-400" |
| banksean | 659b983 | 2025-06-27 00:50:41 +0000 | [diff] [blame] | 97 | : !this.isIdle |
| banksean | 3eaa433 | 2025-07-19 02:19:06 +0000 | [diff] [blame] | 98 | ? "bg-orange-50 dark:bg-orange-900 text-orange-600 dark:text-orange-400" |
| 99 | : "bg-green-50 dark:bg-green-900 text-green-700 dark:text-green-400"}" |
| Josh Bleecher Snyder | 7208bb4 | 2025-07-18 00:44:11 +0000 | [diff] [blame] | 100 | title="${this.isDisconnected |
| 101 | ? "Connection lost or container shut down" |
| 102 | : !this.isIdle |
| 103 | ? "Agent is processing" |
| 104 | : "Agent is idle and ready for input"}" |
| banksean | 659b983 | 2025-06-27 00:50:41 +0000 | [diff] [blame] | 105 | > |
| 106 | ${statusText} |
| 107 | </div> |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 108 | </div> |
| 109 | `; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | declare global { |
| 114 | interface HTMLElementTagNameMap { |
| 115 | "sketch-call-status": SketchCallStatus; |
| 116 | } |
| 117 | } |