| 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"; |
| 9 | import "./sketch-diff-view"; |
| 10 | import { SketchDiffView } from "./sketch-diff-view"; |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 11 | import "./sketch-diff2-view"; |
| 12 | import { SketchDiff2View } from "./sketch-diff2-view"; |
| 13 | import { DefaultGitDataService } from "./git-data-service"; |
| 14 | import "./sketch-monaco-view"; |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 15 | import "./sketch-network-status"; |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 16 | import "./sketch-call-status"; |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 17 | import "./sketch-terminal"; |
| 18 | import "./sketch-timeline"; |
| 19 | import "./sketch-view-mode-select"; |
| 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 | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 24 | type ViewMode = "chat" | "diff" | "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 | |
| 142 | #chat-input { |
| 143 | align-self: flex-end; |
| 144 | width: 100%; |
| 145 | box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1); |
| 146 | } |
| 147 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 148 | .banner-title { |
| 149 | font-size: 18px; |
| 150 | font-weight: 600; |
| 151 | margin: 0; |
| 152 | min-width: 6em; |
| 153 | white-space: nowrap; |
| 154 | overflow: hidden; |
| 155 | text-overflow: ellipsis; |
| 156 | } |
| 157 | |
| 158 | .chat-title { |
| 159 | margin: 0; |
| 160 | padding: 0; |
| 161 | color: rgba(82, 82, 82, 0.85); |
| Josh Bleecher Snyder | eb5166a | 2025-04-30 17:04:20 +0000 | [diff] [blame] | 162 | font-size: 14px; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 163 | font-weight: normal; |
| 164 | font-style: italic; |
| 165 | white-space: nowrap; |
| 166 | overflow: hidden; |
| 167 | text-overflow: ellipsis; |
| 168 | } |
| 169 | |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 170 | /* Allow the container to expand to full width and height in diff mode */ |
| 171 | #view-container-inner.diff-active, |
| 172 | #view-container-inner.diff2-active { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 173 | max-width: 100%; |
| Pokey Rule | 46fff97 | 2025-04-25 14:57:44 +0100 | [diff] [blame] | 174 | width: 100%; |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 175 | height: 100%; |
| 176 | padding: 0; /* Remove padding for more space */ |
| 177 | display: flex; |
| 178 | flex-direction: column; |
| 179 | flex: 1; |
| 180 | min-height: 0; /* Critical for flex behavior */ |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | /* Individual view styles */ |
| 184 | .chat-view, |
| 185 | .diff-view, |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 186 | .diff2-view, |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 187 | .terminal-view { |
| 188 | display: none; /* Hidden by default */ |
| 189 | width: 100%; |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 190 | height: 100%; |
| 191 | } |
| Autoformatter | 8c46362 | 2025-05-16 21:54:17 +0000 | [diff] [blame] | 192 | |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 193 | /* Make chat view take full width available */ |
| 194 | .chat-view.view-active { |
| 195 | display: flex; |
| 196 | flex-direction: column; |
| 197 | width: 100%; |
| 198 | } |
| Autoformatter | 8c46362 | 2025-05-16 21:54:17 +0000 | [diff] [blame] | 199 | |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 200 | /* Monaco diff2 view needs to take all available space */ |
| 201 | .diff2-view.view-active { |
| 202 | flex: 1; |
| 203 | overflow: hidden; |
| 204 | min-height: 0; /* Required for proper flex child behavior */ |
| 205 | display: flex; |
| 206 | flex-direction: column; |
| 207 | height: 100%; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | /* Active view styles - these will be applied via JavaScript */ |
| 211 | .view-active { |
| 212 | display: flex; |
| 213 | flex-direction: column; |
| 214 | } |
| 215 | |
| 216 | .title-container { |
| 217 | display: flex; |
| 218 | flex-direction: column; |
| 219 | white-space: nowrap; |
| 220 | overflow: hidden; |
| 221 | text-overflow: ellipsis; |
| Josh Bleecher Snyder | eb5166a | 2025-04-30 17:04:20 +0000 | [diff] [blame] | 222 | max-width: 30%; |
| Philip Zeyliger | e66db3e | 2025-04-27 15:40:39 +0000 | [diff] [blame] | 223 | padding: 6px 0; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | .refresh-control { |
| 227 | display: flex; |
| 228 | align-items: center; |
| 229 | margin-bottom: 0; |
| 230 | flex-wrap: nowrap; |
| 231 | white-space: nowrap; |
| 232 | flex-shrink: 0; |
| Philip Zeyliger | e66db3e | 2025-04-27 15:40:39 +0000 | [diff] [blame] | 233 | gap: 15px; |
| 234 | padding-left: 15px; |
| 235 | margin-right: 50px; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| Pokey Rule | 397871d | 2025-05-19 15:02:45 +0100 | [diff] [blame] | 238 | .stop-button, |
| 239 | .end-button { |
| Philip Zeyliger | 2c4db09 | 2025-04-28 16:57:50 -0700 | [diff] [blame] | 240 | background: #2196f3; |
| 241 | color: white; |
| 242 | border: none; |
| 243 | padding: 4px 10px; |
| 244 | border-radius: 4px; |
| 245 | cursor: pointer; |
| 246 | font-size: 12px; |
| 247 | margin-right: 5px; |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 248 | display: flex; |
| 249 | align-items: center; |
| 250 | gap: 6px; |
| Philip Zeyliger | 2c4db09 | 2025-04-28 16:57:50 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 253 | .stop-button { |
| 254 | background: #dc3545; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 255 | color: white; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 258 | .stop-button:hover:not(:disabled) { |
| 259 | background-color: #c82333; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 260 | } |
| 261 | |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 262 | .stop-button:disabled { |
| 263 | background-color: #e9a8ad; |
| 264 | cursor: not-allowed; |
| 265 | opacity: 0.7; |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 266 | } |
| 267 | |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 268 | .stop-button:disabled:hover { |
| 269 | background-color: #e9a8ad; |
| 270 | } |
| 271 | |
| Pokey Rule | 397871d | 2025-05-19 15:02:45 +0100 | [diff] [blame] | 272 | .end-button { |
| 273 | background: #6c757d; |
| 274 | color: white; |
| 275 | } |
| 276 | |
| 277 | .end-button:hover:not(:disabled) { |
| 278 | background-color: #5a6268; |
| 279 | } |
| 280 | |
| 281 | .end-button:disabled { |
| 282 | background-color: #a9acaf; |
| 283 | cursor: not-allowed; |
| 284 | opacity: 0.7; |
| 285 | } |
| 286 | |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 287 | .button-icon { |
| 288 | width: 16px; |
| 289 | height: 16px; |
| 290 | } |
| 291 | |
| 292 | @media (max-width: 1400px) { |
| 293 | .button-text { |
| 294 | display: none; |
| 295 | } |
| 296 | |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 297 | .stop-button { |
| 298 | padding: 6px; |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | /* Removed poll-updates class */ |
| 303 | |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 304 | .notifications-toggle { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 305 | display: flex; |
| 306 | align-items: center; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 307 | font-size: 12px; |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 308 | margin-right: 10px; |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 309 | cursor: pointer; |
| 310 | } |
| 311 | |
| 312 | .bell-icon { |
| 313 | width: 20px; |
| 314 | height: 20px; |
| 315 | position: relative; |
| 316 | display: inline-flex; |
| 317 | align-items: center; |
| 318 | justify-content: center; |
| 319 | } |
| 320 | |
| 321 | .bell-disabled::before { |
| 322 | content: ""; |
| 323 | position: absolute; |
| 324 | width: 2px; |
| 325 | height: 24px; |
| 326 | background-color: #dc3545; |
| 327 | transform: rotate(45deg); |
| 328 | transform-origin: center center; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 329 | } |
| 330 | `; |
| 331 | |
| 332 | // Header bar: Network connection status details |
| 333 | @property() |
| 334 | connectionStatus: ConnectionStatus = "disconnected"; |
| Autoformatter | cf57096 | 2025-04-30 17:27:39 +0000 | [diff] [blame] | 335 | |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 336 | // Track if the last commit info has been copied |
| 337 | @state() |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 338 | // lastCommitCopied moved to sketch-container-status |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 339 | |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 340 | // Track notification preferences |
| 341 | @state() |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 342 | notificationsEnabled: boolean = false; |
| 343 | |
| 344 | // Track if the window is focused to control notifications |
| 345 | @state() |
| 346 | private _windowFocused: boolean = document.hasFocus(); |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 347 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 348 | @property() |
| 349 | connectionErrorMessage: string = ""; |
| 350 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 351 | // Chat messages |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 352 | @property({ attribute: false }) |
| Sean McCullough | d9f1337 | 2025-04-21 15:08:49 -0700 | [diff] [blame] | 353 | messages: AgentMessage[] = []; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 354 | |
| 355 | @property() |
| Philip Zeyliger | 9b999b0 | 2025-04-25 16:31:50 +0000 | [diff] [blame] | 356 | set title(value: string) { |
| 357 | const oldValue = this._title; |
| 358 | this._title = value; |
| 359 | this.requestUpdate("title", oldValue); |
| 360 | // Update document title when title property changes |
| 361 | this.updateDocumentTitle(); |
| 362 | } |
| 363 | |
| 364 | get title(): string { |
| 365 | return this._title; |
| 366 | } |
| 367 | |
| 368 | private _title: string = ""; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 369 | |
| 370 | private dataManager = new DataManager(); |
| 371 | |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 372 | @property({ attribute: false }) |
| Sean McCullough | d9f1337 | 2025-04-21 15:08:49 -0700 | [diff] [blame] | 373 | containerState: State = { |
| Philip Zeyliger | d03318d | 2025-05-08 13:09:12 -0700 | [diff] [blame] | 374 | state_version: 2, |
| Sean McCullough | d9f1337 | 2025-04-21 15:08:49 -0700 | [diff] [blame] | 375 | title: "", |
| 376 | os: "", |
| 377 | message_count: 0, |
| 378 | hostname: "", |
| 379 | working_dir: "", |
| 380 | initial_commit: "", |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 381 | outstanding_llm_calls: 0, |
| 382 | outstanding_tool_calls: [], |
| Philip Zeyliger | c72fff5 | 2025-04-29 20:17:54 +0000 | [diff] [blame] | 383 | session_id: "", |
| 384 | ssh_available: false, |
| Philip Zeyliger | 2c4db09 | 2025-04-28 16:57:50 -0700 | [diff] [blame] | 385 | ssh_error: "", |
| 386 | in_container: false, |
| 387 | first_message_index: 0, |
| Sean McCullough | d9f1337 | 2025-04-21 15:08:49 -0700 | [diff] [blame] | 388 | }; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 389 | |
| Philip Zeyliger | 14fe75d | 2025-05-22 17:39:38 +0000 | [diff] [blame] | 390 | |
| Philip Zeyliger | 2c4db09 | 2025-04-28 16:57:50 -0700 | [diff] [blame] | 391 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 392 | // Mutation observer to detect when new messages are added |
| 393 | private mutationObserver: MutationObserver | null = null; |
| 394 | |
| 395 | constructor() { |
| 396 | super(); |
| 397 | |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 398 | // Reference to the container status element |
| 399 | this.containerStatusElement = null; |
| 400 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 401 | // Binding methods to this |
| 402 | this._handleViewModeSelect = this._handleViewModeSelect.bind(this); |
| Sean McCullough | 34bb09a | 2025-05-13 15:39:54 -0700 | [diff] [blame] | 403 | this._handlePopState = this._handlePopState.bind(this); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 404 | this._handleShowCommitDiff = this._handleShowCommitDiff.bind(this); |
| Sean McCullough | 485afc6 | 2025-04-28 14:28:39 -0700 | [diff] [blame] | 405 | this._handleMutlipleChoiceSelected = |
| 406 | this._handleMutlipleChoiceSelected.bind(this); |
| Sean McCullough | d3906e2 | 2025-04-29 17:32:14 +0000 | [diff] [blame] | 407 | this._handleStopClick = this._handleStopClick.bind(this); |
| Pokey Rule | 397871d | 2025-05-19 15:02:45 +0100 | [diff] [blame] | 408 | this._handleEndClick = this._handleEndClick.bind(this); |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 409 | this._handleNotificationsToggle = |
| 410 | this._handleNotificationsToggle.bind(this); |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 411 | this._handleWindowFocus = this._handleWindowFocus.bind(this); |
| 412 | this._handleWindowBlur = this._handleWindowBlur.bind(this); |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 413 | |
| 414 | // Load notification preference from localStorage |
| 415 | try { |
| 416 | const savedPref = localStorage.getItem("sketch-notifications-enabled"); |
| 417 | if (savedPref !== null) { |
| 418 | this.notificationsEnabled = savedPref === "true"; |
| 419 | } |
| 420 | } catch (error) { |
| 421 | console.error("Error loading notification preference:", error); |
| 422 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | // See https://lit.dev/docs/components/lifecycle/ |
| 426 | connectedCallback() { |
| 427 | super.connectedCallback(); |
| 428 | |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 429 | // Get reference to the container status element |
| 430 | setTimeout(() => { |
| 431 | this.containerStatusElement = |
| 432 | this.shadowRoot?.getElementById("container-status"); |
| 433 | }, 0); |
| 434 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 435 | // Initialize client-side nav history. |
| 436 | const url = new URL(window.location.href); |
| 437 | const mode = url.searchParams.get("view") || "chat"; |
| 438 | window.history.replaceState({ mode }, "", url.toString()); |
| 439 | |
| 440 | this.toggleViewMode(mode as ViewMode, false); |
| 441 | // Add popstate event listener to handle browser back/forward navigation |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 442 | window.addEventListener("popstate", this._handlePopState); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 443 | |
| 444 | // Add event listeners |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 445 | window.addEventListener("view-mode-select", this._handleViewModeSelect); |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 446 | window.addEventListener("show-commit-diff", this._handleShowCommitDiff); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 447 | |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 448 | // Add window focus/blur listeners for controlling notifications |
| 449 | window.addEventListener("focus", this._handleWindowFocus); |
| 450 | window.addEventListener("blur", this._handleWindowBlur); |
| Sean McCullough | 485afc6 | 2025-04-28 14:28:39 -0700 | [diff] [blame] | 451 | window.addEventListener( |
| 452 | "multiple-choice-selected", |
| 453 | this._handleMutlipleChoiceSelected, |
| 454 | ); |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 455 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 456 | // register event listeners |
| 457 | this.dataManager.addEventListener( |
| 458 | "dataChanged", |
| Philip Zeyliger | 72682df | 2025-04-23 13:09:46 -0700 | [diff] [blame] | 459 | this.handleDataChanged.bind(this), |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 460 | ); |
| 461 | this.dataManager.addEventListener( |
| 462 | "connectionStatusChanged", |
| Philip Zeyliger | 72682df | 2025-04-23 13:09:46 -0700 | [diff] [blame] | 463 | this.handleConnectionStatusChanged.bind(this), |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 464 | ); |
| 465 | |
| Philip Zeyliger | 9b999b0 | 2025-04-25 16:31:50 +0000 | [diff] [blame] | 466 | // Set initial document title |
| 467 | this.updateDocumentTitle(); |
| 468 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 469 | // Initialize the data manager |
| 470 | this.dataManager.initialize(); |
| Autoformatter | cf57096 | 2025-04-30 17:27:39 +0000 | [diff] [blame] | 471 | |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 472 | // Process existing messages for commit info |
| 473 | if (this.messages && this.messages.length > 0) { |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 474 | // Update last commit info via container status component |
| 475 | setTimeout(() => { |
| 476 | if (this.containerStatusElement) { |
| 477 | this.containerStatusElement.updateLastCommitInfo(this.messages); |
| 478 | } |
| 479 | }, 100); |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 480 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | // See https://lit.dev/docs/components/lifecycle/ |
| 484 | disconnectedCallback() { |
| 485 | super.disconnectedCallback(); |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 486 | window.removeEventListener("popstate", this._handlePopState); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 487 | |
| 488 | // Remove event listeners |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 489 | window.removeEventListener("view-mode-select", this._handleViewModeSelect); |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 490 | window.removeEventListener("show-commit-diff", this._handleShowCommitDiff); |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 491 | window.removeEventListener("focus", this._handleWindowFocus); |
| 492 | window.removeEventListener("blur", this._handleWindowBlur); |
| Sean McCullough | 485afc6 | 2025-04-28 14:28:39 -0700 | [diff] [blame] | 493 | window.removeEventListener( |
| 494 | "multiple-choice-selected", |
| 495 | this._handleMutlipleChoiceSelected, |
| 496 | ); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 497 | |
| 498 | // unregister data manager event listeners |
| 499 | this.dataManager.removeEventListener( |
| 500 | "dataChanged", |
| Philip Zeyliger | 72682df | 2025-04-23 13:09:46 -0700 | [diff] [blame] | 501 | this.handleDataChanged.bind(this), |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 502 | ); |
| 503 | this.dataManager.removeEventListener( |
| 504 | "connectionStatusChanged", |
| Philip Zeyliger | 72682df | 2025-04-23 13:09:46 -0700 | [diff] [blame] | 505 | this.handleConnectionStatusChanged.bind(this), |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 506 | ); |
| 507 | |
| 508 | // Disconnect mutation observer if it exists |
| 509 | if (this.mutationObserver) { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 510 | this.mutationObserver.disconnect(); |
| 511 | this.mutationObserver = null; |
| 512 | } |
| 513 | } |
| 514 | |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 515 | updateUrlForViewMode(mode: ViewMode): void { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 516 | // Get the current URL without search parameters |
| 517 | const url = new URL(window.location.href); |
| 518 | |
| 519 | // Clear existing parameters |
| 520 | url.search = ""; |
| 521 | |
| 522 | // Only add view parameter if not in default chat view |
| 523 | if (mode !== "chat") { |
| 524 | url.searchParams.set("view", mode); |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 525 | const diffView = this.shadowRoot?.querySelector( |
| Philip Zeyliger | 72682df | 2025-04-23 13:09:46 -0700 | [diff] [blame] | 526 | ".diff-view", |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 527 | ) as SketchDiffView; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 528 | |
| 529 | // If in diff view and there's a commit hash, include that too |
| 530 | if (mode === "diff" && diffView.commitHash) { |
| 531 | url.searchParams.set("commit", diffView.commitHash); |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | // Update the browser history without reloading the page |
| 536 | window.history.pushState({ mode }, "", url.toString()); |
| 537 | } |
| 538 | |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 539 | private _handlePopState(event: PopStateEvent) { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 540 | if (event.state && event.state.mode) { |
| 541 | this.toggleViewMode(event.state.mode, false); |
| 542 | } else { |
| 543 | this.toggleViewMode("chat", false); |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | /** |
| 548 | * Handle view mode selection event |
| 549 | */ |
| 550 | private _handleViewModeSelect(event: CustomEvent) { |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 551 | const mode = event.detail.mode as "chat" | "diff" | "diff2" | "terminal"; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 552 | this.toggleViewMode(mode, true); |
| 553 | } |
| 554 | |
| 555 | /** |
| 556 | * Handle show commit diff event |
| 557 | */ |
| 558 | private _handleShowCommitDiff(event: CustomEvent) { |
| 559 | const { commitHash } = event.detail; |
| 560 | if (commitHash) { |
| 561 | this.showCommitDiff(commitHash); |
| 562 | } |
| 563 | } |
| 564 | |
| Sean McCullough | 485afc6 | 2025-04-28 14:28:39 -0700 | [diff] [blame] | 565 | private _handleMultipleChoice(event: CustomEvent) { |
| 566 | window.console.log("_handleMultipleChoice", event); |
| 567 | this._sendChat; |
| 568 | } |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 569 | |
| 570 | private _handleDiffComment(event: CustomEvent) { |
| 571 | // Empty stub required by the event binding in the template |
| 572 | // Actual handling occurs at global level in sketch-chat-input component |
| 573 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 574 | /** |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 575 | * Listen for commit diff event |
| 576 | * @param commitHash The commit hash to show diff for |
| 577 | */ |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 578 | private showCommitDiff(commitHash: string): void { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 579 | // Store the commit hash |
| 580 | this.currentCommitHash = commitHash; |
| 581 | |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 582 | this.toggleViewMode("diff2", true); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 583 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 584 | this.updateComplete.then(() => { |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 585 | const diff2View = this.shadowRoot?.querySelector("sketch-diff2-view"); |
| 586 | if (diff2View) { |
| 587 | (diff2View as SketchDiff2View).refreshDiffView(); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 588 | } |
| 589 | }); |
| 590 | } |
| 591 | |
| 592 | /** |
| Philip Zeyliger | 2d4c48f | 2025-05-02 23:35:03 +0000 | [diff] [blame] | 593 | * Toggle between different view modes: chat, diff, terminal |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 594 | */ |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 595 | private toggleViewMode(mode: ViewMode, updateHistory: boolean): void { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 596 | // Don't do anything if the mode is already active |
| 597 | if (this.viewMode === mode) return; |
| 598 | |
| 599 | // Update the view mode |
| 600 | this.viewMode = mode; |
| 601 | |
| 602 | if (updateHistory) { |
| 603 | // Update URL with the current view mode |
| 604 | this.updateUrlForViewMode(mode); |
| 605 | } |
| 606 | |
| 607 | // Wait for DOM update to complete |
| 608 | this.updateComplete.then(() => { |
| 609 | // Update active view |
| Pokey Rule | 46fff97 | 2025-04-25 14:57:44 +0100 | [diff] [blame] | 610 | const viewContainerInner = this.shadowRoot?.querySelector( |
| 611 | "#view-container-inner", |
| 612 | ); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 613 | const chatView = this.shadowRoot?.querySelector(".chat-view"); |
| 614 | const diffView = this.shadowRoot?.querySelector(".diff-view"); |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 615 | const diff2View = this.shadowRoot?.querySelector(".diff2-view"); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 616 | const terminalView = this.shadowRoot?.querySelector(".terminal-view"); |
| 617 | |
| 618 | // Remove active class from all views |
| 619 | chatView?.classList.remove("view-active"); |
| 620 | diffView?.classList.remove("view-active"); |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 621 | diff2View?.classList.remove("view-active"); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 622 | terminalView?.classList.remove("view-active"); |
| 623 | |
| 624 | // Add/remove diff-active class on view container |
| 625 | if (mode === "diff") { |
| Pokey Rule | 46fff97 | 2025-04-25 14:57:44 +0100 | [diff] [blame] | 626 | viewContainerInner?.classList.add("diff-active"); |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 627 | viewContainerInner?.classList.remove("diff2-active"); |
| 628 | } else if (mode === "diff2") { |
| 629 | viewContainerInner?.classList.add("diff2-active"); |
| 630 | viewContainerInner?.classList.remove("diff-active"); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 631 | } else { |
| Pokey Rule | 46fff97 | 2025-04-25 14:57:44 +0100 | [diff] [blame] | 632 | viewContainerInner?.classList.remove("diff-active"); |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 633 | viewContainerInner?.classList.remove("diff2-active"); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | // Add active class to the selected view |
| 637 | switch (mode) { |
| 638 | case "chat": |
| 639 | chatView?.classList.add("view-active"); |
| 640 | break; |
| 641 | case "diff": |
| 642 | diffView?.classList.add("view-active"); |
| 643 | // Load diff content if we have a diff view |
| 644 | const diffViewComp = |
| 645 | this.shadowRoot?.querySelector("sketch-diff-view"); |
| 646 | if (diffViewComp && this.currentCommitHash) { |
| 647 | (diffViewComp as any).showCommitDiff(this.currentCommitHash); |
| 648 | } else if (diffViewComp) { |
| 649 | (diffViewComp as any).loadDiffContent(); |
| 650 | } |
| 651 | break; |
| Autoformatter | 8c46362 | 2025-05-16 21:54:17 +0000 | [diff] [blame] | 652 | |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 653 | case "diff2": |
| 654 | diff2View?.classList.add("view-active"); |
| 655 | // Refresh git/recentlog when Monaco diff view is opened |
| 656 | // 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] | 657 | const diff2ViewComp = |
| 658 | this.shadowRoot?.querySelector("sketch-diff2-view"); |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 659 | if (diff2ViewComp) { |
| 660 | (diff2ViewComp as SketchDiff2View).refreshDiffView(); |
| 661 | } |
| 662 | break; |
| Philip Zeyliger | 2d4c48f | 2025-05-02 23:35:03 +0000 | [diff] [blame] | 663 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 664 | case "terminal": |
| 665 | terminalView?.classList.add("view-active"); |
| 666 | break; |
| 667 | } |
| 668 | |
| 669 | // Update view mode buttons |
| 670 | const viewModeSelect = this.shadowRoot?.querySelector( |
| Philip Zeyliger | 72682df | 2025-04-23 13:09:46 -0700 | [diff] [blame] | 671 | "sketch-view-mode-select", |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 672 | ); |
| 673 | if (viewModeSelect) { |
| 674 | const event = new CustomEvent("update-active-mode", { |
| 675 | detail: { mode }, |
| 676 | bubbles: true, |
| 677 | composed: true, |
| 678 | }); |
| 679 | viewModeSelect.dispatchEvent(event); |
| 680 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 681 | }); |
| 682 | } |
| 683 | |
| Philip Zeyliger | 9b999b0 | 2025-04-25 16:31:50 +0000 | [diff] [blame] | 684 | /** |
| 685 | * Updates the document title based on current title and connection status |
| 686 | */ |
| 687 | private updateDocumentTitle(): void { |
| 688 | let docTitle = `sk: ${this.title || "untitled"}`; |
| 689 | |
| 690 | // Add red circle emoji if disconnected |
| 691 | if (this.connectionStatus === "disconnected") { |
| 692 | docTitle += " 🔴"; |
| 693 | } |
| 694 | |
| 695 | document.title = docTitle; |
| 696 | } |
| 697 | |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 698 | // Check and request notification permission if needed |
| 699 | private async checkNotificationPermission(): Promise<boolean> { |
| 700 | // Check if the Notification API is supported |
| 701 | if (!("Notification" in window)) { |
| 702 | console.log("This browser does not support notifications"); |
| 703 | return false; |
| 704 | } |
| 705 | |
| 706 | // Check if permission is already granted |
| 707 | if (Notification.permission === "granted") { |
| 708 | return true; |
| 709 | } |
| 710 | |
| 711 | // If permission is not denied, request it |
| 712 | if (Notification.permission !== "denied") { |
| 713 | const permission = await Notification.requestPermission(); |
| 714 | return permission === "granted"; |
| 715 | } |
| 716 | |
| 717 | return false; |
| 718 | } |
| 719 | |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 720 | // Handle notifications toggle click |
| 721 | private _handleNotificationsToggle(): void { |
| 722 | this.notificationsEnabled = !this.notificationsEnabled; |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 723 | |
| 724 | // If enabling notifications, check permissions |
| 725 | if (this.notificationsEnabled) { |
| 726 | this.checkNotificationPermission(); |
| 727 | } |
| 728 | |
| 729 | // Save preference to localStorage |
| 730 | try { |
| 731 | localStorage.setItem( |
| 732 | "sketch-notifications-enabled", |
| 733 | String(this.notificationsEnabled), |
| 734 | ); |
| 735 | } catch (error) { |
| 736 | console.error("Error saving notification preference:", error); |
| 737 | } |
| 738 | } |
| 739 | |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 740 | // Handle window focus event |
| 741 | private _handleWindowFocus(): void { |
| 742 | this._windowFocused = true; |
| 743 | } |
| 744 | |
| 745 | // Handle window blur event |
| 746 | private _handleWindowBlur(): void { |
| 747 | this._windowFocused = false; |
| 748 | } |
| 749 | |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 750 | // Show notification for message with EndOfTurn=true |
| 751 | private async showEndOfTurnNotification( |
| 752 | message: AgentMessage, |
| 753 | ): Promise<void> { |
| 754 | // Don't show notifications if they're disabled |
| 755 | if (!this.notificationsEnabled) return; |
| 756 | |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 757 | // Don't show notifications if the window is focused |
| 758 | if (this._windowFocused) return; |
| 759 | |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 760 | // Check if we have permission to show notifications |
| 761 | const hasPermission = await this.checkNotificationPermission(); |
| 762 | if (!hasPermission) return; |
| 763 | |
| Philip Zeyliger | 3201133 | 2025-04-30 20:59:40 +0000 | [diff] [blame] | 764 | // Only show notifications for agent messages with end_of_turn=true and no parent_conversation_id |
| 765 | if ( |
| 766 | message.type !== "agent" || |
| 767 | !message.end_of_turn || |
| 768 | message.parent_conversation_id |
| 769 | ) |
| 770 | return; |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 771 | |
| 772 | // Create a title that includes the sketch title |
| 773 | const notificationTitle = `Sketch: ${this.title || "untitled"}`; |
| 774 | |
| 775 | // Extract the beginning of the message content (first 100 chars) |
| 776 | const messagePreview = message.content |
| 777 | ? message.content.substring(0, 100) + |
| 778 | (message.content.length > 100 ? "..." : "") |
| 779 | : "Agent has completed its turn"; |
| 780 | |
| 781 | // Create and show the notification |
| 782 | try { |
| 783 | new Notification(notificationTitle, { |
| 784 | body: messagePreview, |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 785 | icon: "https://sketch.dev/favicon.ico", // Use sketch.dev favicon for notification |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 786 | }); |
| 787 | } catch (error) { |
| 788 | console.error("Error showing notification:", error); |
| 789 | } |
| 790 | } |
| 791 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 792 | private handleDataChanged(eventData: { |
| 793 | state: State; |
| Sean McCullough | d9f1337 | 2025-04-21 15:08:49 -0700 | [diff] [blame] | 794 | newMessages: AgentMessage[]; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 795 | }): void { |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 796 | const { state, newMessages } = eventData; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 797 | |
| 798 | // Update state if we received it |
| 799 | if (state) { |
| Josh Bleecher Snyder | e81233f | 2025-04-30 04:05:41 +0000 | [diff] [blame] | 800 | // 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] | 801 | if ( |
| 802 | state.outstanding_llm_calls === 0 && |
| 803 | state.outstanding_tool_calls.length === 0 |
| 804 | ) { |
| Josh Bleecher Snyder | e81233f | 2025-04-30 04:05:41 +0000 | [diff] [blame] | 805 | // Force reset containerState calls when nothing is reported as in progress |
| 806 | state.outstanding_llm_calls = 0; |
| 807 | state.outstanding_tool_calls = []; |
| 808 | } |
| Autoformatter | f830c9d | 2025-04-30 18:16:01 +0000 | [diff] [blame] | 809 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 810 | this.containerState = state; |
| 811 | this.title = state.title; |
| Philip Zeyliger | 9b999b0 | 2025-04-25 16:31:50 +0000 | [diff] [blame] | 812 | |
| 813 | // Update document title when sketch title changes |
| 814 | this.updateDocumentTitle(); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 815 | } |
| 816 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 817 | // Update messages |
| Pokey Rule | e2a8c2f | 2025-04-23 15:09:25 +0100 | [diff] [blame] | 818 | this.messages = aggregateAgentMessages(this.messages, newMessages); |
| Autoformatter | cf57096 | 2025-04-30 17:27:39 +0000 | [diff] [blame] | 819 | |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 820 | // Process new messages to find commit messages |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 821 | // Update last commit info via container status component |
| 822 | if (this.containerStatusElement) { |
| 823 | this.containerStatusElement.updateLastCommitInfo(newMessages); |
| 824 | } |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 825 | |
| 826 | // Check for agent messages with end_of_turn=true and show notifications |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 827 | if (newMessages && newMessages.length > 0) { |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 828 | for (const message of newMessages) { |
| Philip Zeyliger | 3201133 | 2025-04-30 20:59:40 +0000 | [diff] [blame] | 829 | if ( |
| 830 | message.type === "agent" && |
| 831 | message.end_of_turn && |
| 832 | !message.parent_conversation_id |
| 833 | ) { |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 834 | this.showEndOfTurnNotification(message); |
| 835 | break; // Only show one notification per batch of messages |
| 836 | } |
| 837 | } |
| 838 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | private handleConnectionStatusChanged( |
| 842 | status: ConnectionStatus, |
| Philip Zeyliger | 72682df | 2025-04-23 13:09:46 -0700 | [diff] [blame] | 843 | errorMessage?: string, |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 844 | ): void { |
| 845 | this.connectionStatus = status; |
| 846 | this.connectionErrorMessage = errorMessage || ""; |
| Philip Zeyliger | 9b999b0 | 2025-04-25 16:31:50 +0000 | [diff] [blame] | 847 | |
| 848 | // Update document title when connection status changes |
| 849 | this.updateDocumentTitle(); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 850 | } |
| 851 | |
| Sean McCullough | d3906e2 | 2025-04-29 17:32:14 +0000 | [diff] [blame] | 852 | private async _handleStopClick(): Promise<void> { |
| 853 | try { |
| 854 | const response = await fetch("cancel", { |
| 855 | method: "POST", |
| 856 | headers: { |
| 857 | "Content-Type": "application/json", |
| 858 | }, |
| 859 | body: JSON.stringify({ reason: "user requested cancellation" }), |
| 860 | }); |
| 861 | |
| 862 | if (!response.ok) { |
| 863 | const errorData = await response.text(); |
| 864 | throw new Error( |
| 865 | `Failed to stop operation: ${response.status} - ${errorData}`, |
| 866 | ); |
| 867 | } |
| 868 | |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 869 | // Stop request sent |
| Sean McCullough | d3906e2 | 2025-04-29 17:32:14 +0000 | [diff] [blame] | 870 | } catch (error) { |
| 871 | console.error("Error stopping operation:", error); |
| Sean McCullough | d3906e2 | 2025-04-29 17:32:14 +0000 | [diff] [blame] | 872 | } |
| 873 | } |
| 874 | |
| Pokey Rule | 397871d | 2025-05-19 15:02:45 +0100 | [diff] [blame] | 875 | private async _handleEndClick(event?: Event): Promise<void> { |
| 876 | if (event) { |
| 877 | event.preventDefault(); |
| 878 | event.stopPropagation(); |
| 879 | } |
| 880 | // Show confirmation dialog |
| 881 | const confirmed = window.confirm( |
| 882 | "Ending the session will shut down the underlying container. Are you sure?", |
| 883 | ); |
| 884 | if (!confirmed) return; |
| 885 | |
| 886 | try { |
| 887 | const response = await fetch("end", { |
| 888 | method: "POST", |
| 889 | headers: { |
| 890 | "Content-Type": "application/json", |
| 891 | }, |
| 892 | body: JSON.stringify({ reason: "user requested end of session" }), |
| 893 | }); |
| 894 | |
| 895 | if (!response.ok) { |
| 896 | const errorData = await response.text(); |
| 897 | throw new Error( |
| 898 | `Failed to end session: ${response.status} - ${errorData}`, |
| 899 | ); |
| 900 | } |
| 901 | |
| 902 | // After successful response, redirect to messages view |
| 903 | // Extract the session ID from the URL |
| 904 | const currentUrl = window.location.href; |
| 905 | // The URL pattern should be like https://sketch.dev/s/cs71-8qa6-1124-aw79/ |
| 906 | const urlParts = currentUrl.split("/"); |
| 907 | let sessionId = ""; |
| 908 | |
| 909 | // Find the session ID in the URL (should be after /s/) |
| 910 | for (let i = 0; i < urlParts.length; i++) { |
| 911 | if (urlParts[i] === "s" && i + 1 < urlParts.length) { |
| 912 | sessionId = urlParts[i + 1]; |
| 913 | break; |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | if (sessionId) { |
| 918 | // Create the messages URL |
| 919 | const messagesUrl = `/messages/${sessionId}`; |
| 920 | // Redirect to messages view |
| 921 | window.location.href = messagesUrl; |
| 922 | } |
| 923 | |
| 924 | // End request sent - connection will be closed by server |
| 925 | } catch (error) { |
| 926 | console.error("Error ending session:", error); |
| 927 | } |
| 928 | } |
| 929 | |
| Philip Zeyliger | 2c4db09 | 2025-04-28 16:57:50 -0700 | [diff] [blame] | 930 | |
| Philip Zeyliger | 2c4db09 | 2025-04-28 16:57:50 -0700 | [diff] [blame] | 931 | |
| Sean McCullough | 485afc6 | 2025-04-28 14:28:39 -0700 | [diff] [blame] | 932 | async _handleMutlipleChoiceSelected(e: CustomEvent) { |
| 933 | const chatInput = this.shadowRoot?.querySelector( |
| 934 | "sketch-chat-input", |
| 935 | ) as SketchChatInput; |
| 936 | if (chatInput) { |
| 937 | chatInput.content = e.detail.responseText; |
| 938 | chatInput.focus(); |
| 939 | } |
| 940 | } |
| 941 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 942 | async _sendChat(e: CustomEvent) { |
| 943 | console.log("app shell: _sendChat", e); |
| Sean McCullough | 485afc6 | 2025-04-28 14:28:39 -0700 | [diff] [blame] | 944 | e.preventDefault(); |
| 945 | e.stopPropagation(); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 946 | const message = e.detail.message?.trim(); |
| 947 | if (message == "") { |
| 948 | return; |
| 949 | } |
| 950 | try { |
| Josh Bleecher Snyder | 98b64d1 | 2025-05-12 19:42:43 +0000 | [diff] [blame] | 951 | // Always switch to chat view when sending a message so user can see processing |
| 952 | if (this.viewMode !== "chat") { |
| 953 | this.toggleViewMode("chat", true); |
| 954 | } |
| Autoformatter | 5c7f957 | 2025-05-13 01:17:31 +0000 | [diff] [blame] | 955 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 956 | // Send the message to the server |
| 957 | const response = await fetch("chat", { |
| 958 | method: "POST", |
| 959 | headers: { |
| 960 | "Content-Type": "application/json", |
| 961 | }, |
| 962 | body: JSON.stringify({ message }), |
| 963 | }); |
| 964 | |
| 965 | if (!response.ok) { |
| 966 | const errorData = await response.text(); |
| 967 | throw new Error(`Server error: ${response.status} - ${errorData}`); |
| 968 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 969 | } catch (error) { |
| 970 | console.error("Error sending chat message:", error); |
| 971 | const statusText = document.getElementById("statusText"); |
| 972 | if (statusText) { |
| 973 | statusText.textContent = "Error sending message"; |
| 974 | } |
| 975 | } |
| 976 | } |
| 977 | |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 978 | private scrollContainerRef = createRef<HTMLElement>(); |
| 979 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 980 | render() { |
| 981 | return html` |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 982 | <div id="top-banner"> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 983 | <div class="title-container"> |
| 984 | <h1 class="banner-title">sketch</h1> |
| 985 | <h2 id="chatTitle" class="chat-title">${this.title}</h2> |
| 986 | </div> |
| 987 | |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 988 | <!-- Container status info moved above tabs --> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 989 | <sketch-container-status |
| 990 | .state=${this.containerState} |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 991 | id="container-status" |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 992 | ></sketch-container-status> |
| Autoformatter | cf57096 | 2025-04-30 17:27:39 +0000 | [diff] [blame] | 993 | |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 994 | <!-- Last Commit section moved to sketch-container-status --> |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 995 | |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 996 | <!-- Views section with tabs --> |
| 997 | <sketch-view-mode-select></sketch-view-mode-select> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 998 | |
| 999 | <div class="refresh-control"> |
| Sean McCullough | d3906e2 | 2025-04-29 17:32:14 +0000 | [diff] [blame] | 1000 | <button |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 1001 | id="stopButton" |
| 1002 | class="stop-button" |
| 1003 | ?disabled=${(this.containerState?.outstanding_llm_calls || 0) === |
| 1004 | 0 && |
| 1005 | (this.containerState?.outstanding_tool_calls || []).length === 0} |
| 1006 | > |
| 1007 | <svg |
| 1008 | class="button-icon" |
| 1009 | xmlns="http://www.w3.org/2000/svg" |
| 1010 | viewBox="0 0 24 24" |
| 1011 | fill="none" |
| 1012 | stroke="currentColor" |
| 1013 | stroke-width="2" |
| 1014 | stroke-linecap="round" |
| 1015 | stroke-linejoin="round" |
| 1016 | > |
| 1017 | <rect x="6" y="6" width="12" height="12" /> |
| 1018 | </svg> |
| 1019 | <span class="button-text">Stop</span> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1020 | </button> |
| Pokey Rule | 397871d | 2025-05-19 15:02:45 +0100 | [diff] [blame] | 1021 | <button |
| 1022 | id="endButton" |
| 1023 | class="end-button" |
| 1024 | @click=${this._handleEndClick} |
| 1025 | > |
| 1026 | <svg |
| 1027 | class="button-icon" |
| 1028 | xmlns="http://www.w3.org/2000/svg" |
| 1029 | viewBox="0 0 24 24" |
| 1030 | fill="none" |
| 1031 | stroke="currentColor" |
| 1032 | stroke-width="2" |
| 1033 | stroke-linecap="round" |
| 1034 | stroke-linejoin="round" |
| 1035 | > |
| 1036 | <path d="M18 6L6 18" /> |
| 1037 | <path d="M6 6l12 12" /> |
| 1038 | </svg> |
| 1039 | <span class="button-text">End</span> |
| 1040 | </button> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1041 | |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 1042 | <div |
| 1043 | class="notifications-toggle" |
| 1044 | @click=${this._handleNotificationsToggle} |
| 1045 | title="${this.notificationsEnabled |
| 1046 | ? "Disable" |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 1047 | : "Enable"} notifications when the agent completes its turn" |
| Philip Zeyliger | db5e9b4 | 2025-04-30 19:58:13 +0000 | [diff] [blame] | 1048 | > |
| 1049 | <div |
| 1050 | class="bell-icon ${!this.notificationsEnabled |
| 1051 | ? "bell-disabled" |
| 1052 | : ""}" |
| 1053 | > |
| 1054 | <!-- Bell SVG icon --> |
| 1055 | <svg |
| 1056 | xmlns="http://www.w3.org/2000/svg" |
| 1057 | width="16" |
| 1058 | height="16" |
| 1059 | fill="currentColor" |
| 1060 | viewBox="0 0 16 16" |
| 1061 | > |
| 1062 | <path |
| 1063 | 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" |
| 1064 | /> |
| 1065 | </svg> |
| 1066 | </div> |
| Philip Zeyliger | bc6b629 | 2025-04-30 18:00:15 +0000 | [diff] [blame] | 1067 | </div> |
| 1068 | |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 1069 | <sketch-call-status |
| Sean McCullough | d9d4581 | 2025-04-30 16:53:41 -0700 | [diff] [blame] | 1070 | .agentState=${this.containerState?.agent_state} |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 1071 | .llmCalls=${this.containerState?.outstanding_llm_calls || 0} |
| 1072 | .toolCalls=${this.containerState?.outstanding_tool_calls || []} |
| Philip Zeyliger | 7231839 | 2025-05-14 02:56:07 +0000 | [diff] [blame] | 1073 | .isIdle=${this.messages.length > 0 |
| 1074 | ? this.messages[this.messages.length - 1]?.end_of_turn && |
| 1075 | !this.messages[this.messages.length - 1]?.parent_conversation_id |
| 1076 | : true} |
| Philip Zeyliger | 5e35702 | 2025-05-16 04:50:34 +0000 | [diff] [blame] | 1077 | .isDisconnected=${this.connectionStatus === "disconnected"} |
| Philip Zeyliger | 99a9a02 | 2025-04-27 15:15:25 +0000 | [diff] [blame] | 1078 | ></sketch-call-status> |
| Philip Zeyliger | 25f6ff1 | 2025-05-02 04:24:10 +0000 | [diff] [blame] | 1079 | |
| 1080 | <sketch-network-status |
| 1081 | connection=${this.connectionStatus} |
| 1082 | error=${this.connectionErrorMessage} |
| 1083 | ></sketch-network-status> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1084 | </div> |
| 1085 | </div> |
| 1086 | |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 1087 | <div id="view-container" ${ref(this.scrollContainerRef)}> |
| 1088 | <div id="view-container-inner"> |
| 1089 | <div |
| 1090 | class="chat-view ${this.viewMode === "chat" ? "view-active" : ""}" |
| 1091 | > |
| 1092 | <sketch-timeline |
| 1093 | .messages=${this.messages} |
| 1094 | .scrollContainer=${this.scrollContainerRef} |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 1095 | .agentState=${this.containerState?.agent_state} |
| 1096 | .llmCalls=${this.containerState?.outstanding_llm_calls || 0} |
| 1097 | .toolCalls=${this.containerState?.outstanding_tool_calls || []} |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 1098 | ></sketch-timeline> |
| 1099 | </div> |
| 1100 | <div |
| 1101 | class="diff-view ${this.viewMode === "diff" ? "view-active" : ""}" |
| 1102 | > |
| 1103 | <sketch-diff-view |
| 1104 | .commitHash=${this.currentCommitHash} |
| 1105 | ></sketch-diff-view> |
| 1106 | </div> |
| Autoformatter | 8c46362 | 2025-05-16 21:54:17 +0000 | [diff] [blame] | 1107 | |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 1108 | <div |
| 1109 | class="diff2-view ${this.viewMode === "diff2" ? "view-active" : ""}" |
| 1110 | > |
| 1111 | <sketch-diff2-view |
| 1112 | .commit=${this.currentCommitHash} |
| 1113 | .gitService=${new DefaultGitDataService()} |
| 1114 | @diff-comment="${this._handleDiffComment}" |
| 1115 | ></sketch-diff2-view> |
| 1116 | </div> |
| Philip Zeyliger | 2d4c48f | 2025-05-02 23:35:03 +0000 | [diff] [blame] | 1117 | |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 1118 | <div |
| 1119 | class="terminal-view ${this.viewMode === "terminal" |
| 1120 | ? "view-active" |
| 1121 | : ""}" |
| 1122 | > |
| 1123 | <sketch-terminal></sketch-terminal> |
| 1124 | </div> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1125 | </div> |
| 1126 | </div> |
| 1127 | |
| Pokey Rule | 4097e53 | 2025-04-24 18:55:28 +0100 | [diff] [blame] | 1128 | <div id="chat-input"> |
| 1129 | <sketch-chat-input @send-chat="${this._sendChat}"></sketch-chat-input> |
| 1130 | </div> |
| Philip Zeyliger | 2c4db09 | 2025-04-28 16:57:50 -0700 | [diff] [blame] | 1131 | |
| Philip Zeyliger | 14fe75d | 2025-05-22 17:39:38 +0000 | [diff] [blame] | 1132 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1133 | `; |
| 1134 | } |
| 1135 | |
| 1136 | /** |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1137 | * Lifecycle callback when component is first connected to DOM |
| 1138 | */ |
| 1139 | firstUpdated(): void { |
| 1140 | if (this.viewMode !== "chat") { |
| 1141 | return; |
| 1142 | } |
| 1143 | |
| 1144 | // Initial scroll to bottom when component is first rendered |
| 1145 | setTimeout( |
| 1146 | () => this.scrollTo({ top: this.scrollHeight, behavior: "smooth" }), |
| Philip Zeyliger | 72682df | 2025-04-23 13:09:46 -0700 | [diff] [blame] | 1147 | 50, |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1148 | ); |
| 1149 | |
| Philip Zeyliger | 2c4db09 | 2025-04-28 16:57:50 -0700 | [diff] [blame] | 1150 | // Setup stop button |
| 1151 | const stopButton = this.renderRoot?.querySelector( |
| 1152 | "#stopButton", |
| 1153 | ) as HTMLButtonElement; |
| 1154 | stopButton?.addEventListener("click", async () => { |
| 1155 | try { |
| Sean McCullough | 495cb96 | 2025-05-01 16:25:53 -0700 | [diff] [blame] | 1156 | const response = await fetch("cancel", { |
| Philip Zeyliger | 2c4db09 | 2025-04-28 16:57:50 -0700 | [diff] [blame] | 1157 | method: "POST", |
| 1158 | headers: { |
| 1159 | "Content-Type": "application/json", |
| 1160 | }, |
| 1161 | body: JSON.stringify({ reason: "User clicked stop button" }), |
| 1162 | }); |
| 1163 | if (!response.ok) { |
| 1164 | console.error("Failed to cancel:", await response.text()); |
| 1165 | } |
| 1166 | } catch (error) { |
| 1167 | console.error("Error cancelling operation:", error); |
| 1168 | } |
| 1169 | }); |
| 1170 | |
| Pokey Rule | 397871d | 2025-05-19 15:02:45 +0100 | [diff] [blame] | 1171 | // Setup end button |
| 1172 | const endButton = this.renderRoot?.querySelector( |
| 1173 | "#endButton", |
| 1174 | ) as HTMLButtonElement; |
| 1175 | // We're already using the @click binding in the HTML, so manual event listener not needed here |
| 1176 | |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 1177 | // Process any existing messages to find commit information |
| 1178 | if (this.messages && this.messages.length > 0) { |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 1179 | // Update last commit info via container status component |
| 1180 | if (this.containerStatusElement) { |
| 1181 | this.containerStatusElement.updateLastCommitInfo(this.messages); |
| 1182 | } |
| Philip Zeyliger | 47b71c9 | 2025-04-30 15:43:39 +0000 | [diff] [blame] | 1183 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | declare global { |
| 1188 | interface HTMLElementTagNameMap { |
| 1189 | "sketch-app-shell": SketchAppShell; |
| 1190 | } |
| 1191 | } |