| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1 | import { css, html, LitElement } from "lit"; |
| 2 | import { customElement, property, state } from "lit/decorators.js"; |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 3 | import { ConnectionStatus, DataManager } from "../data"; |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 4 | import { AgentMessage, GitLogEntry, State } from "../types"; |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 5 | import { aggregateAgentMessages } from "./aggregateAgentMessages"; |
| Philip Zeyliger | 2d4c48f | 2025-05-02 23:35:03 +0000 | [diff] [blame] | 6 | |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 7 | import "./sketch-chat-input"; |
| 8 | import "./sketch-container-status"; |
| Philip Zeyliger | 00bcaef | 2025-05-30 04:21:15 +0000 | [diff] [blame] | 9 | |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 10 | import "./sketch-diff2-view"; |
| 11 | import { SketchDiff2View } from "./sketch-diff2-view"; |
| 12 | import { DefaultGitDataService } from "./git-data-service"; |
| 13 | import "./sketch-monaco-view"; |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 14 | import "./sketch-network-status"; |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 15 | import "./sketch-call-status"; |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 16 | import "./sketch-terminal"; |
| 17 | import "./sketch-timeline"; |
| 18 | import "./sketch-view-mode-select"; |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 19 | import "./sketch-todo-panel"; |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 20 | |
| 21 | import { createRef, ref } from "lit/directives/ref.js"; |
| Sean McCullough | 485afc6 | 2025-04-28 14:28:39 -0700 | [diff] [blame] | 22 | import { SketchChatInput } from "./sketch-chat-input"; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 23 | |
| Philip Zeyliger | 00bcaef | 2025-05-30 04:21:15 +0000 | [diff] [blame] | 24 | type ViewMode = "chat" | "diff2" | "terminal"; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 25 | |
| 26 | @customElement("sketch-app-shell") |
| 27 | export class SketchAppShell extends LitElement { |
| Philip Zeyliger | 2d4c48f | 2025-05-02 23:35:03 +0000 | [diff] [blame] | 28 | // Current view mode (chat, diff, terminal) |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 29 | @state() |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 30 | viewMode: ViewMode = "chat"; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 31 | |
| 32 | // Current commit hash for diff view |
| 33 | @state() |
| 34 | currentCommitHash: string = ""; |
| 35 | |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 36 | // Last commit information |
| 37 | @state() |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 38 | |
| 39 | // Reference to the container status element |
| 40 | containerStatusElement: any = null; |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 41 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 42 | // See https://lit.dev/docs/components/styles/ for how lit-element handles CSS. |
| 43 | // Note that these styles only apply to the scope of this web component's |
| 44 | // shadow DOM node, so they won't leak out or collide with CSS declared in |
| 45 | // other components or the containing web page (...unless you want it to do that). |
| 46 | static styles = css` |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 47 | .copied-indicator { |
| 48 | position: absolute; |
| 49 | top: -20px; |
| 50 | left: 50%; |
| 51 | transform: translateX(-50%); |
| 52 | background: rgba(40, 167, 69, 0.9); |
| 53 | color: white; |
| 54 | padding: 2px 6px; |
| 55 | border-radius: 3px; |
| 56 | font-size: 10px; |
| 57 | font-family: system-ui, sans-serif; |
| 58 | animation: fadeInOut 2s ease; |
| 59 | pointer-events: none; |
| 60 | } |
| Autoformatter | cf57096 | 2025-04-30 17:27:39 +0000 | [diff] [blame] | 61 | |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 62 | @keyframes fadeInOut { |
| Autoformatter | cf57096 | 2025-04-30 17:27:39 +0000 | [diff] [blame] | 63 | 0% { |
| 64 | opacity: 0; |
| 65 | } |
| 66 | 20% { |
| 67 | opacity: 1; |
| 68 | } |
| 69 | 80% { |
| 70 | opacity: 1; |
| 71 | } |
| 72 | 100% { |
| 73 | opacity: 0; |
| 74 | } |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 75 | } |
| Autoformatter | cf57096 | 2025-04-30 17:27:39 +0000 | [diff] [blame] | 76 | |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 77 | .commit-branch-indicator { |
| 78 | color: #28a745; |
| 79 | } |
| Autoformatter | cf57096 | 2025-04-30 17:27:39 +0000 | [diff] [blame] | 80 | |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 81 | .commit-hash-indicator { |
| 82 | color: #0366d6; |
| 83 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 84 | :host { |
| 85 | display: block; |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 86 | font-family: |
| 87 | system-ui, |
| 88 | -apple-system, |
| 89 | BlinkMacSystemFont, |
| 90 | "Segoe UI", |
| 91 | Roboto, |
| 92 | sans-serif; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 93 | color: #333; |
| 94 | line-height: 1.4; |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 95 | height: 100vh; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 96 | width: 100%; |
| 97 | position: relative; |
| 98 | overflow-x: hidden; |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 99 | display: flex; |
| 100 | flex-direction: column; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /* Top banner with combined elements */ |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 104 | #top-banner { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 105 | display: flex; |
| Philip Zeyliger | e66db3e | 2025-04-27 15:40:39 +0000 | [diff] [blame] | 106 | align-self: stretch; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 107 | justify-content: space-between; |
| 108 | align-items: center; |
| Philip Zeyliger | e66db3e | 2025-04-27 15:40:39 +0000 | [diff] [blame] | 109 | padding: 0 20px; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 110 | margin-bottom: 0; |
| 111 | border-bottom: 1px solid #eee; |
| Philip Zeyliger | e66db3e | 2025-04-27 15:40:39 +0000 | [diff] [blame] | 112 | gap: 20px; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 113 | background: white; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 114 | box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); |
| Philip Zeyliger | e66db3e | 2025-04-27 15:40:39 +0000 | [diff] [blame] | 115 | width: 100%; |
| 116 | height: 48px; |
| 117 | padding-right: 30px; /* Extra padding on the right to prevent elements from hitting the edge */ |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 120 | /* View mode container styles - mirroring timeline.css structure */ |
| 121 | #view-container { |
| 122 | align-self: stretch; |
| 123 | overflow-y: auto; |
| 124 | flex: 1; |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 125 | display: flex; |
| 126 | flex-direction: column; |
| 127 | min-height: 0; /* Critical for proper flex child behavior */ |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | #view-container-inner { |
| 131 | max-width: 1200px; |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 132 | width: calc(100% - 40px); |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 133 | margin: 0 auto; |
| 134 | position: relative; |
| 135 | padding-bottom: 10px; |
| 136 | padding-top: 10px; |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 137 | display: flex; |
| 138 | flex-direction: column; |
| 139 | height: 100%; /* Ensure it takes full height of parent */ |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 140 | } |
| 141 | |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 142 | /* Adjust view container when todo panel is visible in chat mode */ |
| 143 | #view-container-inner.with-todo-panel { |
| 144 | max-width: none; |
| 145 | width: 100%; |
| 146 | margin: 0; |
| 147 | padding-left: 20px; |
| 148 | padding-right: 20px; |
| 149 | } |
| 150 | |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 151 | #chat-input { |
| 152 | align-self: flex-end; |
| 153 | width: 100%; |
| 154 | box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1); |
| 155 | } |
| 156 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 157 | .banner-title { |
| 158 | font-size: 18px; |
| 159 | font-weight: 600; |
| 160 | margin: 0; |
| 161 | min-width: 6em; |
| 162 | white-space: nowrap; |
| 163 | overflow: hidden; |
| 164 | text-overflow: ellipsis; |
| 165 | } |
| 166 | |
| Philip Zeyliger | 0113be5 | 2025-06-07 23:53:41 +0000 | [diff] [blame] | 167 | .banner-title a { |
| 168 | color: inherit; |
| 169 | text-decoration: none; |
| 170 | transition: opacity 0.2s ease; |
| 171 | display: flex; |
| 172 | align-items: center; |
| 173 | gap: 8px; |
| 174 | } |
| 175 | |
| 176 | .banner-title a:hover { |
| 177 | opacity: 0.8; |
| 178 | text-decoration: underline; |
| 179 | } |
| 180 | |
| 181 | .banner-title img { |
| 182 | width: 20px; |
| 183 | height: 20px; |
| 184 | border-radius: 3px; |
| 185 | } |
| 186 | |
| 187 | /* Mobile-specific styles for banner link */ |
| 188 | @media (max-width: 768px) { |
| 189 | .title-container { |
| 190 | max-width: 50%; /* Allow more space on mobile */ |
| 191 | } |
| 192 | |
| 193 | .banner-title { |
| 194 | font-size: 16px; /* Slightly smaller on mobile */ |
| 195 | } |
| 196 | |
| 197 | .banner-title img { |
| 198 | width: 18px; |
| 199 | height: 18px; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | @media (max-width: 480px) { |
| 204 | .title-container { |
| 205 | max-width: 60%; /* Even more space on very small screens */ |
| 206 | } |
| 207 | |
| 208 | .banner-title { |
| 209 | font-size: 14px; |
| 210 | } |
| 211 | |
| 212 | .banner-title img { |
| 213 | width: 16px; |
| 214 | height: 16px; |
| 215 | } |
| 216 | } |
| 217 | |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 218 | .slug-title { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 219 | margin: 0; |
| 220 | padding: 0; |
| 221 | color: rgba(82, 82, 82, 0.85); |
| Josh Bleecher Snyder | eb5166a | 2025-04-30 17:04:20 +0000 | [diff] [blame] | 222 | font-size: 14px; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 223 | font-weight: normal; |
| 224 | font-style: italic; |
| 225 | white-space: nowrap; |
| 226 | overflow: hidden; |
| 227 | text-overflow: ellipsis; |
| 228 | } |
| 229 | |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 230 | /* Allow the container to expand to full width and height in diff mode */ |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 231 | #view-container-inner.diff2-active { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 232 | max-width: 100%; |
| Pokey Rule | 46fff97 | 2025-04-25 14:57:44 +0100 | [diff] [blame] | 233 | width: 100%; |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 234 | height: 100%; |
| 235 | padding: 0; /* Remove padding for more space */ |
| 236 | display: flex; |
| 237 | flex-direction: column; |
| 238 | flex: 1; |
| 239 | min-height: 0; /* Critical for flex behavior */ |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | /* Individual view styles */ |
| 243 | .chat-view, |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 244 | .diff2-view, |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 245 | .terminal-view { |
| 246 | display: none; /* Hidden by default */ |
| 247 | width: 100%; |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 248 | height: 100%; |
| 249 | } |
| Autoformatter | 8c46362 | 2025-05-16 21:54:17 +0000 | [diff] [blame] | 250 | |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 251 | /* Make chat view take full width available */ |
| 252 | .chat-view.view-active { |
| 253 | display: flex; |
| 254 | flex-direction: column; |
| 255 | width: 100%; |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 256 | height: 100%; |
| 257 | } |
| 258 | |
| 259 | /* Chat timeline container - takes full width, memory panel will be positioned separately */ |
| 260 | .chat-timeline-container { |
| 261 | flex: 1; |
| 262 | display: flex; |
| 263 | flex-direction: column; |
| 264 | width: 100%; |
| 265 | height: 100%; |
| 266 | margin-right: 0; /* Default - no memory panel */ |
| 267 | transition: margin-right 0.2s ease; /* Smooth transition */ |
| 268 | } |
| 269 | |
| 270 | /* Adjust chat timeline container when todo panel is visible */ |
| 271 | .chat-timeline-container.with-todo-panel { |
| 272 | margin-right: 400px; /* Make space for fixed todo panel */ |
| 273 | width: calc(100% - 400px); /* Explicitly set width to prevent overlap */ |
| 274 | } |
| 275 | |
| 276 | /* Todo panel container - fixed to right side */ |
| 277 | .todo-panel-container { |
| 278 | position: fixed; |
| 279 | top: 48px; /* Below top banner */ |
| 280 | right: 15px; /* Leave space for scroll bar */ |
| 281 | width: 400px; |
| 282 | bottom: var( |
| 283 | --chat-input-height, |
| 284 | 90px |
| 285 | ); /* Dynamic height based on chat input size */ |
| 286 | background-color: #fafafa; |
| 287 | border-left: 1px solid #e0e0e0; |
| 288 | z-index: 100; |
| 289 | display: none; /* Hidden by default */ |
| 290 | transition: bottom 0.2s ease; /* Smooth transition when height changes */ |
| 291 | /* Add fuzzy gradient at bottom to blend with text entry */ |
| 292 | background: linear-gradient( |
| 293 | to bottom, |
| 294 | #fafafa 0%, |
| 295 | #fafafa 90%, |
| 296 | rgba(250, 250, 250, 0.5) 95%, |
| 297 | rgba(250, 250, 250, 0.2) 100% |
| 298 | ); |
| 299 | } |
| 300 | |
| 301 | .todo-panel-container.visible { |
| 302 | display: block; |
| 303 | } |
| 304 | |
| 305 | /* Responsive adjustments for todo panel */ |
| 306 | @media (max-width: 1200px) { |
| 307 | .todo-panel-container { |
| 308 | width: 350px; |
| 309 | /* bottom is still controlled by --chat-input-height CSS variable */ |
| 310 | } |
| 311 | .chat-timeline-container.with-todo-panel { |
| 312 | margin-right: 350px; |
| 313 | width: calc(100% - 350px); |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | @media (max-width: 900px) { |
| 318 | .todo-panel-container { |
| 319 | width: 300px; |
| 320 | /* bottom is still controlled by --chat-input-height CSS variable */ |
| 321 | } |
| 322 | .chat-timeline-container.with-todo-panel { |
| 323 | margin-right: 300px; |
| 324 | width: calc(100% - 300px); |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | /* On very small screens, hide todo panel or make it overlay */ |
| 329 | @media (max-width: 768px) { |
| 330 | .todo-panel-container.visible { |
| 331 | display: none; /* Hide on mobile */ |
| 332 | } |
| 333 | .chat-timeline-container.with-todo-panel { |
| 334 | margin-right: 0; |
| 335 | width: 100%; |
| 336 | } |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 337 | } |
| Autoformatter | 8c46362 | 2025-05-16 21:54:17 +0000 | [diff] [blame] | 338 | |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 339 | /* Monaco diff2 view needs to take all available space */ |
| 340 | .diff2-view.view-active { |
| 341 | flex: 1; |
| 342 | overflow: hidden; |
| 343 | min-height: 0; /* Required for proper flex child behavior */ |
| 344 | display: flex; |
| 345 | flex-direction: column; |
| 346 | height: 100%; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | /* Active view styles - these will be applied via JavaScript */ |
| 350 | .view-active { |
| 351 | display: flex; |
| 352 | flex-direction: column; |
| 353 | } |
| 354 | |
| 355 | .title-container { |
| 356 | display: flex; |
| 357 | flex-direction: column; |
| 358 | white-space: nowrap; |
| 359 | overflow: hidden; |
| 360 | text-overflow: ellipsis; |
| Josh Bleecher Snyder | eb5166a | 2025-04-30 17:04:20 +0000 | [diff] [blame] | 361 | max-width: 30%; |
| Philip Zeyliger | e66db3e | 2025-04-27 15:40:39 +0000 | [diff] [blame] | 362 | padding: 6px 0; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | .refresh-control { |
| 366 | display: flex; |
| 367 | align-items: center; |
| 368 | margin-bottom: 0; |
| 369 | flex-wrap: nowrap; |
| 370 | white-space: nowrap; |
| 371 | flex-shrink: 0; |
| Philip Zeyliger | e66db3e | 2025-04-27 15:40:39 +0000 | [diff] [blame] | 372 | gap: 15px; |
| 373 | padding-left: 15px; |
| 374 | margin-right: 50px; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| Pokey Rule | 397871d | 2025-05-19 15:02:45 +0100 | [diff] [blame] | 377 | .stop-button, |
| 378 | .end-button { |
| Philip Zeyliger | 2c4db09 | 2025-04-28 16:57:50 -0700 | [diff] [blame] | 379 | background: #2196f3; |
| 380 | color: white; |
| 381 | border: none; |
| 382 | padding: 4px 10px; |
| 383 | border-radius: 4px; |
| 384 | cursor: pointer; |
| 385 | font-size: 12px; |
| 386 | margin-right: 5px; |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 387 | display: flex; |
| 388 | align-items: center; |
| 389 | gap: 6px; |
| Philip Zeyliger | 2c4db09 | 2025-04-28 16:57:50 -0700 | [diff] [blame] | 390 | } |
| 391 | |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 392 | .stop-button { |
| 393 | background: #dc3545; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 394 | color: white; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 397 | .stop-button:hover:not(:disabled) { |
| 398 | background-color: #c82333; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 399 | } |
| 400 | |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 401 | .stop-button:disabled { |
| 402 | background-color: #e9a8ad; |
| 403 | cursor: not-allowed; |
| 404 | opacity: 0.7; |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 405 | } |
| 406 | |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 407 | .stop-button:disabled:hover { |
| 408 | background-color: #e9a8ad; |
| 409 | } |
| 410 | |
| Pokey Rule | 397871d | 2025-05-19 15:02:45 +0100 | [diff] [blame] | 411 | .end-button { |
| 412 | background: #6c757d; |
| 413 | color: white; |
| 414 | } |
| 415 | |
| 416 | .end-button:hover:not(:disabled) { |
| 417 | background-color: #5a6268; |
| 418 | } |
| 419 | |
| 420 | .end-button:disabled { |
| 421 | background-color: #a9acaf; |
| 422 | cursor: not-allowed; |
| 423 | opacity: 0.7; |
| 424 | } |
| 425 | |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 426 | .button-icon { |
| 427 | width: 16px; |
| 428 | height: 16px; |
| 429 | } |
| 430 | |
| 431 | @media (max-width: 1400px) { |
| 432 | .button-text { |
| 433 | display: none; |
| 434 | } |
| 435 | |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 436 | .stop-button { |
| 437 | padding: 6px; |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | /* Removed poll-updates class */ |
| 442 | |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 443 | .notifications-toggle { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 444 | display: flex; |
| 445 | align-items: center; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 446 | font-size: 12px; |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 447 | margin-right: 10px; |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 448 | cursor: pointer; |
| 449 | } |
| 450 | |
| 451 | .bell-icon { |
| 452 | width: 20px; |
| 453 | height: 20px; |
| 454 | position: relative; |
| 455 | display: inline-flex; |
| 456 | align-items: center; |
| 457 | justify-content: center; |
| 458 | } |
| 459 | |
| 460 | .bell-disabled::before { |
| 461 | content: ""; |
| 462 | position: absolute; |
| 463 | width: 2px; |
| 464 | height: 24px; |
| 465 | background-color: #dc3545; |
| 466 | transform: rotate(45deg); |
| 467 | transform-origin: center center; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 468 | } |
| 469 | `; |
| 470 | |
| 471 | // Header bar: Network connection status details |
| 472 | @property() |
| 473 | connectionStatus: ConnectionStatus = "disconnected"; |
| Autoformatter | cf57096 | 2025-04-30 17:27:39 +0000 | [diff] [blame] | 474 | |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 475 | // Track if the last commit info has been copied |
| 476 | @state() |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 477 | // lastCommitCopied moved to sketch-container-status |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 478 | |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 479 | // Track notification preferences |
| 480 | @state() |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 481 | notificationsEnabled: boolean = false; |
| 482 | |
| 483 | // Track if the window is focused to control notifications |
| 484 | @state() |
| 485 | private _windowFocused: boolean = document.hasFocus(); |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 486 | |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 487 | // Track if the todo panel should be visible |
| 488 | @state() |
| 489 | private _todoPanelVisible: boolean = false; |
| 490 | |
| 491 | // ResizeObserver for tracking chat input height changes |
| 492 | private chatInputResizeObserver: ResizeObserver | null = null; |
| 493 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 494 | @property() |
| 495 | connectionErrorMessage: string = ""; |
| 496 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 497 | // Chat messages |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 498 | @property({ attribute: false }) |
| Sean McCullough | d9f1337 | 2025-04-21 15:08:49 -0700 | [diff] [blame] | 499 | messages: AgentMessage[] = []; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 500 | |
| 501 | @property() |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 502 | set slug(value: string) { |
| 503 | const oldValue = this._slug; |
| 504 | this._slug = value; |
| 505 | this.requestUpdate("slug", oldValue); |
| 506 | // Update document title when slug property changes |
| Philip Zeyliger | 9b999b0 | 2025-04-25 16:31:50 +0000 | [diff] [blame] | 507 | this.updateDocumentTitle(); |
| 508 | } |
| 509 | |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 510 | get slug(): string { |
| 511 | return this._slug; |
| Philip Zeyliger | 9b999b0 | 2025-04-25 16:31:50 +0000 | [diff] [blame] | 512 | } |
| 513 | |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 514 | private _slug: string = ""; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 515 | |
| 516 | private dataManager = new DataManager(); |
| 517 | |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 518 | @property({ attribute: false }) |
| Sean McCullough | d9f1337 | 2025-04-21 15:08:49 -0700 | [diff] [blame] | 519 | containerState: State = { |
| Philip Zeyliger | d03318d | 2025-05-08 13:09:12 -0700 | [diff] [blame] | 520 | state_version: 2, |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 521 | slug: "", |
| Sean McCullough | d9f1337 | 2025-04-21 15:08:49 -0700 | [diff] [blame] | 522 | os: "", |
| 523 | message_count: 0, |
| 524 | hostname: "", |
| 525 | working_dir: "", |
| 526 | initial_commit: "", |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 527 | outstanding_llm_calls: 0, |
| 528 | outstanding_tool_calls: [], |
| Philip Zeyliger | c72fff5 | 2025-04-29 20:17:54 +0000 | [diff] [blame] | 529 | session_id: "", |
| 530 | ssh_available: false, |
| Philip Zeyliger | 2c4db09 | 2025-04-28 16:57:50 -0700 | [diff] [blame] | 531 | ssh_error: "", |
| 532 | in_container: false, |
| 533 | first_message_index: 0, |
| Sean McCullough | d9f1337 | 2025-04-21 15:08:49 -0700 | [diff] [blame] | 534 | }; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 535 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 536 | // Mutation observer to detect when new messages are added |
| 537 | private mutationObserver: MutationObserver | null = null; |
| 538 | |
| 539 | constructor() { |
| 540 | super(); |
| 541 | |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 542 | // Reference to the container status element |
| 543 | this.containerStatusElement = null; |
| 544 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 545 | // Binding methods to this |
| 546 | this._handleViewModeSelect = this._handleViewModeSelect.bind(this); |
| Sean McCullough | 34bb09a | 2025-05-13 15:39:54 -0700 | [diff] [blame] | 547 | this._handlePopState = this._handlePopState.bind(this); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 548 | this._handleShowCommitDiff = this._handleShowCommitDiff.bind(this); |
| Sean McCullough | 485afc6 | 2025-04-28 14:28:39 -0700 | [diff] [blame] | 549 | this._handleMutlipleChoiceSelected = |
| 550 | this._handleMutlipleChoiceSelected.bind(this); |
| Sean McCullough | d3906e2 | 2025-04-29 17:32:14 +0000 | [diff] [blame] | 551 | this._handleStopClick = this._handleStopClick.bind(this); |
| Pokey Rule | 397871d | 2025-05-19 15:02:45 +0100 | [diff] [blame] | 552 | this._handleEndClick = this._handleEndClick.bind(this); |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 553 | this._handleNotificationsToggle = |
| 554 | this._handleNotificationsToggle.bind(this); |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 555 | this._handleWindowFocus = this._handleWindowFocus.bind(this); |
| 556 | this._handleWindowBlur = this._handleWindowBlur.bind(this); |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 557 | |
| 558 | // Load notification preference from localStorage |
| 559 | try { |
| 560 | const savedPref = localStorage.getItem("sketch-notifications-enabled"); |
| 561 | if (savedPref !== null) { |
| 562 | this.notificationsEnabled = savedPref === "true"; |
| 563 | } |
| 564 | } catch (error) { |
| 565 | console.error("Error loading notification preference:", error); |
| 566 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | // See https://lit.dev/docs/components/lifecycle/ |
| 570 | connectedCallback() { |
| 571 | super.connectedCallback(); |
| 572 | |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 573 | // Get reference to the container status element |
| 574 | setTimeout(() => { |
| 575 | this.containerStatusElement = |
| 576 | this.shadowRoot?.getElementById("container-status"); |
| 577 | }, 0); |
| 578 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 579 | // Initialize client-side nav history. |
| 580 | const url = new URL(window.location.href); |
| 581 | const mode = url.searchParams.get("view") || "chat"; |
| 582 | window.history.replaceState({ mode }, "", url.toString()); |
| 583 | |
| 584 | this.toggleViewMode(mode as ViewMode, false); |
| 585 | // Add popstate event listener to handle browser back/forward navigation |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 586 | window.addEventListener("popstate", this._handlePopState); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 587 | |
| 588 | // Add event listeners |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 589 | window.addEventListener("view-mode-select", this._handleViewModeSelect); |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 590 | window.addEventListener("show-commit-diff", this._handleShowCommitDiff); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 591 | |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 592 | // Add window focus/blur listeners for controlling notifications |
| 593 | window.addEventListener("focus", this._handleWindowFocus); |
| 594 | window.addEventListener("blur", this._handleWindowBlur); |
| Sean McCullough | 485afc6 | 2025-04-28 14:28:39 -0700 | [diff] [blame] | 595 | window.addEventListener( |
| 596 | "multiple-choice-selected", |
| 597 | this._handleMutlipleChoiceSelected, |
| 598 | ); |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 599 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 600 | // register event listeners |
| 601 | this.dataManager.addEventListener( |
| 602 | "dataChanged", |
| Philip Zeyliger | 72682df | 2025-04-23 13:09:46 -0700 | [diff] [blame] | 603 | this.handleDataChanged.bind(this), |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 604 | ); |
| 605 | this.dataManager.addEventListener( |
| 606 | "connectionStatusChanged", |
| Philip Zeyliger | 72682df | 2025-04-23 13:09:46 -0700 | [diff] [blame] | 607 | this.handleConnectionStatusChanged.bind(this), |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 608 | ); |
| 609 | |
| Philip Zeyliger | 9b999b0 | 2025-04-25 16:31:50 +0000 | [diff] [blame] | 610 | // Set initial document title |
| 611 | this.updateDocumentTitle(); |
| 612 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 613 | // Initialize the data manager |
| 614 | this.dataManager.initialize(); |
| Autoformatter | cf57096 | 2025-04-30 17:27:39 +0000 | [diff] [blame] | 615 | |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 616 | // Process existing messages for commit info |
| 617 | if (this.messages && this.messages.length > 0) { |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 618 | // Update last commit info via container status component |
| 619 | setTimeout(() => { |
| 620 | if (this.containerStatusElement) { |
| 621 | this.containerStatusElement.updateLastCommitInfo(this.messages); |
| 622 | } |
| 623 | }, 100); |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 624 | } |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 625 | |
| 626 | // Check if todo panel should be visible on initial load |
| 627 | this.checkTodoPanelVisibility(); |
| 628 | |
| 629 | // Set up ResizeObserver for chat input to update todo panel height |
| 630 | this.setupChatInputObserver(); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | // See https://lit.dev/docs/components/lifecycle/ |
| 634 | disconnectedCallback() { |
| 635 | super.disconnectedCallback(); |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 636 | window.removeEventListener("popstate", this._handlePopState); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 637 | |
| 638 | // Remove event listeners |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 639 | window.removeEventListener("view-mode-select", this._handleViewModeSelect); |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 640 | window.removeEventListener("show-commit-diff", this._handleShowCommitDiff); |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 641 | window.removeEventListener("focus", this._handleWindowFocus); |
| 642 | window.removeEventListener("blur", this._handleWindowBlur); |
| Sean McCullough | 485afc6 | 2025-04-28 14:28:39 -0700 | [diff] [blame] | 643 | window.removeEventListener( |
| 644 | "multiple-choice-selected", |
| 645 | this._handleMutlipleChoiceSelected, |
| 646 | ); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 647 | |
| 648 | // unregister data manager event listeners |
| 649 | this.dataManager.removeEventListener( |
| 650 | "dataChanged", |
| Philip Zeyliger | 72682df | 2025-04-23 13:09:46 -0700 | [diff] [blame] | 651 | this.handleDataChanged.bind(this), |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 652 | ); |
| 653 | this.dataManager.removeEventListener( |
| 654 | "connectionStatusChanged", |
| Philip Zeyliger | 72682df | 2025-04-23 13:09:46 -0700 | [diff] [blame] | 655 | this.handleConnectionStatusChanged.bind(this), |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 656 | ); |
| 657 | |
| 658 | // Disconnect mutation observer if it exists |
| 659 | if (this.mutationObserver) { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 660 | this.mutationObserver.disconnect(); |
| 661 | this.mutationObserver = null; |
| 662 | } |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 663 | |
| 664 | // Disconnect chat input resize observer if it exists |
| 665 | if (this.chatInputResizeObserver) { |
| 666 | this.chatInputResizeObserver.disconnect(); |
| 667 | this.chatInputResizeObserver = null; |
| 668 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 669 | } |
| 670 | |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 671 | updateUrlForViewMode(mode: ViewMode): void { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 672 | // Get the current URL without search parameters |
| 673 | const url = new URL(window.location.href); |
| 674 | |
| 675 | // Clear existing parameters |
| 676 | url.search = ""; |
| 677 | |
| 678 | // Only add view parameter if not in default chat view |
| 679 | if (mode !== "chat") { |
| 680 | url.searchParams.set("view", mode); |
| Philip Zeyliger | 00bcaef | 2025-05-30 04:21:15 +0000 | [diff] [blame] | 681 | const diff2View = this.shadowRoot?.querySelector( |
| 682 | "sketch-diff2-view", |
| 683 | ) as SketchDiff2View; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 684 | |
| Philip Zeyliger | 00bcaef | 2025-05-30 04:21:15 +0000 | [diff] [blame] | 685 | // If in diff2 view and there's a commit hash, include that too |
| 686 | if (mode === "diff2" && diff2View?.commit) { |
| 687 | url.searchParams.set("commit", diff2View.commit); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | |
| 691 | // Update the browser history without reloading the page |
| 692 | window.history.pushState({ mode }, "", url.toString()); |
| 693 | } |
| 694 | |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 695 | private _handlePopState(event: PopStateEvent) { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 696 | if (event.state && event.state.mode) { |
| 697 | this.toggleViewMode(event.state.mode, false); |
| 698 | } else { |
| 699 | this.toggleViewMode("chat", false); |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | /** |
| 704 | * Handle view mode selection event |
| 705 | */ |
| 706 | private _handleViewModeSelect(event: CustomEvent) { |
| Philip Zeyliger | 00bcaef | 2025-05-30 04:21:15 +0000 | [diff] [blame] | 707 | const mode = event.detail.mode as "chat" | "diff2" | "terminal"; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 708 | this.toggleViewMode(mode, true); |
| 709 | } |
| 710 | |
| 711 | /** |
| 712 | * Handle show commit diff event |
| 713 | */ |
| 714 | private _handleShowCommitDiff(event: CustomEvent) { |
| 715 | const { commitHash } = event.detail; |
| 716 | if (commitHash) { |
| 717 | this.showCommitDiff(commitHash); |
| 718 | } |
| 719 | } |
| 720 | |
| Sean McCullough | 485afc6 | 2025-04-28 14:28:39 -0700 | [diff] [blame] | 721 | private _handleMultipleChoice(event: CustomEvent) { |
| 722 | window.console.log("_handleMultipleChoice", event); |
| 723 | this._sendChat; |
| 724 | } |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 725 | |
| 726 | private _handleDiffComment(event: CustomEvent) { |
| 727 | // Empty stub required by the event binding in the template |
| 728 | // Actual handling occurs at global level in sketch-chat-input component |
| 729 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 730 | /** |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 731 | * Listen for commit diff event |
| 732 | * @param commitHash The commit hash to show diff for |
| 733 | */ |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 734 | private showCommitDiff(commitHash: string): void { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 735 | // Store the commit hash |
| 736 | this.currentCommitHash = commitHash; |
| 737 | |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 738 | this.toggleViewMode("diff2", true); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 739 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 740 | this.updateComplete.then(() => { |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 741 | const diff2View = this.shadowRoot?.querySelector("sketch-diff2-view"); |
| 742 | if (diff2View) { |
| 743 | (diff2View as SketchDiff2View).refreshDiffView(); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 744 | } |
| 745 | }); |
| 746 | } |
| 747 | |
| 748 | /** |
| Philip Zeyliger | 00bcaef | 2025-05-30 04:21:15 +0000 | [diff] [blame] | 749 | * Toggle between different view modes: chat, diff2, terminal |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 750 | */ |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 751 | private toggleViewMode(mode: ViewMode, updateHistory: boolean): void { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 752 | // Don't do anything if the mode is already active |
| 753 | if (this.viewMode === mode) return; |
| 754 | |
| 755 | // Update the view mode |
| 756 | this.viewMode = mode; |
| 757 | |
| 758 | if (updateHistory) { |
| 759 | // Update URL with the current view mode |
| 760 | this.updateUrlForViewMode(mode); |
| 761 | } |
| 762 | |
| 763 | // Wait for DOM update to complete |
| 764 | this.updateComplete.then(() => { |
| 765 | // Update active view |
| Pokey Rule | 46fff97 | 2025-04-25 14:57:44 +0100 | [diff] [blame] | 766 | const viewContainerInner = this.shadowRoot?.querySelector( |
| 767 | "#view-container-inner", |
| 768 | ); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 769 | const chatView = this.shadowRoot?.querySelector(".chat-view"); |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 770 | const diff2View = this.shadowRoot?.querySelector(".diff2-view"); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 771 | const terminalView = this.shadowRoot?.querySelector(".terminal-view"); |
| 772 | |
| 773 | // Remove active class from all views |
| 774 | chatView?.classList.remove("view-active"); |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 775 | diff2View?.classList.remove("view-active"); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 776 | terminalView?.classList.remove("view-active"); |
| 777 | |
| Philip Zeyliger | 00bcaef | 2025-05-30 04:21:15 +0000 | [diff] [blame] | 778 | // Add/remove diff2-active class on view container |
| 779 | if (mode === "diff2") { |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 780 | viewContainerInner?.classList.add("diff2-active"); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 781 | } else { |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 782 | viewContainerInner?.classList.remove("diff2-active"); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | // Add active class to the selected view |
| 786 | switch (mode) { |
| 787 | case "chat": |
| 788 | chatView?.classList.add("view-active"); |
| 789 | break; |
| Autoformatter | 8c46362 | 2025-05-16 21:54:17 +0000 | [diff] [blame] | 790 | |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 791 | case "diff2": |
| 792 | diff2View?.classList.add("view-active"); |
| 793 | // Refresh git/recentlog when Monaco diff view is opened |
| 794 | // This ensures branch information is always up-to-date, as branches can change frequently |
| Autoformatter | 8c46362 | 2025-05-16 21:54:17 +0000 | [diff] [blame] | 795 | const diff2ViewComp = |
| 796 | this.shadowRoot?.querySelector("sketch-diff2-view"); |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 797 | if (diff2ViewComp) { |
| 798 | (diff2ViewComp as SketchDiff2View).refreshDiffView(); |
| 799 | } |
| 800 | break; |
| Philip Zeyliger | 2d4c48f | 2025-05-02 23:35:03 +0000 | [diff] [blame] | 801 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 802 | case "terminal": |
| 803 | terminalView?.classList.add("view-active"); |
| 804 | break; |
| 805 | } |
| 806 | |
| 807 | // Update view mode buttons |
| 808 | const viewModeSelect = this.shadowRoot?.querySelector( |
| Philip Zeyliger | 72682df | 2025-04-23 13:09:46 -0700 | [diff] [blame] | 809 | "sketch-view-mode-select", |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 810 | ); |
| 811 | if (viewModeSelect) { |
| 812 | const event = new CustomEvent("update-active-mode", { |
| 813 | detail: { mode }, |
| 814 | bubbles: true, |
| 815 | composed: true, |
| 816 | }); |
| 817 | viewModeSelect.dispatchEvent(event); |
| 818 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 819 | }); |
| 820 | } |
| 821 | |
| Philip Zeyliger | 9b999b0 | 2025-04-25 16:31:50 +0000 | [diff] [blame] | 822 | /** |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 823 | * Updates the document title based on current slug and connection status |
| Philip Zeyliger | 9b999b0 | 2025-04-25 16:31:50 +0000 | [diff] [blame] | 824 | */ |
| 825 | private updateDocumentTitle(): void { |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 826 | let docTitle = `sk: ${this.slug || "untitled"}`; |
| Philip Zeyliger | 9b999b0 | 2025-04-25 16:31:50 +0000 | [diff] [blame] | 827 | |
| 828 | // Add red circle emoji if disconnected |
| 829 | if (this.connectionStatus === "disconnected") { |
| 830 | docTitle += " 🔴"; |
| 831 | } |
| 832 | |
| 833 | document.title = docTitle; |
| 834 | } |
| 835 | |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 836 | // Check and request notification permission if needed |
| 837 | private async checkNotificationPermission(): Promise<boolean> { |
| 838 | // Check if the Notification API is supported |
| 839 | if (!("Notification" in window)) { |
| 840 | console.log("This browser does not support notifications"); |
| 841 | return false; |
| 842 | } |
| 843 | |
| 844 | // Check if permission is already granted |
| 845 | if (Notification.permission === "granted") { |
| 846 | return true; |
| 847 | } |
| 848 | |
| 849 | // If permission is not denied, request it |
| 850 | if (Notification.permission !== "denied") { |
| 851 | const permission = await Notification.requestPermission(); |
| 852 | return permission === "granted"; |
| 853 | } |
| 854 | |
| 855 | return false; |
| 856 | } |
| 857 | |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 858 | // Handle notifications toggle click |
| 859 | private _handleNotificationsToggle(): void { |
| 860 | this.notificationsEnabled = !this.notificationsEnabled; |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 861 | |
| 862 | // If enabling notifications, check permissions |
| 863 | if (this.notificationsEnabled) { |
| 864 | this.checkNotificationPermission(); |
| 865 | } |
| 866 | |
| 867 | // Save preference to localStorage |
| 868 | try { |
| 869 | localStorage.setItem( |
| 870 | "sketch-notifications-enabled", |
| 871 | String(this.notificationsEnabled), |
| 872 | ); |
| 873 | } catch (error) { |
| 874 | console.error("Error saving notification preference:", error); |
| 875 | } |
| 876 | } |
| 877 | |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 878 | // Handle window focus event |
| 879 | private _handleWindowFocus(): void { |
| 880 | this._windowFocused = true; |
| 881 | } |
| 882 | |
| 883 | // Handle window blur event |
| 884 | private _handleWindowBlur(): void { |
| 885 | this._windowFocused = false; |
| 886 | } |
| 887 | |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 888 | // Show notification for message with EndOfTurn=true |
| 889 | private async showEndOfTurnNotification( |
| 890 | message: AgentMessage, |
| 891 | ): Promise<void> { |
| 892 | // Don't show notifications if they're disabled |
| 893 | if (!this.notificationsEnabled) return; |
| 894 | |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 895 | // Don't show notifications if the window is focused |
| 896 | if (this._windowFocused) return; |
| 897 | |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 898 | // Check if we have permission to show notifications |
| 899 | const hasPermission = await this.checkNotificationPermission(); |
| 900 | if (!hasPermission) return; |
| 901 | |
| Philip Zeyliger | 3201133 | 2025-04-30 20:59:40 +0000 | [diff] [blame] | 902 | // Only show notifications for agent messages with end_of_turn=true and no parent_conversation_id |
| 903 | if ( |
| 904 | message.type !== "agent" || |
| 905 | !message.end_of_turn || |
| 906 | message.parent_conversation_id |
| 907 | ) |
| 908 | return; |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 909 | |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 910 | // Create a title that includes the sketch slug |
| 911 | const notificationTitle = `Sketch: ${this.slug || "untitled"}`; |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 912 | |
| 913 | // Extract the beginning of the message content (first 100 chars) |
| 914 | const messagePreview = message.content |
| 915 | ? message.content.substring(0, 100) + |
| 916 | (message.content.length > 100 ? "..." : "") |
| 917 | : "Agent has completed its turn"; |
| 918 | |
| 919 | // Create and show the notification |
| 920 | try { |
| 921 | new Notification(notificationTitle, { |
| 922 | body: messagePreview, |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 923 | icon: "https://sketch.dev/favicon.ico", // Use sketch.dev favicon for notification |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 924 | }); |
| 925 | } catch (error) { |
| 926 | console.error("Error showing notification:", error); |
| 927 | } |
| 928 | } |
| 929 | |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 930 | // Check if todo panel should be visible based on latest todo content from messages or state |
| 931 | private checkTodoPanelVisibility(): void { |
| 932 | // Find the latest todo content from messages first |
| 933 | let latestTodoContent = ""; |
| 934 | for (let i = this.messages.length - 1; i >= 0; i--) { |
| 935 | const message = this.messages[i]; |
| 936 | if (message.todo_content !== undefined) { |
| 937 | latestTodoContent = message.todo_content || ""; |
| 938 | break; |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | // If no todo content found in messages, check the current state |
| 943 | if (latestTodoContent === "" && this.containerState?.todo_content) { |
| 944 | latestTodoContent = this.containerState.todo_content; |
| 945 | } |
| 946 | |
| 947 | // Parse the todo data to check if there are any actual todos |
| 948 | let hasTodos = false; |
| 949 | if (latestTodoContent.trim()) { |
| 950 | try { |
| 951 | const todoData = JSON.parse(latestTodoContent); |
| 952 | hasTodos = todoData.items && todoData.items.length > 0; |
| 953 | } catch (error) { |
| 954 | // Invalid JSON, treat as no todos |
| 955 | hasTodos = false; |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | this._todoPanelVisible = hasTodos; |
| 960 | |
| 961 | // Update todo panel content if visible |
| 962 | if (hasTodos) { |
| 963 | const todoPanel = this.shadowRoot?.querySelector( |
| 964 | "sketch-todo-panel", |
| 965 | ) as any; |
| 966 | if (todoPanel && todoPanel.updateTodoContent) { |
| 967 | todoPanel.updateTodoContent(latestTodoContent); |
| 968 | } |
| 969 | } |
| 970 | } |
| 971 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 972 | private handleDataChanged(eventData: { |
| 973 | state: State; |
| Sean McCullough | d9f1337 | 2025-04-21 15:08:49 -0700 | [diff] [blame] | 974 | newMessages: AgentMessage[]; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 975 | }): void { |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 976 | const { state, newMessages } = eventData; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 977 | |
| 978 | // Update state if we received it |
| 979 | if (state) { |
| Josh Bleecher Snyder | e81233f | 2025-04-30 04:05:41 +0000 | [diff] [blame] | 980 | // Ensure we're using the latest call status to prevent indicators from being stuck |
| Autoformatter | f830c9d | 2025-04-30 18:16:01 +0000 | [diff] [blame] | 981 | if ( |
| 982 | state.outstanding_llm_calls === 0 && |
| 983 | state.outstanding_tool_calls.length === 0 |
| 984 | ) { |
| Josh Bleecher Snyder | e81233f | 2025-04-30 04:05:41 +0000 | [diff] [blame] | 985 | // Force reset containerState calls when nothing is reported as in progress |
| 986 | state.outstanding_llm_calls = 0; |
| 987 | state.outstanding_tool_calls = []; |
| 988 | } |
| Autoformatter | f830c9d | 2025-04-30 18:16:01 +0000 | [diff] [blame] | 989 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 990 | this.containerState = state; |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 991 | this.slug = state.slug || ""; |
| Philip Zeyliger | 9b999b0 | 2025-04-25 16:31:50 +0000 | [diff] [blame] | 992 | |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 993 | // Update document title when sketch slug changes |
| Philip Zeyliger | 9b999b0 | 2025-04-25 16:31:50 +0000 | [diff] [blame] | 994 | this.updateDocumentTitle(); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 995 | } |
| 996 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 997 | // Update messages |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 998 | this.messages = aggregateAgentMessages(this.messages, newMessages); |
| Autoformatter | cf57096 | 2025-04-30 17:27:39 +0000 | [diff] [blame] | 999 | |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 1000 | // Process new messages to find commit messages |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 1001 | // Update last commit info via container status component |
| 1002 | if (this.containerStatusElement) { |
| 1003 | this.containerStatusElement.updateLastCommitInfo(newMessages); |
| 1004 | } |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 1005 | |
| 1006 | // Check for agent messages with end_of_turn=true and show notifications |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 1007 | if (newMessages && newMessages.length > 0) { |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 1008 | for (const message of newMessages) { |
| Philip Zeyliger | 3201133 | 2025-04-30 20:59:40 +0000 | [diff] [blame] | 1009 | if ( |
| 1010 | message.type === "agent" && |
| 1011 | message.end_of_turn && |
| 1012 | !message.parent_conversation_id |
| 1013 | ) { |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 1014 | this.showEndOfTurnNotification(message); |
| 1015 | break; // Only show one notification per batch of messages |
| 1016 | } |
| 1017 | } |
| 1018 | } |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 1019 | |
| 1020 | // Check if todo panel should be visible after agent loop iteration |
| 1021 | this.checkTodoPanelVisibility(); |
| 1022 | |
| 1023 | // Ensure chat input observer is set up when new data comes in |
| 1024 | if (!this.chatInputResizeObserver) { |
| 1025 | this.setupChatInputObserver(); |
| 1026 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | private handleConnectionStatusChanged( |
| 1030 | status: ConnectionStatus, |
| Philip Zeyliger | 72682df | 2025-04-23 13:09:46 -0700 | [diff] [blame] | 1031 | errorMessage?: string, |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1032 | ): void { |
| 1033 | this.connectionStatus = status; |
| 1034 | this.connectionErrorMessage = errorMessage || ""; |
| Philip Zeyliger | 9b999b0 | 2025-04-25 16:31:50 +0000 | [diff] [blame] | 1035 | |
| 1036 | // Update document title when connection status changes |
| 1037 | this.updateDocumentTitle(); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1038 | } |
| 1039 | |
| Sean McCullough | d3906e2 | 2025-04-29 17:32:14 +0000 | [diff] [blame] | 1040 | private async _handleStopClick(): Promise<void> { |
| 1041 | try { |
| 1042 | const response = await fetch("cancel", { |
| 1043 | method: "POST", |
| 1044 | headers: { |
| 1045 | "Content-Type": "application/json", |
| 1046 | }, |
| 1047 | body: JSON.stringify({ reason: "user requested cancellation" }), |
| 1048 | }); |
| 1049 | |
| 1050 | if (!response.ok) { |
| 1051 | const errorData = await response.text(); |
| 1052 | throw new Error( |
| 1053 | `Failed to stop operation: ${response.status} - ${errorData}`, |
| 1054 | ); |
| 1055 | } |
| 1056 | |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 1057 | // Stop request sent |
| Sean McCullough | d3906e2 | 2025-04-29 17:32:14 +0000 | [diff] [blame] | 1058 | } catch (error) { |
| 1059 | console.error("Error stopping operation:", error); |
| Sean McCullough | d3906e2 | 2025-04-29 17:32:14 +0000 | [diff] [blame] | 1060 | } |
| 1061 | } |
| 1062 | |
| Pokey Rule | 397871d | 2025-05-19 15:02:45 +0100 | [diff] [blame] | 1063 | private async _handleEndClick(event?: Event): Promise<void> { |
| 1064 | if (event) { |
| 1065 | event.preventDefault(); |
| 1066 | event.stopPropagation(); |
| 1067 | } |
| Philip Zeyliger | b573940 | 2025-06-02 07:04:34 -0700 | [diff] [blame] | 1068 | |
| Philip Zeyliger | 1609893 | 2025-06-04 11:02:55 -0700 | [diff] [blame] | 1069 | // Show confirmation dialog |
| 1070 | const confirmed = window.confirm( |
| 1071 | "Ending the session will shut down the underlying container. Are you sure?", |
| 1072 | ); |
| 1073 | if (!confirmed) return; |
| Pokey Rule | 397871d | 2025-05-19 15:02:45 +0100 | [diff] [blame] | 1074 | |
| 1075 | try { |
| 1076 | const response = await fetch("end", { |
| 1077 | method: "POST", |
| 1078 | headers: { |
| 1079 | "Content-Type": "application/json", |
| 1080 | }, |
| Philip Zeyliger | 1609893 | 2025-06-04 11:02:55 -0700 | [diff] [blame] | 1081 | body: JSON.stringify({ reason: "user requested end of session" }), |
| Pokey Rule | 397871d | 2025-05-19 15:02:45 +0100 | [diff] [blame] | 1082 | }); |
| 1083 | |
| 1084 | if (!response.ok) { |
| 1085 | const errorData = await response.text(); |
| 1086 | throw new Error( |
| 1087 | `Failed to end session: ${response.status} - ${errorData}`, |
| 1088 | ); |
| 1089 | } |
| 1090 | |
| 1091 | // After successful response, redirect to messages view |
| 1092 | // Extract the session ID from the URL |
| 1093 | const currentUrl = window.location.href; |
| 1094 | // The URL pattern should be like https://sketch.dev/s/cs71-8qa6-1124-aw79/ |
| 1095 | const urlParts = currentUrl.split("/"); |
| 1096 | let sessionId = ""; |
| 1097 | |
| 1098 | // Find the session ID in the URL (should be after /s/) |
| 1099 | for (let i = 0; i < urlParts.length; i++) { |
| 1100 | if (urlParts[i] === "s" && i + 1 < urlParts.length) { |
| 1101 | sessionId = urlParts[i + 1]; |
| 1102 | break; |
| 1103 | } |
| 1104 | } |
| 1105 | |
| 1106 | if (sessionId) { |
| 1107 | // Create the messages URL |
| 1108 | const messagesUrl = `/messages/${sessionId}`; |
| 1109 | // Redirect to messages view |
| 1110 | window.location.href = messagesUrl; |
| 1111 | } |
| 1112 | |
| 1113 | // End request sent - connection will be closed by server |
| 1114 | } catch (error) { |
| 1115 | console.error("Error ending session:", error); |
| 1116 | } |
| 1117 | } |
| 1118 | |
| Sean McCullough | 485afc6 | 2025-04-28 14:28:39 -0700 | [diff] [blame] | 1119 | async _handleMutlipleChoiceSelected(e: CustomEvent) { |
| 1120 | const chatInput = this.shadowRoot?.querySelector( |
| 1121 | "sketch-chat-input", |
| 1122 | ) as SketchChatInput; |
| 1123 | if (chatInput) { |
| Josh Bleecher Snyder | 6cad861 | 2025-05-30 19:25:39 +0000 | [diff] [blame] | 1124 | if (chatInput.content && chatInput.content.trim() !== "") { |
| 1125 | chatInput.content += "\n\n"; |
| 1126 | } |
| 1127 | chatInput.content += e.detail.responseText; |
| Sean McCullough | 485afc6 | 2025-04-28 14:28:39 -0700 | [diff] [blame] | 1128 | chatInput.focus(); |
| Josh Bleecher Snyder | 6cad861 | 2025-05-30 19:25:39 +0000 | [diff] [blame] | 1129 | // Adjust textarea height to accommodate new content |
| 1130 | requestAnimationFrame(() => { |
| 1131 | if (chatInput.adjustChatSpacing) { |
| 1132 | chatInput.adjustChatSpacing(); |
| 1133 | } |
| 1134 | }); |
| Sean McCullough | 485afc6 | 2025-04-28 14:28:39 -0700 | [diff] [blame] | 1135 | } |
| 1136 | } |
| 1137 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1138 | async _sendChat(e: CustomEvent) { |
| 1139 | console.log("app shell: _sendChat", e); |
| Sean McCullough | 485afc6 | 2025-04-28 14:28:39 -0700 | [diff] [blame] | 1140 | e.preventDefault(); |
| 1141 | e.stopPropagation(); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1142 | const message = e.detail.message?.trim(); |
| 1143 | if (message == "") { |
| 1144 | return; |
| 1145 | } |
| 1146 | try { |
| Josh Bleecher Snyder | 98b64d1 | 2025-05-12 19:42:43 +0000 | [diff] [blame] | 1147 | // Always switch to chat view when sending a message so user can see processing |
| 1148 | if (this.viewMode !== "chat") { |
| 1149 | this.toggleViewMode("chat", true); |
| 1150 | } |
| Autoformatter | 5c7f957 | 2025-05-13 01:17:31 +0000 | [diff] [blame] | 1151 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1152 | // Send the message to the server |
| 1153 | const response = await fetch("chat", { |
| 1154 | method: "POST", |
| 1155 | headers: { |
| 1156 | "Content-Type": "application/json", |
| 1157 | }, |
| 1158 | body: JSON.stringify({ message }), |
| 1159 | }); |
| 1160 | |
| 1161 | if (!response.ok) { |
| 1162 | const errorData = await response.text(); |
| 1163 | throw new Error(`Server error: ${response.status} - ${errorData}`); |
| 1164 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1165 | } catch (error) { |
| 1166 | console.error("Error sending chat message:", error); |
| 1167 | const statusText = document.getElementById("statusText"); |
| 1168 | if (statusText) { |
| 1169 | statusText.textContent = "Error sending message"; |
| 1170 | } |
| 1171 | } |
| 1172 | } |
| 1173 | |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 1174 | private scrollContainerRef = createRef<HTMLElement>(); |
| 1175 | |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 1176 | /** |
| 1177 | * Set up ResizeObserver to monitor chat input height changes |
| 1178 | */ |
| 1179 | private setupChatInputObserver(): void { |
| 1180 | // Wait for DOM to be ready |
| 1181 | this.updateComplete.then(() => { |
| 1182 | const chatInputElement = this.shadowRoot?.querySelector("#chat-input"); |
| 1183 | if (chatInputElement && !this.chatInputResizeObserver) { |
| 1184 | this.chatInputResizeObserver = new ResizeObserver((entries) => { |
| 1185 | for (const entry of entries) { |
| 1186 | this.updateTodoPanelHeight(entry.contentRect.height); |
| 1187 | } |
| 1188 | }); |
| 1189 | |
| 1190 | this.chatInputResizeObserver.observe(chatInputElement); |
| 1191 | |
| 1192 | // Initial height calculation |
| 1193 | const rect = chatInputElement.getBoundingClientRect(); |
| 1194 | this.updateTodoPanelHeight(rect.height); |
| 1195 | } |
| 1196 | }); |
| 1197 | } |
| 1198 | |
| 1199 | /** |
| 1200 | * Update the CSS custom property that controls todo panel bottom position |
| 1201 | */ |
| 1202 | private updateTodoPanelHeight(chatInputHeight: number): void { |
| 1203 | // Add some padding (20px) between todo panel and chat input |
| 1204 | const bottomOffset = chatInputHeight; |
| 1205 | |
| 1206 | // Update the CSS custom property on the host element |
| 1207 | this.style.setProperty("--chat-input-height", `${bottomOffset}px`); |
| 1208 | } |
| 1209 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1210 | render() { |
| 1211 | return html` |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 1212 | <div id="top-banner"> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1213 | <div class="title-container"> |
| Philip Zeyliger | 0113be5 | 2025-06-07 23:53:41 +0000 | [diff] [blame] | 1214 | <h1 class="banner-title"> |
| 1215 | ${this.containerState?.skaband_addr |
| 1216 | ? html`<a |
| 1217 | href="${this.containerState.skaband_addr}" |
| 1218 | target="_blank" |
| 1219 | rel="noopener noreferrer" |
| 1220 | > |
| 1221 | <img |
| 1222 | src="${this.containerState.skaband_addr}/sketch.dev.png" |
| 1223 | alt="sketch" |
| 1224 | /> |
| 1225 | sketch |
| 1226 | </a>` |
| 1227 | : html`sketch`} |
| 1228 | </h1> |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 1229 | <h2 class="slug-title">${this.slug}</h2> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1230 | </div> |
| 1231 | |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 1232 | <!-- Container status info moved above tabs --> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1233 | <sketch-container-status |
| 1234 | .state=${this.containerState} |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 1235 | id="container-status" |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1236 | ></sketch-container-status> |
| Autoformatter | cf57096 | 2025-04-30 17:27:39 +0000 | [diff] [blame] | 1237 | |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 1238 | <!-- Last Commit section moved to sketch-container-status --> |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 1239 | |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 1240 | <!-- Views section with tabs --> |
| 1241 | <sketch-view-mode-select></sketch-view-mode-select> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1242 | |
| 1243 | <div class="refresh-control"> |
| Sean McCullough | d3906e2 | 2025-04-29 17:32:14 +0000 | [diff] [blame] | 1244 | <button |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 1245 | id="stopButton" |
| 1246 | class="stop-button" |
| 1247 | ?disabled=${(this.containerState?.outstanding_llm_calls || 0) === |
| 1248 | 0 && |
| 1249 | (this.containerState?.outstanding_tool_calls || []).length === 0} |
| 1250 | > |
| 1251 | <svg |
| 1252 | class="button-icon" |
| 1253 | xmlns="http://www.w3.org/2000/svg" |
| 1254 | viewBox="0 0 24 24" |
| 1255 | fill="none" |
| 1256 | stroke="currentColor" |
| 1257 | stroke-width="2" |
| 1258 | stroke-linecap="round" |
| 1259 | stroke-linejoin="round" |
| 1260 | > |
| 1261 | <rect x="6" y="6" width="12" height="12" /> |
| 1262 | </svg> |
| 1263 | <span class="button-text">Stop</span> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1264 | </button> |
| Pokey Rule | 397871d | 2025-05-19 15:02:45 +0100 | [diff] [blame] | 1265 | <button |
| 1266 | id="endButton" |
| 1267 | class="end-button" |
| 1268 | @click=${this._handleEndClick} |
| 1269 | > |
| 1270 | <svg |
| 1271 | class="button-icon" |
| 1272 | xmlns="http://www.w3.org/2000/svg" |
| 1273 | viewBox="0 0 24 24" |
| 1274 | fill="none" |
| 1275 | stroke="currentColor" |
| 1276 | stroke-width="2" |
| 1277 | stroke-linecap="round" |
| 1278 | stroke-linejoin="round" |
| 1279 | > |
| 1280 | <path d="M18 6L6 18" /> |
| 1281 | <path d="M6 6l12 12" /> |
| 1282 | </svg> |
| 1283 | <span class="button-text">End</span> |
| 1284 | </button> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1285 | |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 1286 | <div |
| 1287 | class="notifications-toggle" |
| 1288 | @click=${this._handleNotificationsToggle} |
| 1289 | title="${this.notificationsEnabled |
| 1290 | ? "Disable" |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 1291 | : "Enable"} notifications when the agent completes its turn" |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 1292 | > |
| 1293 | <div |
| 1294 | class="bell-icon ${!this.notificationsEnabled |
| 1295 | ? "bell-disabled" |
| 1296 | : ""}" |
| 1297 | > |
| 1298 | <!-- Bell SVG icon --> |
| 1299 | <svg |
| 1300 | xmlns="http://www.w3.org/2000/svg" |
| 1301 | width="16" |
| 1302 | height="16" |
| 1303 | fill="currentColor" |
| 1304 | viewBox="0 0 16 16" |
| 1305 | > |
| 1306 | <path |
| 1307 | d="M8 16a2 2 0 0 0 2-2H6a2 2 0 0 0 2 2zM8 1.918l-.797.161A4.002 4.002 0 0 0 4 6c0 .628-.134 2.197-.459 3.742-.16.767-.376 1.566-.663 2.258h10.244c-.287-.692-.502-1.49-.663-2.258C12.134 8.197 12 6.628 12 6a4.002 4.002 0 0 0-3.203-3.92L8 1.917zM14.22 12c.223.447.481.801.78 1H1c.299-.199.557-.553.78-1C2.68 10.2 3 6.88 3 6c0-2.42 1.72-4.44 4.005-4.901a1 1 0 1 1 1.99 0A5.002 5.002 0 0 1 13 6c0 .88.32 4.2 1.22 6z" |
| 1308 | /> |
| 1309 | </svg> |
| 1310 | </div> |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 1311 | </div> |
| 1312 | |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 1313 | <sketch-call-status |
| Sean McCullough | d9d4581 | 2025-04-30 16:53:41 -0700 | [diff] [blame] | 1314 | .agentState=${this.containerState?.agent_state} |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 1315 | .llmCalls=${this.containerState?.outstanding_llm_calls || 0} |
| 1316 | .toolCalls=${this.containerState?.outstanding_tool_calls || []} |
| Philip Zeyliger | 7231839 | 2025-05-14 02:56:07 +0000 | [diff] [blame] | 1317 | .isIdle=${this.messages.length > 0 |
| 1318 | ? this.messages[this.messages.length - 1]?.end_of_turn && |
| 1319 | !this.messages[this.messages.length - 1]?.parent_conversation_id |
| 1320 | : true} |
| Philip Zeyliger | 5e35702 | 2025-05-16 04:50:34 +0000 | [diff] [blame] | 1321 | .isDisconnected=${this.connectionStatus === "disconnected"} |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 1322 | ></sketch-call-status> |
| Philip Zeyliger | 25f6ff1 | 2025-05-02 04:24:10 +0000 | [diff] [blame] | 1323 | |
| 1324 | <sketch-network-status |
| 1325 | connection=${this.connectionStatus} |
| 1326 | error=${this.connectionErrorMessage} |
| 1327 | ></sketch-network-status> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1328 | </div> |
| 1329 | </div> |
| 1330 | |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 1331 | <div id="view-container" ${ref(this.scrollContainerRef)}> |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 1332 | <div |
| 1333 | id="view-container-inner" |
| 1334 | class="${this._todoPanelVisible && this.viewMode === "chat" |
| 1335 | ? "with-todo-panel" |
| 1336 | : ""}" |
| 1337 | > |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 1338 | <div |
| 1339 | class="chat-view ${this.viewMode === "chat" ? "view-active" : ""}" |
| 1340 | > |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 1341 | <div |
| 1342 | class="chat-timeline-container ${this._todoPanelVisible && |
| 1343 | this.viewMode === "chat" |
| 1344 | ? "with-todo-panel" |
| 1345 | : ""}" |
| 1346 | > |
| 1347 | <sketch-timeline |
| 1348 | .messages=${this.messages} |
| 1349 | .scrollContainer=${this.scrollContainerRef} |
| 1350 | .agentState=${this.containerState?.agent_state} |
| 1351 | .llmCalls=${this.containerState?.outstanding_llm_calls || 0} |
| 1352 | .toolCalls=${this.containerState?.outstanding_tool_calls || []} |
| Philip Zeyliger | b8a8f35 | 2025-06-02 07:39:37 -0700 | [diff] [blame] | 1353 | .firstMessageIndex=${this.containerState?.first_message_index || |
| 1354 | 0} |
| philip.zeyliger | 6d3de48 | 2025-06-10 19:38:14 -0700 | [diff] [blame] | 1355 | .state=${this.containerState} |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 1356 | ></sketch-timeline> |
| 1357 | </div> |
| 1358 | </div> |
| 1359 | |
| 1360 | <!-- Todo panel positioned outside the main flow - only visible in chat view --> |
| 1361 | <div |
| 1362 | class="todo-panel-container ${this._todoPanelVisible && |
| 1363 | this.viewMode === "chat" |
| 1364 | ? "visible" |
| 1365 | : ""}" |
| 1366 | > |
| 1367 | <sketch-todo-panel |
| 1368 | .visible=${this._todoPanelVisible && this.viewMode === "chat"} |
| 1369 | ></sketch-todo-panel> |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 1370 | </div> |
| 1371 | <div |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 1372 | class="diff2-view ${this.viewMode === "diff2" ? "view-active" : ""}" |
| 1373 | > |
| 1374 | <sketch-diff2-view |
| 1375 | .commit=${this.currentCommitHash} |
| 1376 | .gitService=${new DefaultGitDataService()} |
| 1377 | @diff-comment="${this._handleDiffComment}" |
| 1378 | ></sketch-diff2-view> |
| 1379 | </div> |
| Philip Zeyliger | 2d4c48f | 2025-05-02 23:35:03 +0000 | [diff] [blame] | 1380 | |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 1381 | <div |
| 1382 | class="terminal-view ${this.viewMode === "terminal" |
| 1383 | ? "view-active" |
| 1384 | : ""}" |
| 1385 | > |
| 1386 | <sketch-terminal></sketch-terminal> |
| 1387 | </div> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1388 | </div> |
| 1389 | </div> |
| 1390 | |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 1391 | <div id="chat-input"> |
| 1392 | <sketch-chat-input @send-chat="${this._sendChat}"></sketch-chat-input> |
| 1393 | </div> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1394 | `; |
| 1395 | } |
| 1396 | |
| 1397 | /** |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1398 | * Lifecycle callback when component is first connected to DOM |
| 1399 | */ |
| 1400 | firstUpdated(): void { |
| 1401 | if (this.viewMode !== "chat") { |
| 1402 | return; |
| 1403 | } |
| 1404 | |
| 1405 | // Initial scroll to bottom when component is first rendered |
| 1406 | setTimeout( |
| 1407 | () => this.scrollTo({ top: this.scrollHeight, behavior: "smooth" }), |
| Philip Zeyliger | 72682df | 2025-04-23 13:09:46 -0700 | [diff] [blame] | 1408 | 50, |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1409 | ); |
| 1410 | |
| Philip Zeyliger | 2c4db09 | 2025-04-28 16:57:50 -0700 | [diff] [blame] | 1411 | // Setup stop button |
| 1412 | const stopButton = this.renderRoot?.querySelector( |
| 1413 | "#stopButton", |
| 1414 | ) as HTMLButtonElement; |
| 1415 | stopButton?.addEventListener("click", async () => { |
| 1416 | try { |
| Sean McCullough | 495cb96 | 2025-05-01 16:25:53 -0700 | [diff] [blame] | 1417 | const response = await fetch("cancel", { |
| Philip Zeyliger | 2c4db09 | 2025-04-28 16:57:50 -0700 | [diff] [blame] | 1418 | method: "POST", |
| 1419 | headers: { |
| 1420 | "Content-Type": "application/json", |
| 1421 | }, |
| 1422 | body: JSON.stringify({ reason: "User clicked stop button" }), |
| 1423 | }); |
| 1424 | if (!response.ok) { |
| 1425 | console.error("Failed to cancel:", await response.text()); |
| 1426 | } |
| 1427 | } catch (error) { |
| 1428 | console.error("Error cancelling operation:", error); |
| 1429 | } |
| 1430 | }); |
| 1431 | |
| Pokey Rule | 397871d | 2025-05-19 15:02:45 +0100 | [diff] [blame] | 1432 | // Setup end button |
| 1433 | const endButton = this.renderRoot?.querySelector( |
| 1434 | "#endButton", |
| 1435 | ) as HTMLButtonElement; |
| 1436 | // We're already using the @click binding in the HTML, so manual event listener not needed here |
| 1437 | |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 1438 | // Process any existing messages to find commit information |
| 1439 | if (this.messages && this.messages.length > 0) { |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 1440 | // Update last commit info via container status component |
| 1441 | if (this.containerStatusElement) { |
| 1442 | this.containerStatusElement.updateLastCommitInfo(this.messages); |
| 1443 | } |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 1444 | } |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 1445 | |
| 1446 | // Set up chat input height observer for todo panel |
| 1447 | this.setupChatInputObserver(); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1448 | } |
| 1449 | } |
| 1450 | |
| 1451 | declare global { |
| 1452 | interface HTMLElementTagNameMap { |
| 1453 | "sketch-app-shell": SketchAppShell; |
| 1454 | } |
| 1455 | } |