| 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 | } |
| philip.zeyliger | ffa94c6 | 2025-06-19 18:43:37 -0700 | [diff] [blame^] | 469 | |
| 470 | /* Print styles for full chat printing */ |
| 471 | @media print { |
| 472 | :host { |
| 473 | height: auto !important; |
| 474 | overflow: visible !important; |
| 475 | display: block !important; |
| 476 | } |
| 477 | |
| 478 | /* Hide non-essential UI elements during printing */ |
| 479 | #top-banner { |
| 480 | border-bottom: 1px solid #000; |
| 481 | box-shadow: none; |
| 482 | page-break-inside: avoid; |
| 483 | } |
| 484 | |
| 485 | /* Hide interactive elements that aren't useful in print */ |
| 486 | .stop-button, |
| 487 | .end-button, |
| 488 | .notifications-toggle, |
| 489 | sketch-call-status, |
| 490 | sketch-network-status, |
| 491 | sketch-view-mode-select { |
| 492 | display: none !important; |
| 493 | } |
| 494 | |
| 495 | /* Ensure view container can expand to full content */ |
| 496 | #view-container { |
| 497 | overflow: visible !important; |
| 498 | flex: none !important; |
| 499 | height: auto !important; |
| 500 | max-height: none !important; |
| 501 | } |
| 502 | |
| 503 | #view-container-inner { |
| 504 | height: auto !important; |
| 505 | max-height: none !important; |
| 506 | overflow: visible !important; |
| 507 | } |
| 508 | |
| 509 | /* Remove todo panel from print to avoid layout issues */ |
| 510 | .todo-panel-container { |
| 511 | display: none !important; |
| 512 | } |
| 513 | |
| 514 | /* Ensure chat timeline container takes full width in print */ |
| 515 | .chat-timeline-container { |
| 516 | margin-right: 0 !important; |
| 517 | width: 100% !important; |
| 518 | height: auto !important; |
| 519 | overflow: visible !important; |
| 520 | } |
| 521 | |
| 522 | /* Make chat view fully visible */ |
| 523 | .chat-view { |
| 524 | height: auto !important; |
| 525 | overflow: visible !important; |
| 526 | } |
| 527 | |
| 528 | /* Hide chat input during printing */ |
| 529 | #chat-input { |
| 530 | display: none !important; |
| 531 | } |
| 532 | |
| 533 | /* Adjust diff2 and terminal views for print */ |
| 534 | .diff2-view, |
| 535 | .terminal-view { |
| 536 | height: auto !important; |
| 537 | overflow: visible !important; |
| 538 | } |
| 539 | |
| 540 | /* Ensure only active view is shown in print */ |
| 541 | .chat-view:not(.view-active), |
| 542 | .diff2-view:not(.view-active), |
| 543 | .terminal-view:not(.view-active) { |
| 544 | display: none !important; |
| 545 | } |
| 546 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 547 | `; |
| 548 | |
| 549 | // Header bar: Network connection status details |
| 550 | @property() |
| 551 | connectionStatus: ConnectionStatus = "disconnected"; |
| Autoformatter | cf57096 | 2025-04-30 17:27:39 +0000 | [diff] [blame] | 552 | |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 553 | // Track if the last commit info has been copied |
| 554 | @state() |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 555 | // lastCommitCopied moved to sketch-container-status |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 556 | |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 557 | // Track notification preferences |
| 558 | @state() |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 559 | notificationsEnabled: boolean = false; |
| 560 | |
| 561 | // Track if the window is focused to control notifications |
| 562 | @state() |
| 563 | private _windowFocused: boolean = document.hasFocus(); |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 564 | |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 565 | // Track if the todo panel should be visible |
| 566 | @state() |
| 567 | private _todoPanelVisible: boolean = false; |
| 568 | |
| banksean | 65ff909 | 2025-06-19 00:36:25 +0000 | [diff] [blame] | 569 | // Store scroll position for the chat view to preserve it when switching tabs |
| 570 | @state() |
| 571 | private _chatScrollPosition: number = 0; |
| 572 | |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 573 | // ResizeObserver for tracking chat input height changes |
| 574 | private chatInputResizeObserver: ResizeObserver | null = null; |
| 575 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 576 | @property() |
| 577 | connectionErrorMessage: string = ""; |
| 578 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 579 | // Chat messages |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 580 | @property({ attribute: false }) |
| Sean McCullough | d9f1337 | 2025-04-21 15:08:49 -0700 | [diff] [blame] | 581 | messages: AgentMessage[] = []; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 582 | |
| 583 | @property() |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 584 | set slug(value: string) { |
| 585 | const oldValue = this._slug; |
| 586 | this._slug = value; |
| 587 | this.requestUpdate("slug", oldValue); |
| 588 | // Update document title when slug property changes |
| Philip Zeyliger | 9b999b0 | 2025-04-25 16:31:50 +0000 | [diff] [blame] | 589 | this.updateDocumentTitle(); |
| 590 | } |
| 591 | |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 592 | get slug(): string { |
| 593 | return this._slug; |
| Philip Zeyliger | 9b999b0 | 2025-04-25 16:31:50 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 596 | private _slug: string = ""; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 597 | |
| 598 | private dataManager = new DataManager(); |
| 599 | |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 600 | @property({ attribute: false }) |
| Sean McCullough | d9f1337 | 2025-04-21 15:08:49 -0700 | [diff] [blame] | 601 | containerState: State = { |
| Philip Zeyliger | d03318d | 2025-05-08 13:09:12 -0700 | [diff] [blame] | 602 | state_version: 2, |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 603 | slug: "", |
| Sean McCullough | d9f1337 | 2025-04-21 15:08:49 -0700 | [diff] [blame] | 604 | os: "", |
| 605 | message_count: 0, |
| 606 | hostname: "", |
| 607 | working_dir: "", |
| 608 | initial_commit: "", |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 609 | outstanding_llm_calls: 0, |
| 610 | outstanding_tool_calls: [], |
| Philip Zeyliger | c72fff5 | 2025-04-29 20:17:54 +0000 | [diff] [blame] | 611 | session_id: "", |
| 612 | ssh_available: false, |
| Philip Zeyliger | 2c4db09 | 2025-04-28 16:57:50 -0700 | [diff] [blame] | 613 | ssh_error: "", |
| 614 | in_container: false, |
| 615 | first_message_index: 0, |
| Philip Zeyliger | 64f6046 | 2025-06-16 13:57:10 -0700 | [diff] [blame] | 616 | diff_lines_added: 0, |
| 617 | diff_lines_removed: 0, |
| Sean McCullough | d9f1337 | 2025-04-21 15:08:49 -0700 | [diff] [blame] | 618 | }; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 619 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 620 | // Mutation observer to detect when new messages are added |
| 621 | private mutationObserver: MutationObserver | null = null; |
| 622 | |
| 623 | constructor() { |
| 624 | super(); |
| 625 | |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 626 | // Reference to the container status element |
| 627 | this.containerStatusElement = null; |
| 628 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 629 | // Binding methods to this |
| 630 | this._handleViewModeSelect = this._handleViewModeSelect.bind(this); |
| Sean McCullough | 34bb09a | 2025-05-13 15:39:54 -0700 | [diff] [blame] | 631 | this._handlePopState = this._handlePopState.bind(this); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 632 | this._handleShowCommitDiff = this._handleShowCommitDiff.bind(this); |
| Sean McCullough | 485afc6 | 2025-04-28 14:28:39 -0700 | [diff] [blame] | 633 | this._handleMutlipleChoiceSelected = |
| 634 | this._handleMutlipleChoiceSelected.bind(this); |
| Sean McCullough | d3906e2 | 2025-04-29 17:32:14 +0000 | [diff] [blame] | 635 | this._handleStopClick = this._handleStopClick.bind(this); |
| Pokey Rule | 397871d | 2025-05-19 15:02:45 +0100 | [diff] [blame] | 636 | this._handleEndClick = this._handleEndClick.bind(this); |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 637 | this._handleNotificationsToggle = |
| 638 | this._handleNotificationsToggle.bind(this); |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 639 | this._handleWindowFocus = this._handleWindowFocus.bind(this); |
| 640 | this._handleWindowBlur = this._handleWindowBlur.bind(this); |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 641 | |
| 642 | // Load notification preference from localStorage |
| 643 | try { |
| 644 | const savedPref = localStorage.getItem("sketch-notifications-enabled"); |
| 645 | if (savedPref !== null) { |
| 646 | this.notificationsEnabled = savedPref === "true"; |
| 647 | } |
| 648 | } catch (error) { |
| 649 | console.error("Error loading notification preference:", error); |
| 650 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | // See https://lit.dev/docs/components/lifecycle/ |
| 654 | connectedCallback() { |
| 655 | super.connectedCallback(); |
| 656 | |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 657 | // Get reference to the container status element |
| 658 | setTimeout(() => { |
| 659 | this.containerStatusElement = |
| 660 | this.shadowRoot?.getElementById("container-status"); |
| 661 | }, 0); |
| 662 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 663 | // Initialize client-side nav history. |
| 664 | const url = new URL(window.location.href); |
| 665 | const mode = url.searchParams.get("view") || "chat"; |
| 666 | window.history.replaceState({ mode }, "", url.toString()); |
| 667 | |
| 668 | this.toggleViewMode(mode as ViewMode, false); |
| 669 | // Add popstate event listener to handle browser back/forward navigation |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 670 | window.addEventListener("popstate", this._handlePopState); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 671 | |
| 672 | // Add event listeners |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 673 | window.addEventListener("view-mode-select", this._handleViewModeSelect); |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 674 | window.addEventListener("show-commit-diff", this._handleShowCommitDiff); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 675 | |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 676 | // Add window focus/blur listeners for controlling notifications |
| 677 | window.addEventListener("focus", this._handleWindowFocus); |
| 678 | window.addEventListener("blur", this._handleWindowBlur); |
| Sean McCullough | 485afc6 | 2025-04-28 14:28:39 -0700 | [diff] [blame] | 679 | window.addEventListener( |
| 680 | "multiple-choice-selected", |
| 681 | this._handleMutlipleChoiceSelected, |
| 682 | ); |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 683 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 684 | // register event listeners |
| 685 | this.dataManager.addEventListener( |
| 686 | "dataChanged", |
| Philip Zeyliger | 72682df | 2025-04-23 13:09:46 -0700 | [diff] [blame] | 687 | this.handleDataChanged.bind(this), |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 688 | ); |
| 689 | this.dataManager.addEventListener( |
| 690 | "connectionStatusChanged", |
| Philip Zeyliger | 72682df | 2025-04-23 13:09:46 -0700 | [diff] [blame] | 691 | this.handleConnectionStatusChanged.bind(this), |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 692 | ); |
| 693 | |
| Philip Zeyliger | 9b999b0 | 2025-04-25 16:31:50 +0000 | [diff] [blame] | 694 | // Set initial document title |
| 695 | this.updateDocumentTitle(); |
| 696 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 697 | // Initialize the data manager |
| 698 | this.dataManager.initialize(); |
| Autoformatter | cf57096 | 2025-04-30 17:27:39 +0000 | [diff] [blame] | 699 | |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 700 | // Process existing messages for commit info |
| 701 | if (this.messages && this.messages.length > 0) { |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 702 | // Update last commit info via container status component |
| 703 | setTimeout(() => { |
| 704 | if (this.containerStatusElement) { |
| 705 | this.containerStatusElement.updateLastCommitInfo(this.messages); |
| 706 | } |
| 707 | }, 100); |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 708 | } |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 709 | |
| 710 | // Check if todo panel should be visible on initial load |
| 711 | this.checkTodoPanelVisibility(); |
| 712 | |
| 713 | // Set up ResizeObserver for chat input to update todo panel height |
| 714 | this.setupChatInputObserver(); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | // See https://lit.dev/docs/components/lifecycle/ |
| 718 | disconnectedCallback() { |
| 719 | super.disconnectedCallback(); |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 720 | window.removeEventListener("popstate", this._handlePopState); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 721 | |
| 722 | // Remove event listeners |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 723 | window.removeEventListener("view-mode-select", this._handleViewModeSelect); |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 724 | window.removeEventListener("show-commit-diff", this._handleShowCommitDiff); |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 725 | window.removeEventListener("focus", this._handleWindowFocus); |
| 726 | window.removeEventListener("blur", this._handleWindowBlur); |
| Sean McCullough | 485afc6 | 2025-04-28 14:28:39 -0700 | [diff] [blame] | 727 | window.removeEventListener( |
| 728 | "multiple-choice-selected", |
| 729 | this._handleMutlipleChoiceSelected, |
| 730 | ); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 731 | |
| 732 | // unregister data manager event listeners |
| 733 | this.dataManager.removeEventListener( |
| 734 | "dataChanged", |
| Philip Zeyliger | 72682df | 2025-04-23 13:09:46 -0700 | [diff] [blame] | 735 | this.handleDataChanged.bind(this), |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 736 | ); |
| 737 | this.dataManager.removeEventListener( |
| 738 | "connectionStatusChanged", |
| Philip Zeyliger | 72682df | 2025-04-23 13:09:46 -0700 | [diff] [blame] | 739 | this.handleConnectionStatusChanged.bind(this), |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 740 | ); |
| 741 | |
| 742 | // Disconnect mutation observer if it exists |
| 743 | if (this.mutationObserver) { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 744 | this.mutationObserver.disconnect(); |
| 745 | this.mutationObserver = null; |
| 746 | } |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 747 | |
| 748 | // Disconnect chat input resize observer if it exists |
| 749 | if (this.chatInputResizeObserver) { |
| 750 | this.chatInputResizeObserver.disconnect(); |
| 751 | this.chatInputResizeObserver = null; |
| 752 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 753 | } |
| 754 | |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 755 | updateUrlForViewMode(mode: ViewMode): void { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 756 | // Get the current URL without search parameters |
| 757 | const url = new URL(window.location.href); |
| 758 | |
| 759 | // Clear existing parameters |
| 760 | url.search = ""; |
| 761 | |
| 762 | // Only add view parameter if not in default chat view |
| 763 | if (mode !== "chat") { |
| 764 | url.searchParams.set("view", mode); |
| Philip Zeyliger | 00bcaef | 2025-05-30 04:21:15 +0000 | [diff] [blame] | 765 | const diff2View = this.shadowRoot?.querySelector( |
| 766 | "sketch-diff2-view", |
| 767 | ) as SketchDiff2View; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 768 | |
| Philip Zeyliger | 00bcaef | 2025-05-30 04:21:15 +0000 | [diff] [blame] | 769 | // If in diff2 view and there's a commit hash, include that too |
| 770 | if (mode === "diff2" && diff2View?.commit) { |
| 771 | url.searchParams.set("commit", diff2View.commit); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 772 | } |
| 773 | } |
| 774 | |
| 775 | // Update the browser history without reloading the page |
| 776 | window.history.pushState({ mode }, "", url.toString()); |
| 777 | } |
| 778 | |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 779 | private _handlePopState(event: PopStateEvent) { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 780 | if (event.state && event.state.mode) { |
| 781 | this.toggleViewMode(event.state.mode, false); |
| 782 | } else { |
| 783 | this.toggleViewMode("chat", false); |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | /** |
| 788 | * Handle view mode selection event |
| 789 | */ |
| 790 | private _handleViewModeSelect(event: CustomEvent) { |
| Philip Zeyliger | 00bcaef | 2025-05-30 04:21:15 +0000 | [diff] [blame] | 791 | const mode = event.detail.mode as "chat" | "diff2" | "terminal"; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 792 | this.toggleViewMode(mode, true); |
| 793 | } |
| 794 | |
| 795 | /** |
| 796 | * Handle show commit diff event |
| 797 | */ |
| 798 | private _handleShowCommitDiff(event: CustomEvent) { |
| 799 | const { commitHash } = event.detail; |
| 800 | if (commitHash) { |
| 801 | this.showCommitDiff(commitHash); |
| 802 | } |
| 803 | } |
| 804 | |
| Sean McCullough | 485afc6 | 2025-04-28 14:28:39 -0700 | [diff] [blame] | 805 | private _handleMultipleChoice(event: CustomEvent) { |
| 806 | window.console.log("_handleMultipleChoice", event); |
| 807 | this._sendChat; |
| 808 | } |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 809 | |
| 810 | private _handleDiffComment(event: CustomEvent) { |
| 811 | // Empty stub required by the event binding in the template |
| 812 | // Actual handling occurs at global level in sketch-chat-input component |
| 813 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 814 | /** |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 815 | * Listen for commit diff event |
| 816 | * @param commitHash The commit hash to show diff for |
| 817 | */ |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 818 | private showCommitDiff(commitHash: string): void { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 819 | // Store the commit hash |
| 820 | this.currentCommitHash = commitHash; |
| 821 | |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 822 | this.toggleViewMode("diff2", true); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 823 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 824 | this.updateComplete.then(() => { |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 825 | const diff2View = this.shadowRoot?.querySelector("sketch-diff2-view"); |
| 826 | if (diff2View) { |
| 827 | (diff2View as SketchDiff2View).refreshDiffView(); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 828 | } |
| 829 | }); |
| 830 | } |
| 831 | |
| 832 | /** |
| Philip Zeyliger | 00bcaef | 2025-05-30 04:21:15 +0000 | [diff] [blame] | 833 | * Toggle between different view modes: chat, diff2, terminal |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 834 | */ |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 835 | private toggleViewMode(mode: ViewMode, updateHistory: boolean): void { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 836 | // Don't do anything if the mode is already active |
| 837 | if (this.viewMode === mode) return; |
| 838 | |
| banksean | 65ff909 | 2025-06-19 00:36:25 +0000 | [diff] [blame] | 839 | // Store scroll position if we're leaving the chat view |
| 840 | if (this.viewMode === "chat" && this.scrollContainerRef.value) { |
| 841 | // Only store scroll position if we actually have meaningful content |
| 842 | const scrollTop = this.scrollContainerRef.value.scrollTop; |
| 843 | const scrollHeight = this.scrollContainerRef.value.scrollHeight; |
| 844 | const clientHeight = this.scrollContainerRef.value.clientHeight; |
| 845 | |
| 846 | // Store position only if we have scrollable content and have actually scrolled |
| 847 | if (scrollHeight > clientHeight && scrollTop > 0) { |
| 848 | this._chatScrollPosition = scrollTop; |
| 849 | } |
| 850 | } |
| 851 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 852 | // Update the view mode |
| 853 | this.viewMode = mode; |
| 854 | |
| 855 | if (updateHistory) { |
| 856 | // Update URL with the current view mode |
| 857 | this.updateUrlForViewMode(mode); |
| 858 | } |
| 859 | |
| 860 | // Wait for DOM update to complete |
| 861 | this.updateComplete.then(() => { |
| 862 | // Update active view |
| Pokey Rule | 46fff97 | 2025-04-25 14:57:44 +0100 | [diff] [blame] | 863 | const viewContainerInner = this.shadowRoot?.querySelector( |
| 864 | "#view-container-inner", |
| 865 | ); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 866 | const chatView = this.shadowRoot?.querySelector(".chat-view"); |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 867 | const diff2View = this.shadowRoot?.querySelector(".diff2-view"); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 868 | const terminalView = this.shadowRoot?.querySelector(".terminal-view"); |
| 869 | |
| 870 | // Remove active class from all views |
| 871 | chatView?.classList.remove("view-active"); |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 872 | diff2View?.classList.remove("view-active"); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 873 | terminalView?.classList.remove("view-active"); |
| 874 | |
| Philip Zeyliger | 00bcaef | 2025-05-30 04:21:15 +0000 | [diff] [blame] | 875 | // Add/remove diff2-active class on view container |
| 876 | if (mode === "diff2") { |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 877 | viewContainerInner?.classList.add("diff2-active"); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 878 | } else { |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 879 | viewContainerInner?.classList.remove("diff2-active"); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | // Add active class to the selected view |
| 883 | switch (mode) { |
| 884 | case "chat": |
| 885 | chatView?.classList.add("view-active"); |
| banksean | 65ff909 | 2025-06-19 00:36:25 +0000 | [diff] [blame] | 886 | // Restore scroll position if we're switching back to chat |
| 887 | if (this.scrollContainerRef.value && this._chatScrollPosition > 0) { |
| 888 | // Use requestAnimationFrame to ensure DOM is ready |
| 889 | requestAnimationFrame(() => { |
| 890 | if (this.scrollContainerRef.value) { |
| 891 | // Double-check that we're still in chat mode and the container is available |
| 892 | if ( |
| 893 | this.viewMode === "chat" && |
| 894 | this.scrollContainerRef.value.isConnected |
| 895 | ) { |
| 896 | this.scrollContainerRef.value.scrollTop = |
| 897 | this._chatScrollPosition; |
| 898 | } |
| 899 | } |
| 900 | }); |
| 901 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 902 | break; |
| Autoformatter | 8c46362 | 2025-05-16 21:54:17 +0000 | [diff] [blame] | 903 | |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 904 | case "diff2": |
| 905 | diff2View?.classList.add("view-active"); |
| 906 | // Refresh git/recentlog when Monaco diff view is opened |
| 907 | // 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] | 908 | const diff2ViewComp = |
| 909 | this.shadowRoot?.querySelector("sketch-diff2-view"); |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 910 | if (diff2ViewComp) { |
| 911 | (diff2ViewComp as SketchDiff2View).refreshDiffView(); |
| 912 | } |
| 913 | break; |
| Philip Zeyliger | 2d4c48f | 2025-05-02 23:35:03 +0000 | [diff] [blame] | 914 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 915 | case "terminal": |
| 916 | terminalView?.classList.add("view-active"); |
| 917 | break; |
| 918 | } |
| 919 | |
| 920 | // Update view mode buttons |
| 921 | const viewModeSelect = this.shadowRoot?.querySelector( |
| Philip Zeyliger | 72682df | 2025-04-23 13:09:46 -0700 | [diff] [blame] | 922 | "sketch-view-mode-select", |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 923 | ); |
| 924 | if (viewModeSelect) { |
| 925 | const event = new CustomEvent("update-active-mode", { |
| 926 | detail: { mode }, |
| 927 | bubbles: true, |
| 928 | composed: true, |
| 929 | }); |
| 930 | viewModeSelect.dispatchEvent(event); |
| 931 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 932 | }); |
| 933 | } |
| 934 | |
| Philip Zeyliger | 9b999b0 | 2025-04-25 16:31:50 +0000 | [diff] [blame] | 935 | /** |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 936 | * Updates the document title based on current slug and connection status |
| Philip Zeyliger | 9b999b0 | 2025-04-25 16:31:50 +0000 | [diff] [blame] | 937 | */ |
| 938 | private updateDocumentTitle(): void { |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 939 | let docTitle = `sk: ${this.slug || "untitled"}`; |
| Philip Zeyliger | 9b999b0 | 2025-04-25 16:31:50 +0000 | [diff] [blame] | 940 | |
| 941 | // Add red circle emoji if disconnected |
| 942 | if (this.connectionStatus === "disconnected") { |
| 943 | docTitle += " 🔴"; |
| 944 | } |
| 945 | |
| 946 | document.title = docTitle; |
| 947 | } |
| 948 | |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 949 | // Check and request notification permission if needed |
| 950 | private async checkNotificationPermission(): Promise<boolean> { |
| 951 | // Check if the Notification API is supported |
| 952 | if (!("Notification" in window)) { |
| 953 | console.log("This browser does not support notifications"); |
| 954 | return false; |
| 955 | } |
| 956 | |
| 957 | // Check if permission is already granted |
| 958 | if (Notification.permission === "granted") { |
| 959 | return true; |
| 960 | } |
| 961 | |
| 962 | // If permission is not denied, request it |
| 963 | if (Notification.permission !== "denied") { |
| 964 | const permission = await Notification.requestPermission(); |
| 965 | return permission === "granted"; |
| 966 | } |
| 967 | |
| 968 | return false; |
| 969 | } |
| 970 | |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 971 | // Handle notifications toggle click |
| 972 | private _handleNotificationsToggle(): void { |
| 973 | this.notificationsEnabled = !this.notificationsEnabled; |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 974 | |
| 975 | // If enabling notifications, check permissions |
| 976 | if (this.notificationsEnabled) { |
| 977 | this.checkNotificationPermission(); |
| 978 | } |
| 979 | |
| 980 | // Save preference to localStorage |
| 981 | try { |
| 982 | localStorage.setItem( |
| 983 | "sketch-notifications-enabled", |
| 984 | String(this.notificationsEnabled), |
| 985 | ); |
| 986 | } catch (error) { |
| 987 | console.error("Error saving notification preference:", error); |
| 988 | } |
| 989 | } |
| 990 | |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 991 | // Handle window focus event |
| 992 | private _handleWindowFocus(): void { |
| 993 | this._windowFocused = true; |
| 994 | } |
| 995 | |
| 996 | // Handle window blur event |
| 997 | private _handleWindowBlur(): void { |
| 998 | this._windowFocused = false; |
| 999 | } |
| 1000 | |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 1001 | // Show notification for message with EndOfTurn=true |
| 1002 | private async showEndOfTurnNotification( |
| 1003 | message: AgentMessage, |
| 1004 | ): Promise<void> { |
| 1005 | // Don't show notifications if they're disabled |
| 1006 | if (!this.notificationsEnabled) return; |
| 1007 | |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 1008 | // Don't show notifications if the window is focused |
| 1009 | if (this._windowFocused) return; |
| 1010 | |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 1011 | // Check if we have permission to show notifications |
| 1012 | const hasPermission = await this.checkNotificationPermission(); |
| 1013 | if (!hasPermission) return; |
| 1014 | |
| Philip Zeyliger | 3201133 | 2025-04-30 20:59:40 +0000 | [diff] [blame] | 1015 | // Only show notifications for agent messages with end_of_turn=true and no parent_conversation_id |
| 1016 | if ( |
| 1017 | message.type !== "agent" || |
| 1018 | !message.end_of_turn || |
| 1019 | message.parent_conversation_id |
| 1020 | ) |
| 1021 | return; |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 1022 | |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 1023 | // Create a title that includes the sketch slug |
| 1024 | const notificationTitle = `Sketch: ${this.slug || "untitled"}`; |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 1025 | |
| 1026 | // Extract the beginning of the message content (first 100 chars) |
| 1027 | const messagePreview = message.content |
| 1028 | ? message.content.substring(0, 100) + |
| 1029 | (message.content.length > 100 ? "..." : "") |
| 1030 | : "Agent has completed its turn"; |
| 1031 | |
| 1032 | // Create and show the notification |
| 1033 | try { |
| 1034 | new Notification(notificationTitle, { |
| 1035 | body: messagePreview, |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 1036 | icon: "https://sketch.dev/favicon.ico", // Use sketch.dev favicon for notification |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 1037 | }); |
| 1038 | } catch (error) { |
| 1039 | console.error("Error showing notification:", error); |
| 1040 | } |
| 1041 | } |
| 1042 | |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 1043 | // Check if todo panel should be visible based on latest todo content from messages or state |
| 1044 | private checkTodoPanelVisibility(): void { |
| 1045 | // Find the latest todo content from messages first |
| 1046 | let latestTodoContent = ""; |
| 1047 | for (let i = this.messages.length - 1; i >= 0; i--) { |
| 1048 | const message = this.messages[i]; |
| 1049 | if (message.todo_content !== undefined) { |
| 1050 | latestTodoContent = message.todo_content || ""; |
| 1051 | break; |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | // If no todo content found in messages, check the current state |
| 1056 | if (latestTodoContent === "" && this.containerState?.todo_content) { |
| 1057 | latestTodoContent = this.containerState.todo_content; |
| 1058 | } |
| 1059 | |
| 1060 | // Parse the todo data to check if there are any actual todos |
| 1061 | let hasTodos = false; |
| 1062 | if (latestTodoContent.trim()) { |
| 1063 | try { |
| 1064 | const todoData = JSON.parse(latestTodoContent); |
| 1065 | hasTodos = todoData.items && todoData.items.length > 0; |
| 1066 | } catch (error) { |
| 1067 | // Invalid JSON, treat as no todos |
| 1068 | hasTodos = false; |
| 1069 | } |
| 1070 | } |
| 1071 | |
| 1072 | this._todoPanelVisible = hasTodos; |
| 1073 | |
| 1074 | // Update todo panel content if visible |
| 1075 | if (hasTodos) { |
| 1076 | const todoPanel = this.shadowRoot?.querySelector( |
| 1077 | "sketch-todo-panel", |
| 1078 | ) as any; |
| 1079 | if (todoPanel && todoPanel.updateTodoContent) { |
| 1080 | todoPanel.updateTodoContent(latestTodoContent); |
| 1081 | } |
| 1082 | } |
| 1083 | } |
| 1084 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1085 | private handleDataChanged(eventData: { |
| 1086 | state: State; |
| Sean McCullough | d9f1337 | 2025-04-21 15:08:49 -0700 | [diff] [blame] | 1087 | newMessages: AgentMessage[]; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1088 | }): void { |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 1089 | const { state, newMessages } = eventData; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1090 | |
| 1091 | // Update state if we received it |
| 1092 | if (state) { |
| Josh Bleecher Snyder | e81233f | 2025-04-30 04:05:41 +0000 | [diff] [blame] | 1093 | // 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] | 1094 | if ( |
| 1095 | state.outstanding_llm_calls === 0 && |
| 1096 | state.outstanding_tool_calls.length === 0 |
| 1097 | ) { |
| Josh Bleecher Snyder | e81233f | 2025-04-30 04:05:41 +0000 | [diff] [blame] | 1098 | // Force reset containerState calls when nothing is reported as in progress |
| 1099 | state.outstanding_llm_calls = 0; |
| 1100 | state.outstanding_tool_calls = []; |
| 1101 | } |
| Autoformatter | f830c9d | 2025-04-30 18:16:01 +0000 | [diff] [blame] | 1102 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1103 | this.containerState = state; |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 1104 | this.slug = state.slug || ""; |
| Philip Zeyliger | 9b999b0 | 2025-04-25 16:31:50 +0000 | [diff] [blame] | 1105 | |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 1106 | // Update document title when sketch slug changes |
| Philip Zeyliger | 9b999b0 | 2025-04-25 16:31:50 +0000 | [diff] [blame] | 1107 | this.updateDocumentTitle(); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1108 | } |
| 1109 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1110 | // Update messages |
| banksean | 65ff909 | 2025-06-19 00:36:25 +0000 | [diff] [blame] | 1111 | const oldMessageCount = this.messages.length; |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 1112 | this.messages = aggregateAgentMessages(this.messages, newMessages); |
| Autoformatter | cf57096 | 2025-04-30 17:27:39 +0000 | [diff] [blame] | 1113 | |
| banksean | 65ff909 | 2025-06-19 00:36:25 +0000 | [diff] [blame] | 1114 | // If new messages were added and we're in chat view, reset stored scroll position |
| 1115 | // so the timeline can auto-scroll to bottom for new content |
| 1116 | if (this.messages.length > oldMessageCount && this.viewMode === "chat") { |
| 1117 | // Only reset if we were near the bottom (indicating user wants to follow new messages) |
| 1118 | if (this.scrollContainerRef.value) { |
| 1119 | const scrollTop = this.scrollContainerRef.value.scrollTop; |
| 1120 | const scrollHeight = this.scrollContainerRef.value.scrollHeight; |
| 1121 | const clientHeight = this.scrollContainerRef.value.clientHeight; |
| 1122 | const isNearBottom = scrollTop + clientHeight >= scrollHeight - 50; // 50px tolerance |
| 1123 | |
| 1124 | if (isNearBottom) { |
| 1125 | this._chatScrollPosition = 0; // Reset stored position to allow auto-scroll |
| 1126 | } |
| 1127 | } |
| 1128 | } |
| 1129 | |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 1130 | // Process new messages to find commit messages |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 1131 | // Update last commit info via container status component |
| 1132 | if (this.containerStatusElement) { |
| 1133 | this.containerStatusElement.updateLastCommitInfo(newMessages); |
| 1134 | } |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 1135 | |
| 1136 | // Check for agent messages with end_of_turn=true and show notifications |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 1137 | if (newMessages && newMessages.length > 0) { |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 1138 | for (const message of newMessages) { |
| Philip Zeyliger | 3201133 | 2025-04-30 20:59:40 +0000 | [diff] [blame] | 1139 | if ( |
| 1140 | message.type === "agent" && |
| 1141 | message.end_of_turn && |
| 1142 | !message.parent_conversation_id |
| 1143 | ) { |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 1144 | this.showEndOfTurnNotification(message); |
| 1145 | break; // Only show one notification per batch of messages |
| 1146 | } |
| 1147 | } |
| 1148 | } |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 1149 | |
| 1150 | // Check if todo panel should be visible after agent loop iteration |
| 1151 | this.checkTodoPanelVisibility(); |
| 1152 | |
| 1153 | // Ensure chat input observer is set up when new data comes in |
| 1154 | if (!this.chatInputResizeObserver) { |
| 1155 | this.setupChatInputObserver(); |
| 1156 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | private handleConnectionStatusChanged( |
| 1160 | status: ConnectionStatus, |
| Philip Zeyliger | 72682df | 2025-04-23 13:09:46 -0700 | [diff] [blame] | 1161 | errorMessage?: string, |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1162 | ): void { |
| 1163 | this.connectionStatus = status; |
| 1164 | this.connectionErrorMessage = errorMessage || ""; |
| Philip Zeyliger | 9b999b0 | 2025-04-25 16:31:50 +0000 | [diff] [blame] | 1165 | |
| 1166 | // Update document title when connection status changes |
| 1167 | this.updateDocumentTitle(); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1168 | } |
| 1169 | |
| Sean McCullough | d3906e2 | 2025-04-29 17:32:14 +0000 | [diff] [blame] | 1170 | private async _handleStopClick(): Promise<void> { |
| 1171 | try { |
| 1172 | const response = await fetch("cancel", { |
| 1173 | method: "POST", |
| 1174 | headers: { |
| 1175 | "Content-Type": "application/json", |
| 1176 | }, |
| 1177 | body: JSON.stringify({ reason: "user requested cancellation" }), |
| 1178 | }); |
| 1179 | |
| 1180 | if (!response.ok) { |
| 1181 | const errorData = await response.text(); |
| 1182 | throw new Error( |
| 1183 | `Failed to stop operation: ${response.status} - ${errorData}`, |
| 1184 | ); |
| 1185 | } |
| 1186 | |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 1187 | // Stop request sent |
| Sean McCullough | d3906e2 | 2025-04-29 17:32:14 +0000 | [diff] [blame] | 1188 | } catch (error) { |
| 1189 | console.error("Error stopping operation:", error); |
| Sean McCullough | d3906e2 | 2025-04-29 17:32:14 +0000 | [diff] [blame] | 1190 | } |
| 1191 | } |
| 1192 | |
| Pokey Rule | 397871d | 2025-05-19 15:02:45 +0100 | [diff] [blame] | 1193 | private async _handleEndClick(event?: Event): Promise<void> { |
| 1194 | if (event) { |
| 1195 | event.preventDefault(); |
| 1196 | event.stopPropagation(); |
| 1197 | } |
| Philip Zeyliger | b573940 | 2025-06-02 07:04:34 -0700 | [diff] [blame] | 1198 | |
| Philip Zeyliger | 1609893 | 2025-06-04 11:02:55 -0700 | [diff] [blame] | 1199 | // Show confirmation dialog |
| 1200 | const confirmed = window.confirm( |
| 1201 | "Ending the session will shut down the underlying container. Are you sure?", |
| 1202 | ); |
| 1203 | if (!confirmed) return; |
| Pokey Rule | 397871d | 2025-05-19 15:02:45 +0100 | [diff] [blame] | 1204 | |
| 1205 | try { |
| 1206 | const response = await fetch("end", { |
| 1207 | method: "POST", |
| 1208 | headers: { |
| 1209 | "Content-Type": "application/json", |
| 1210 | }, |
| Philip Zeyliger | 1609893 | 2025-06-04 11:02:55 -0700 | [diff] [blame] | 1211 | body: JSON.stringify({ reason: "user requested end of session" }), |
| Pokey Rule | 397871d | 2025-05-19 15:02:45 +0100 | [diff] [blame] | 1212 | }); |
| 1213 | |
| 1214 | if (!response.ok) { |
| 1215 | const errorData = await response.text(); |
| 1216 | throw new Error( |
| 1217 | `Failed to end session: ${response.status} - ${errorData}`, |
| 1218 | ); |
| 1219 | } |
| 1220 | |
| 1221 | // After successful response, redirect to messages view |
| 1222 | // Extract the session ID from the URL |
| 1223 | const currentUrl = window.location.href; |
| 1224 | // The URL pattern should be like https://sketch.dev/s/cs71-8qa6-1124-aw79/ |
| 1225 | const urlParts = currentUrl.split("/"); |
| 1226 | let sessionId = ""; |
| 1227 | |
| 1228 | // Find the session ID in the URL (should be after /s/) |
| 1229 | for (let i = 0; i < urlParts.length; i++) { |
| 1230 | if (urlParts[i] === "s" && i + 1 < urlParts.length) { |
| 1231 | sessionId = urlParts[i + 1]; |
| 1232 | break; |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | if (sessionId) { |
| 1237 | // Create the messages URL |
| 1238 | const messagesUrl = `/messages/${sessionId}`; |
| 1239 | // Redirect to messages view |
| 1240 | window.location.href = messagesUrl; |
| 1241 | } |
| 1242 | |
| 1243 | // End request sent - connection will be closed by server |
| 1244 | } catch (error) { |
| 1245 | console.error("Error ending session:", error); |
| 1246 | } |
| 1247 | } |
| 1248 | |
| Sean McCullough | 485afc6 | 2025-04-28 14:28:39 -0700 | [diff] [blame] | 1249 | async _handleMutlipleChoiceSelected(e: CustomEvent) { |
| 1250 | const chatInput = this.shadowRoot?.querySelector( |
| 1251 | "sketch-chat-input", |
| 1252 | ) as SketchChatInput; |
| 1253 | if (chatInput) { |
| Josh Bleecher Snyder | 6cad861 | 2025-05-30 19:25:39 +0000 | [diff] [blame] | 1254 | if (chatInput.content && chatInput.content.trim() !== "") { |
| 1255 | chatInput.content += "\n\n"; |
| 1256 | } |
| 1257 | chatInput.content += e.detail.responseText; |
| Sean McCullough | 485afc6 | 2025-04-28 14:28:39 -0700 | [diff] [blame] | 1258 | chatInput.focus(); |
| Josh Bleecher Snyder | 6cad861 | 2025-05-30 19:25:39 +0000 | [diff] [blame] | 1259 | // Adjust textarea height to accommodate new content |
| 1260 | requestAnimationFrame(() => { |
| 1261 | if (chatInput.adjustChatSpacing) { |
| 1262 | chatInput.adjustChatSpacing(); |
| 1263 | } |
| 1264 | }); |
| Sean McCullough | 485afc6 | 2025-04-28 14:28:39 -0700 | [diff] [blame] | 1265 | } |
| 1266 | } |
| 1267 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1268 | async _sendChat(e: CustomEvent) { |
| 1269 | console.log("app shell: _sendChat", e); |
| Sean McCullough | 485afc6 | 2025-04-28 14:28:39 -0700 | [diff] [blame] | 1270 | e.preventDefault(); |
| 1271 | e.stopPropagation(); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1272 | const message = e.detail.message?.trim(); |
| 1273 | if (message == "") { |
| 1274 | return; |
| 1275 | } |
| 1276 | try { |
| Josh Bleecher Snyder | 98b64d1 | 2025-05-12 19:42:43 +0000 | [diff] [blame] | 1277 | // Always switch to chat view when sending a message so user can see processing |
| 1278 | if (this.viewMode !== "chat") { |
| 1279 | this.toggleViewMode("chat", true); |
| 1280 | } |
| Autoformatter | 5c7f957 | 2025-05-13 01:17:31 +0000 | [diff] [blame] | 1281 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1282 | // Send the message to the server |
| 1283 | const response = await fetch("chat", { |
| 1284 | method: "POST", |
| 1285 | headers: { |
| 1286 | "Content-Type": "application/json", |
| 1287 | }, |
| 1288 | body: JSON.stringify({ message }), |
| 1289 | }); |
| 1290 | |
| 1291 | if (!response.ok) { |
| 1292 | const errorData = await response.text(); |
| 1293 | throw new Error(`Server error: ${response.status} - ${errorData}`); |
| 1294 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1295 | } catch (error) { |
| 1296 | console.error("Error sending chat message:", error); |
| 1297 | const statusText = document.getElementById("statusText"); |
| 1298 | if (statusText) { |
| 1299 | statusText.textContent = "Error sending message"; |
| 1300 | } |
| 1301 | } |
| 1302 | } |
| 1303 | |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 1304 | private scrollContainerRef = createRef<HTMLElement>(); |
| 1305 | |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 1306 | /** |
| 1307 | * Set up ResizeObserver to monitor chat input height changes |
| 1308 | */ |
| 1309 | private setupChatInputObserver(): void { |
| 1310 | // Wait for DOM to be ready |
| 1311 | this.updateComplete.then(() => { |
| 1312 | const chatInputElement = this.shadowRoot?.querySelector("#chat-input"); |
| 1313 | if (chatInputElement && !this.chatInputResizeObserver) { |
| 1314 | this.chatInputResizeObserver = new ResizeObserver((entries) => { |
| 1315 | for (const entry of entries) { |
| 1316 | this.updateTodoPanelHeight(entry.contentRect.height); |
| 1317 | } |
| 1318 | }); |
| 1319 | |
| 1320 | this.chatInputResizeObserver.observe(chatInputElement); |
| 1321 | |
| 1322 | // Initial height calculation |
| 1323 | const rect = chatInputElement.getBoundingClientRect(); |
| 1324 | this.updateTodoPanelHeight(rect.height); |
| 1325 | } |
| 1326 | }); |
| 1327 | } |
| 1328 | |
| 1329 | /** |
| 1330 | * Update the CSS custom property that controls todo panel bottom position |
| 1331 | */ |
| 1332 | private updateTodoPanelHeight(chatInputHeight: number): void { |
| 1333 | // Add some padding (20px) between todo panel and chat input |
| 1334 | const bottomOffset = chatInputHeight; |
| 1335 | |
| 1336 | // Update the CSS custom property on the host element |
| 1337 | this.style.setProperty("--chat-input-height", `${bottomOffset}px`); |
| 1338 | } |
| 1339 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1340 | render() { |
| 1341 | return html` |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 1342 | <div id="top-banner"> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1343 | <div class="title-container"> |
| Philip Zeyliger | 0113be5 | 2025-06-07 23:53:41 +0000 | [diff] [blame] | 1344 | <h1 class="banner-title"> |
| 1345 | ${this.containerState?.skaband_addr |
| 1346 | ? html`<a |
| 1347 | href="${this.containerState.skaband_addr}" |
| 1348 | target="_blank" |
| 1349 | rel="noopener noreferrer" |
| 1350 | > |
| 1351 | <img |
| 1352 | src="${this.containerState.skaband_addr}/sketch.dev.png" |
| 1353 | alt="sketch" |
| 1354 | /> |
| 1355 | sketch |
| 1356 | </a>` |
| 1357 | : html`sketch`} |
| 1358 | </h1> |
| Josh Bleecher Snyder | 19969a9 | 2025-06-05 14:34:02 -0700 | [diff] [blame] | 1359 | <h2 class="slug-title">${this.slug}</h2> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1360 | </div> |
| 1361 | |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 1362 | <!-- Container status info moved above tabs --> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1363 | <sketch-container-status |
| 1364 | .state=${this.containerState} |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 1365 | id="container-status" |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1366 | ></sketch-container-status> |
| Autoformatter | cf57096 | 2025-04-30 17:27:39 +0000 | [diff] [blame] | 1367 | |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 1368 | <!-- Last Commit section moved to sketch-container-status --> |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 1369 | |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 1370 | <!-- Views section with tabs --> |
| Philip Zeyliger | 64f6046 | 2025-06-16 13:57:10 -0700 | [diff] [blame] | 1371 | <sketch-view-mode-select |
| 1372 | .diffLinesAdded=${this.containerState?.diff_lines_added || 0} |
| 1373 | .diffLinesRemoved=${this.containerState?.diff_lines_removed || 0} |
| 1374 | ></sketch-view-mode-select> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1375 | |
| 1376 | <div class="refresh-control"> |
| Sean McCullough | d3906e2 | 2025-04-29 17:32:14 +0000 | [diff] [blame] | 1377 | <button |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 1378 | id="stopButton" |
| 1379 | class="stop-button" |
| 1380 | ?disabled=${(this.containerState?.outstanding_llm_calls || 0) === |
| 1381 | 0 && |
| 1382 | (this.containerState?.outstanding_tool_calls || []).length === 0} |
| 1383 | > |
| 1384 | <svg |
| 1385 | class="button-icon" |
| 1386 | xmlns="http://www.w3.org/2000/svg" |
| 1387 | viewBox="0 0 24 24" |
| 1388 | fill="none" |
| 1389 | stroke="currentColor" |
| 1390 | stroke-width="2" |
| 1391 | stroke-linecap="round" |
| 1392 | stroke-linejoin="round" |
| 1393 | > |
| 1394 | <rect x="6" y="6" width="12" height="12" /> |
| 1395 | </svg> |
| 1396 | <span class="button-text">Stop</span> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1397 | </button> |
| Pokey Rule | 397871d | 2025-05-19 15:02:45 +0100 | [diff] [blame] | 1398 | <button |
| 1399 | id="endButton" |
| 1400 | class="end-button" |
| 1401 | @click=${this._handleEndClick} |
| 1402 | > |
| 1403 | <svg |
| 1404 | class="button-icon" |
| 1405 | xmlns="http://www.w3.org/2000/svg" |
| 1406 | viewBox="0 0 24 24" |
| 1407 | fill="none" |
| 1408 | stroke="currentColor" |
| 1409 | stroke-width="2" |
| 1410 | stroke-linecap="round" |
| 1411 | stroke-linejoin="round" |
| 1412 | > |
| 1413 | <path d="M18 6L6 18" /> |
| 1414 | <path d="M6 6l12 12" /> |
| 1415 | </svg> |
| 1416 | <span class="button-text">End</span> |
| 1417 | </button> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1418 | |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 1419 | <div |
| 1420 | class="notifications-toggle" |
| 1421 | @click=${this._handleNotificationsToggle} |
| 1422 | title="${this.notificationsEnabled |
| 1423 | ? "Disable" |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 1424 | : "Enable"} notifications when the agent completes its turn" |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 1425 | > |
| 1426 | <div |
| 1427 | class="bell-icon ${!this.notificationsEnabled |
| 1428 | ? "bell-disabled" |
| 1429 | : ""}" |
| 1430 | > |
| 1431 | <!-- Bell SVG icon --> |
| 1432 | <svg |
| 1433 | xmlns="http://www.w3.org/2000/svg" |
| 1434 | width="16" |
| 1435 | height="16" |
| 1436 | fill="currentColor" |
| 1437 | viewBox="0 0 16 16" |
| 1438 | > |
| 1439 | <path |
| 1440 | 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" |
| 1441 | /> |
| 1442 | </svg> |
| 1443 | </div> |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 1444 | </div> |
| 1445 | |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 1446 | <sketch-call-status |
| Sean McCullough | d9d4581 | 2025-04-30 16:53:41 -0700 | [diff] [blame] | 1447 | .agentState=${this.containerState?.agent_state} |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 1448 | .llmCalls=${this.containerState?.outstanding_llm_calls || 0} |
| 1449 | .toolCalls=${this.containerState?.outstanding_tool_calls || []} |
| Philip Zeyliger | 7231839 | 2025-05-14 02:56:07 +0000 | [diff] [blame] | 1450 | .isIdle=${this.messages.length > 0 |
| 1451 | ? this.messages[this.messages.length - 1]?.end_of_turn && |
| 1452 | !this.messages[this.messages.length - 1]?.parent_conversation_id |
| 1453 | : true} |
| Philip Zeyliger | 5e35702 | 2025-05-16 04:50:34 +0000 | [diff] [blame] | 1454 | .isDisconnected=${this.connectionStatus === "disconnected"} |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 1455 | ></sketch-call-status> |
| Philip Zeyliger | 25f6ff1 | 2025-05-02 04:24:10 +0000 | [diff] [blame] | 1456 | |
| 1457 | <sketch-network-status |
| 1458 | connection=${this.connectionStatus} |
| 1459 | error=${this.connectionErrorMessage} |
| 1460 | ></sketch-network-status> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1461 | </div> |
| 1462 | </div> |
| 1463 | |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 1464 | <div id="view-container" ${ref(this.scrollContainerRef)}> |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 1465 | <div |
| 1466 | id="view-container-inner" |
| 1467 | class="${this._todoPanelVisible && this.viewMode === "chat" |
| 1468 | ? "with-todo-panel" |
| 1469 | : ""}" |
| 1470 | > |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 1471 | <div |
| 1472 | class="chat-view ${this.viewMode === "chat" ? "view-active" : ""}" |
| 1473 | > |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 1474 | <div |
| 1475 | class="chat-timeline-container ${this._todoPanelVisible && |
| 1476 | this.viewMode === "chat" |
| 1477 | ? "with-todo-panel" |
| 1478 | : ""}" |
| 1479 | > |
| 1480 | <sketch-timeline |
| 1481 | .messages=${this.messages} |
| 1482 | .scrollContainer=${this.scrollContainerRef} |
| 1483 | .agentState=${this.containerState?.agent_state} |
| 1484 | .llmCalls=${this.containerState?.outstanding_llm_calls || 0} |
| 1485 | .toolCalls=${this.containerState?.outstanding_tool_calls || []} |
| Philip Zeyliger | b8a8f35 | 2025-06-02 07:39:37 -0700 | [diff] [blame] | 1486 | .firstMessageIndex=${this.containerState?.first_message_index || |
| 1487 | 0} |
| philip.zeyliger | 6d3de48 | 2025-06-10 19:38:14 -0700 | [diff] [blame] | 1488 | .state=${this.containerState} |
| banksean | 5477736 | 2025-06-19 16:38:30 +0000 | [diff] [blame] | 1489 | .dataManager=${this.dataManager} |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 1490 | ></sketch-timeline> |
| 1491 | </div> |
| 1492 | </div> |
| 1493 | |
| 1494 | <!-- Todo panel positioned outside the main flow - only visible in chat view --> |
| 1495 | <div |
| 1496 | class="todo-panel-container ${this._todoPanelVisible && |
| 1497 | this.viewMode === "chat" |
| 1498 | ? "visible" |
| 1499 | : ""}" |
| 1500 | > |
| 1501 | <sketch-todo-panel |
| 1502 | .visible=${this._todoPanelVisible && this.viewMode === "chat"} |
| 1503 | ></sketch-todo-panel> |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 1504 | </div> |
| 1505 | <div |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 1506 | class="diff2-view ${this.viewMode === "diff2" ? "view-active" : ""}" |
| 1507 | > |
| 1508 | <sketch-diff2-view |
| 1509 | .commit=${this.currentCommitHash} |
| 1510 | .gitService=${new DefaultGitDataService()} |
| 1511 | @diff-comment="${this._handleDiffComment}" |
| 1512 | ></sketch-diff2-view> |
| 1513 | </div> |
| Philip Zeyliger | 2d4c48f | 2025-05-02 23:35:03 +0000 | [diff] [blame] | 1514 | |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 1515 | <div |
| 1516 | class="terminal-view ${this.viewMode === "terminal" |
| 1517 | ? "view-active" |
| 1518 | : ""}" |
| 1519 | > |
| 1520 | <sketch-terminal></sketch-terminal> |
| 1521 | </div> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1522 | </div> |
| 1523 | </div> |
| 1524 | |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 1525 | <div id="chat-input"> |
| 1526 | <sketch-chat-input @send-chat="${this._sendChat}"></sketch-chat-input> |
| 1527 | </div> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1528 | `; |
| 1529 | } |
| 1530 | |
| 1531 | /** |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1532 | * Lifecycle callback when component is first connected to DOM |
| 1533 | */ |
| 1534 | firstUpdated(): void { |
| 1535 | if (this.viewMode !== "chat") { |
| 1536 | return; |
| 1537 | } |
| 1538 | |
| 1539 | // Initial scroll to bottom when component is first rendered |
| 1540 | setTimeout( |
| 1541 | () => this.scrollTo({ top: this.scrollHeight, behavior: "smooth" }), |
| Philip Zeyliger | 72682df | 2025-04-23 13:09:46 -0700 | [diff] [blame] | 1542 | 50, |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1543 | ); |
| 1544 | |
| Philip Zeyliger | 2c4db09 | 2025-04-28 16:57:50 -0700 | [diff] [blame] | 1545 | // Setup stop button |
| 1546 | const stopButton = this.renderRoot?.querySelector( |
| 1547 | "#stopButton", |
| 1548 | ) as HTMLButtonElement; |
| 1549 | stopButton?.addEventListener("click", async () => { |
| 1550 | try { |
| Sean McCullough | 495cb96 | 2025-05-01 16:25:53 -0700 | [diff] [blame] | 1551 | const response = await fetch("cancel", { |
| Philip Zeyliger | 2c4db09 | 2025-04-28 16:57:50 -0700 | [diff] [blame] | 1552 | method: "POST", |
| 1553 | headers: { |
| 1554 | "Content-Type": "application/json", |
| 1555 | }, |
| 1556 | body: JSON.stringify({ reason: "User clicked stop button" }), |
| 1557 | }); |
| 1558 | if (!response.ok) { |
| 1559 | console.error("Failed to cancel:", await response.text()); |
| 1560 | } |
| 1561 | } catch (error) { |
| 1562 | console.error("Error cancelling operation:", error); |
| 1563 | } |
| 1564 | }); |
| 1565 | |
| Pokey Rule | 397871d | 2025-05-19 15:02:45 +0100 | [diff] [blame] | 1566 | // Setup end button |
| 1567 | const endButton = this.renderRoot?.querySelector( |
| 1568 | "#endButton", |
| 1569 | ) as HTMLButtonElement; |
| 1570 | // We're already using the @click binding in the HTML, so manual event listener not needed here |
| 1571 | |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 1572 | // Process any existing messages to find commit information |
| 1573 | if (this.messages && this.messages.length > 0) { |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 1574 | // Update last commit info via container status component |
| 1575 | if (this.containerStatusElement) { |
| 1576 | this.containerStatusElement.updateLastCommitInfo(this.messages); |
| 1577 | } |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 1578 | } |
| Josh Bleecher Snyder | 112b923 | 2025-05-23 11:26:33 -0700 | [diff] [blame] | 1579 | |
| 1580 | // Set up chat input height observer for todo panel |
| 1581 | this.setupChatInputObserver(); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1582 | } |
| 1583 | } |
| 1584 | |
| 1585 | declare global { |
| 1586 | interface HTMLElementTagNameMap { |
| 1587 | "sketch-app-shell": SketchAppShell; |
| 1588 | } |
| 1589 | } |