blob: f74fd59439fcac572945e6aa2c917d7fcbcee723 [file] [log] [blame]
Sean McCullough86b56862025-04-18 13:04:03 -07001import { css, html, LitElement } from "lit";
2import { customElement, property, state } from "lit/decorators.js";
Pokey Rule4097e532025-04-24 18:55:28 +01003import { ConnectionStatus, DataManager } from "../data";
4import { AgentMessage, State } from "../types";
Pokey Rulee2a8c2f2025-04-23 15:09:25 +01005import { aggregateAgentMessages } from "./aggregateAgentMessages";
Pokey Rule4097e532025-04-24 18:55:28 +01006import "./sketch-charts";
7import "./sketch-chat-input";
8import "./sketch-container-status";
9import "./sketch-diff-view";
10import { SketchDiffView } from "./sketch-diff-view";
11import "./sketch-network-status";
Philip Zeyliger99a9a022025-04-27 15:15:25 +000012import "./sketch-call-status";
Pokey Rule4097e532025-04-24 18:55:28 +010013import "./sketch-terminal";
14import "./sketch-timeline";
15import "./sketch-view-mode-select";
16
17import { createRef, ref } from "lit/directives/ref.js";
Sean McCullough86b56862025-04-18 13:04:03 -070018
19type ViewMode = "chat" | "diff" | "charts" | "terminal";
20
21@customElement("sketch-app-shell")
22export class SketchAppShell extends LitElement {
23 // Current view mode (chat, diff, charts, terminal)
24 @state()
25 viewMode: "chat" | "diff" | "charts" | "terminal" = "chat";
26
27 // Current commit hash for diff view
28 @state()
29 currentCommitHash: string = "";
30
Sean McCullough86b56862025-04-18 13:04:03 -070031 // See https://lit.dev/docs/components/styles/ for how lit-element handles CSS.
32 // Note that these styles only apply to the scope of this web component's
33 // shadow DOM node, so they won't leak out or collide with CSS declared in
34 // other components or the containing web page (...unless you want it to do that).
35 static styles = css`
36 :host {
37 display: block;
Sean McCullough71941bd2025-04-18 13:31:48 -070038 font-family:
39 system-ui,
40 -apple-system,
41 BlinkMacSystemFont,
42 "Segoe UI",
43 Roboto,
44 sans-serif;
Sean McCullough86b56862025-04-18 13:04:03 -070045 color: #333;
46 line-height: 1.4;
Pokey Rule4097e532025-04-24 18:55:28 +010047 height: 100vh;
Sean McCullough86b56862025-04-18 13:04:03 -070048 width: 100%;
49 position: relative;
50 overflow-x: hidden;
Pokey Rule4097e532025-04-24 18:55:28 +010051 display: flex;
52 flex-direction: column;
Sean McCullough86b56862025-04-18 13:04:03 -070053 }
54
55 /* Top banner with combined elements */
Pokey Rule4097e532025-04-24 18:55:28 +010056 #top-banner {
Sean McCullough86b56862025-04-18 13:04:03 -070057 display: flex;
Philip Zeyligere66db3e2025-04-27 15:40:39 +000058 align-self: stretch;
Sean McCullough86b56862025-04-18 13:04:03 -070059 justify-content: space-between;
60 align-items: center;
Philip Zeyligere66db3e2025-04-27 15:40:39 +000061 padding: 0 20px;
Sean McCullough86b56862025-04-18 13:04:03 -070062 margin-bottom: 0;
63 border-bottom: 1px solid #eee;
Philip Zeyligere66db3e2025-04-27 15:40:39 +000064 gap: 20px;
Sean McCullough86b56862025-04-18 13:04:03 -070065 background: white;
Sean McCullough86b56862025-04-18 13:04:03 -070066 box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
Philip Zeyligere66db3e2025-04-27 15:40:39 +000067 width: 100%;
68 height: 48px;
69 padding-right: 30px; /* Extra padding on the right to prevent elements from hitting the edge */
Sean McCullough86b56862025-04-18 13:04:03 -070070 }
71
Pokey Rule4097e532025-04-24 18:55:28 +010072 /* View mode container styles - mirroring timeline.css structure */
73 #view-container {
74 align-self: stretch;
75 overflow-y: auto;
76 flex: 1;
77 }
78
79 #view-container-inner {
80 max-width: 1200px;
81 margin: 0 auto;
82 position: relative;
83 padding-bottom: 10px;
84 padding-top: 10px;
85 }
86
87 #chat-input {
88 align-self: flex-end;
89 width: 100%;
90 box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
91 }
92
Sean McCullough86b56862025-04-18 13:04:03 -070093 .banner-title {
94 font-size: 18px;
95 font-weight: 600;
96 margin: 0;
97 min-width: 6em;
98 white-space: nowrap;
99 overflow: hidden;
100 text-overflow: ellipsis;
101 }
102
103 .chat-title {
104 margin: 0;
105 padding: 0;
106 color: rgba(82, 82, 82, 0.85);
107 font-size: 16px;
108 font-weight: normal;
109 font-style: italic;
110 white-space: nowrap;
111 overflow: hidden;
112 text-overflow: ellipsis;
113 }
114
Sean McCullough86b56862025-04-18 13:04:03 -0700115 /* Allow the container to expand to full width in diff mode */
Pokey Rule46fff972025-04-25 14:57:44 +0100116 #view-container-inner.diff-active {
Sean McCullough86b56862025-04-18 13:04:03 -0700117 max-width: 100%;
Pokey Rule46fff972025-04-25 14:57:44 +0100118 width: 100%;
Sean McCullough86b56862025-04-18 13:04:03 -0700119 }
120
121 /* Individual view styles */
122 .chat-view,
123 .diff-view,
124 .chart-view,
125 .terminal-view {
126 display: none; /* Hidden by default */
127 width: 100%;
128 }
129
130 /* Active view styles - these will be applied via JavaScript */
131 .view-active {
132 display: flex;
133 flex-direction: column;
134 }
135
136 .title-container {
137 display: flex;
138 flex-direction: column;
139 white-space: nowrap;
140 overflow: hidden;
141 text-overflow: ellipsis;
Philip Zeyligere66db3e2025-04-27 15:40:39 +0000142 max-width: 25%;
143 padding: 6px 0;
Sean McCullough86b56862025-04-18 13:04:03 -0700144 }
145
146 .refresh-control {
147 display: flex;
148 align-items: center;
149 margin-bottom: 0;
150 flex-wrap: nowrap;
151 white-space: nowrap;
152 flex-shrink: 0;
Philip Zeyligere66db3e2025-04-27 15:40:39 +0000153 gap: 15px;
154 padding-left: 15px;
155 margin-right: 50px;
Sean McCullough86b56862025-04-18 13:04:03 -0700156 }
157
158 .refresh-button {
159 background: #4caf50;
160 color: white;
161 border: none;
162 padding: 4px 10px;
163 border-radius: 4px;
164 cursor: pointer;
165 font-size: 12px;
166 margin-right: 5px;
167 }
168
169 .stop-button:hover {
170 background-color: #c82333 !important;
171 }
172
173 .poll-updates {
174 display: flex;
175 align-items: center;
Sean McCullough86b56862025-04-18 13:04:03 -0700176 font-size: 12px;
177 }
178 `;
179
180 // Header bar: Network connection status details
181 @property()
182 connectionStatus: ConnectionStatus = "disconnected";
183
184 @property()
185 connectionErrorMessage: string = "";
186
187 @property()
188 messageStatus: string = "";
189
190 // Chat messages
Pokey Rulee2a8c2f2025-04-23 15:09:25 +0100191 @property({ attribute: false })
Sean McCulloughd9f13372025-04-21 15:08:49 -0700192 messages: AgentMessage[] = [];
Sean McCullough86b56862025-04-18 13:04:03 -0700193
194 @property()
Philip Zeyliger9b999b02025-04-25 16:31:50 +0000195 set title(value: string) {
196 const oldValue = this._title;
197 this._title = value;
198 this.requestUpdate("title", oldValue);
199 // Update document title when title property changes
200 this.updateDocumentTitle();
201 }
202
203 get title(): string {
204 return this._title;
205 }
206
207 private _title: string = "";
Sean McCullough86b56862025-04-18 13:04:03 -0700208
209 private dataManager = new DataManager();
210
Pokey Rulee2a8c2f2025-04-23 15:09:25 +0100211 @property({ attribute: false })
Sean McCulloughd9f13372025-04-21 15:08:49 -0700212 containerState: State = {
213 title: "",
214 os: "",
215 message_count: 0,
216 hostname: "",
217 working_dir: "",
218 initial_commit: "",
Philip Zeyliger99a9a022025-04-27 15:15:25 +0000219 outstanding_llm_calls: 0,
220 outstanding_tool_calls: [],
Sean McCulloughd9f13372025-04-21 15:08:49 -0700221 };
Sean McCullough86b56862025-04-18 13:04:03 -0700222
Sean McCullough86b56862025-04-18 13:04:03 -0700223 // Mutation observer to detect when new messages are added
224 private mutationObserver: MutationObserver | null = null;
225
226 constructor() {
227 super();
228
229 // Binding methods to this
230 this._handleViewModeSelect = this._handleViewModeSelect.bind(this);
Sean McCullough86b56862025-04-18 13:04:03 -0700231 this._handleShowCommitDiff = this._handleShowCommitDiff.bind(this);
232 this._handlePopState = this._handlePopState.bind(this);
233 }
234
235 // See https://lit.dev/docs/components/lifecycle/
236 connectedCallback() {
237 super.connectedCallback();
238
239 // Initialize client-side nav history.
240 const url = new URL(window.location.href);
241 const mode = url.searchParams.get("view") || "chat";
242 window.history.replaceState({ mode }, "", url.toString());
243
244 this.toggleViewMode(mode as ViewMode, false);
245 // Add popstate event listener to handle browser back/forward navigation
Pokey Rulee2a8c2f2025-04-23 15:09:25 +0100246 window.addEventListener("popstate", this._handlePopState);
Sean McCullough86b56862025-04-18 13:04:03 -0700247
248 // Add event listeners
Pokey Rulee2a8c2f2025-04-23 15:09:25 +0100249 window.addEventListener("view-mode-select", this._handleViewModeSelect);
Pokey Rulee2a8c2f2025-04-23 15:09:25 +0100250 window.addEventListener("show-commit-diff", this._handleShowCommitDiff);
Sean McCullough86b56862025-04-18 13:04:03 -0700251
252 // register event listeners
253 this.dataManager.addEventListener(
254 "dataChanged",
Philip Zeyliger72682df2025-04-23 13:09:46 -0700255 this.handleDataChanged.bind(this),
Sean McCullough86b56862025-04-18 13:04:03 -0700256 );
257 this.dataManager.addEventListener(
258 "connectionStatusChanged",
Philip Zeyliger72682df2025-04-23 13:09:46 -0700259 this.handleConnectionStatusChanged.bind(this),
Sean McCullough86b56862025-04-18 13:04:03 -0700260 );
261
Philip Zeyliger9b999b02025-04-25 16:31:50 +0000262 // Set initial document title
263 this.updateDocumentTitle();
264
Sean McCullough86b56862025-04-18 13:04:03 -0700265 // Initialize the data manager
266 this.dataManager.initialize();
267 }
268
269 // See https://lit.dev/docs/components/lifecycle/
270 disconnectedCallback() {
271 super.disconnectedCallback();
Pokey Rulee2a8c2f2025-04-23 15:09:25 +0100272 window.removeEventListener("popstate", this._handlePopState);
Sean McCullough86b56862025-04-18 13:04:03 -0700273
274 // Remove event listeners
Pokey Rulee2a8c2f2025-04-23 15:09:25 +0100275 window.removeEventListener("view-mode-select", this._handleViewModeSelect);
Pokey Rulee2a8c2f2025-04-23 15:09:25 +0100276 window.removeEventListener("show-commit-diff", this._handleShowCommitDiff);
Sean McCullough86b56862025-04-18 13:04:03 -0700277
278 // unregister data manager event listeners
279 this.dataManager.removeEventListener(
280 "dataChanged",
Philip Zeyliger72682df2025-04-23 13:09:46 -0700281 this.handleDataChanged.bind(this),
Sean McCullough86b56862025-04-18 13:04:03 -0700282 );
283 this.dataManager.removeEventListener(
284 "connectionStatusChanged",
Philip Zeyliger72682df2025-04-23 13:09:46 -0700285 this.handleConnectionStatusChanged.bind(this),
Sean McCullough86b56862025-04-18 13:04:03 -0700286 );
287
288 // Disconnect mutation observer if it exists
289 if (this.mutationObserver) {
Sean McCullough86b56862025-04-18 13:04:03 -0700290 this.mutationObserver.disconnect();
291 this.mutationObserver = null;
292 }
293 }
294
Sean McCullough71941bd2025-04-18 13:31:48 -0700295 updateUrlForViewMode(mode: "chat" | "diff" | "charts" | "terminal"): void {
Sean McCullough86b56862025-04-18 13:04:03 -0700296 // Get the current URL without search parameters
297 const url = new URL(window.location.href);
298
299 // Clear existing parameters
300 url.search = "";
301
302 // Only add view parameter if not in default chat view
303 if (mode !== "chat") {
304 url.searchParams.set("view", mode);
Sean McCullough71941bd2025-04-18 13:31:48 -0700305 const diffView = this.shadowRoot?.querySelector(
Philip Zeyliger72682df2025-04-23 13:09:46 -0700306 ".diff-view",
Sean McCullough71941bd2025-04-18 13:31:48 -0700307 ) as SketchDiffView;
Sean McCullough86b56862025-04-18 13:04:03 -0700308
309 // If in diff view and there's a commit hash, include that too
310 if (mode === "diff" && diffView.commitHash) {
311 url.searchParams.set("commit", diffView.commitHash);
312 }
313 }
314
315 // Update the browser history without reloading the page
316 window.history.pushState({ mode }, "", url.toString());
317 }
318
Pokey Rulee2a8c2f2025-04-23 15:09:25 +0100319 private _handlePopState(event: PopStateEvent) {
Sean McCullough86b56862025-04-18 13:04:03 -0700320 if (event.state && event.state.mode) {
321 this.toggleViewMode(event.state.mode, false);
322 } else {
323 this.toggleViewMode("chat", false);
324 }
325 }
326
327 /**
328 * Handle view mode selection event
329 */
330 private _handleViewModeSelect(event: CustomEvent) {
331 const mode = event.detail.mode as "chat" | "diff" | "charts" | "terminal";
332 this.toggleViewMode(mode, true);
333 }
334
335 /**
336 * Handle show commit diff event
337 */
338 private _handleShowCommitDiff(event: CustomEvent) {
339 const { commitHash } = event.detail;
340 if (commitHash) {
341 this.showCommitDiff(commitHash);
342 }
343 }
344
345 /**
Sean McCullough86b56862025-04-18 13:04:03 -0700346 * Listen for commit diff event
347 * @param commitHash The commit hash to show diff for
348 */
Pokey Rulee2a8c2f2025-04-23 15:09:25 +0100349 private showCommitDiff(commitHash: string): void {
Sean McCullough86b56862025-04-18 13:04:03 -0700350 // Store the commit hash
351 this.currentCommitHash = commitHash;
352
353 // Switch to diff view
Sean McCullough71941bd2025-04-18 13:31:48 -0700354 this.toggleViewMode("diff", true);
Sean McCullough86b56862025-04-18 13:04:03 -0700355
356 // Wait for DOM update to complete
357 this.updateComplete.then(() => {
358 // Get the diff view component
359 const diffView = this.shadowRoot?.querySelector("sketch-diff-view");
360 if (diffView) {
361 // Call the showCommitDiff method
362 (diffView as any).showCommitDiff(commitHash);
363 }
364 });
365 }
366
367 /**
368 * Toggle between different view modes: chat, diff, charts, terminal
369 */
Pokey Rulee2a8c2f2025-04-23 15:09:25 +0100370 private toggleViewMode(mode: ViewMode, updateHistory: boolean): void {
Sean McCullough86b56862025-04-18 13:04:03 -0700371 // Don't do anything if the mode is already active
372 if (this.viewMode === mode) return;
373
374 // Update the view mode
375 this.viewMode = mode;
376
377 if (updateHistory) {
378 // Update URL with the current view mode
379 this.updateUrlForViewMode(mode);
380 }
381
382 // Wait for DOM update to complete
383 this.updateComplete.then(() => {
384 // Update active view
Pokey Rule46fff972025-04-25 14:57:44 +0100385 const viewContainerInner = this.shadowRoot?.querySelector(
386 "#view-container-inner",
387 );
Sean McCullough86b56862025-04-18 13:04:03 -0700388 const chatView = this.shadowRoot?.querySelector(".chat-view");
389 const diffView = this.shadowRoot?.querySelector(".diff-view");
390 const chartView = this.shadowRoot?.querySelector(".chart-view");
391 const terminalView = this.shadowRoot?.querySelector(".terminal-view");
392
393 // Remove active class from all views
394 chatView?.classList.remove("view-active");
395 diffView?.classList.remove("view-active");
396 chartView?.classList.remove("view-active");
397 terminalView?.classList.remove("view-active");
398
399 // Add/remove diff-active class on view container
400 if (mode === "diff") {
Pokey Rule46fff972025-04-25 14:57:44 +0100401 viewContainerInner?.classList.add("diff-active");
Sean McCullough86b56862025-04-18 13:04:03 -0700402 } else {
Pokey Rule46fff972025-04-25 14:57:44 +0100403 viewContainerInner?.classList.remove("diff-active");
Sean McCullough86b56862025-04-18 13:04:03 -0700404 }
405
406 // Add active class to the selected view
407 switch (mode) {
408 case "chat":
409 chatView?.classList.add("view-active");
410 break;
411 case "diff":
412 diffView?.classList.add("view-active");
413 // Load diff content if we have a diff view
414 const diffViewComp =
415 this.shadowRoot?.querySelector("sketch-diff-view");
416 if (diffViewComp && this.currentCommitHash) {
417 (diffViewComp as any).showCommitDiff(this.currentCommitHash);
418 } else if (diffViewComp) {
419 (diffViewComp as any).loadDiffContent();
420 }
421 break;
422 case "charts":
423 chartView?.classList.add("view-active");
424 break;
425 case "terminal":
426 terminalView?.classList.add("view-active");
427 break;
428 }
429
430 // Update view mode buttons
431 const viewModeSelect = this.shadowRoot?.querySelector(
Philip Zeyliger72682df2025-04-23 13:09:46 -0700432 "sketch-view-mode-select",
Sean McCullough86b56862025-04-18 13:04:03 -0700433 );
434 if (viewModeSelect) {
435 const event = new CustomEvent("update-active-mode", {
436 detail: { mode },
437 bubbles: true,
438 composed: true,
439 });
440 viewModeSelect.dispatchEvent(event);
441 }
442
443 // FIXME: This is a hack to get vega chart in sketch-charts.ts to work properly
444 // When the chart is in the background, its container has a width of 0, so vega
445 // renders width 0 and only changes that width on a resize event.
446 // See https://github.com/vega/react-vega/issues/85#issuecomment-1826421132
447 window.dispatchEvent(new Event("resize"));
448 });
449 }
450
Philip Zeyliger9b999b02025-04-25 16:31:50 +0000451 /**
452 * Updates the document title based on current title and connection status
453 */
454 private updateDocumentTitle(): void {
455 let docTitle = `sk: ${this.title || "untitled"}`;
456
457 // Add red circle emoji if disconnected
458 if (this.connectionStatus === "disconnected") {
459 docTitle += " 🔴";
460 }
461
462 document.title = docTitle;
463 }
464
Sean McCullough86b56862025-04-18 13:04:03 -0700465 private handleDataChanged(eventData: {
466 state: State;
Sean McCulloughd9f13372025-04-21 15:08:49 -0700467 newMessages: AgentMessage[];
Sean McCullough86b56862025-04-18 13:04:03 -0700468 isFirstFetch?: boolean;
469 }): void {
470 const { state, newMessages, isFirstFetch } = eventData;
471
472 // Check if this is the first data fetch or if there are new messages
473 if (isFirstFetch) {
Sean McCullough86b56862025-04-18 13:04:03 -0700474 this.messageStatus = "Initial messages loaded";
475 } else if (newMessages && newMessages.length > 0) {
Sean McCullough86b56862025-04-18 13:04:03 -0700476 this.messageStatus = "Updated just now";
Sean McCullough86b56862025-04-18 13:04:03 -0700477 } else {
478 this.messageStatus = "No new messages";
479 }
480
481 // Update state if we received it
482 if (state) {
483 this.containerState = state;
484 this.title = state.title;
Philip Zeyliger9b999b02025-04-25 16:31:50 +0000485
486 // Update document title when sketch title changes
487 this.updateDocumentTitle();
Sean McCullough86b56862025-04-18 13:04:03 -0700488 }
489
Sean McCullough86b56862025-04-18 13:04:03 -0700490 // Update messages
Pokey Rulee2a8c2f2025-04-23 15:09:25 +0100491 this.messages = aggregateAgentMessages(this.messages, newMessages);
Sean McCullough86b56862025-04-18 13:04:03 -0700492 }
493
494 private handleConnectionStatusChanged(
495 status: ConnectionStatus,
Philip Zeyliger72682df2025-04-23 13:09:46 -0700496 errorMessage?: string,
Sean McCullough86b56862025-04-18 13:04:03 -0700497 ): void {
498 this.connectionStatus = status;
499 this.connectionErrorMessage = errorMessage || "";
Philip Zeyliger9b999b02025-04-25 16:31:50 +0000500
501 // Update document title when connection status changes
502 this.updateDocumentTitle();
Sean McCullough86b56862025-04-18 13:04:03 -0700503 }
504
505 async _sendChat(e: CustomEvent) {
506 console.log("app shell: _sendChat", e);
507 const message = e.detail.message?.trim();
508 if (message == "") {
509 return;
510 }
511 try {
512 // Send the message to the server
513 const response = await fetch("chat", {
514 method: "POST",
515 headers: {
516 "Content-Type": "application/json",
517 },
518 body: JSON.stringify({ message }),
519 });
520
521 if (!response.ok) {
522 const errorData = await response.text();
523 throw new Error(`Server error: ${response.status} - ${errorData}`);
524 }
Sean McCullough86b56862025-04-18 13:04:03 -0700525
Philip Zeyliger73db6052025-04-23 13:09:07 -0700526 // TOOD(philip): If the data manager is getting messages out of order, there's a bug?
Sean McCullough86b56862025-04-18 13:04:03 -0700527 // Reset data manager state to force a full refresh after sending a message
528 // This ensures we get all messages in the correct order
529 // Use private API for now - TODO: add a resetState() method to DataManager
530 (this.dataManager as any).nextFetchIndex = 0;
531 (this.dataManager as any).currentFetchStartIndex = 0;
532
Sean McCullough86b56862025-04-18 13:04:03 -0700533 // // If in diff view, switch to conversation view
534 // if (this.viewMode === "diff") {
535 // await this.toggleViewMode("chat");
536 // }
537
538 // Refresh the timeline data to show the new message
539 await this.dataManager.fetchData();
Sean McCullough86b56862025-04-18 13:04:03 -0700540 } catch (error) {
541 console.error("Error sending chat message:", error);
542 const statusText = document.getElementById("statusText");
543 if (statusText) {
544 statusText.textContent = "Error sending message";
545 }
546 }
547 }
548
Pokey Rule4097e532025-04-24 18:55:28 +0100549 private scrollContainerRef = createRef<HTMLElement>();
550
Sean McCullough86b56862025-04-18 13:04:03 -0700551 render() {
552 return html`
Pokey Rule4097e532025-04-24 18:55:28 +0100553 <div id="top-banner">
Sean McCullough86b56862025-04-18 13:04:03 -0700554 <div class="title-container">
555 <h1 class="banner-title">sketch</h1>
556 <h2 id="chatTitle" class="chat-title">${this.title}</h2>
557 </div>
558
Philip Zeyligere66db3e2025-04-27 15:40:39 +0000559 <!-- Views section with tabs -->
560 <sketch-view-mode-select></sketch-view-mode-select>
561
562 <!-- Container status info -->
Sean McCullough86b56862025-04-18 13:04:03 -0700563 <sketch-container-status
564 .state=${this.containerState}
565 ></sketch-container-status>
566
567 <div class="refresh-control">
Sean McCullough86b56862025-04-18 13:04:03 -0700568 <button id="stopButton" class="refresh-button stop-button">
569 Stop
570 </button>
571
572 <div class="poll-updates">
573 <input type="checkbox" id="pollToggle" checked />
574 <label for="pollToggle">Poll</label>
575 </div>
576
577 <sketch-network-status
578 message=${this.messageStatus}
579 connection=${this.connectionStatus}
580 error=${this.connectionErrorMessage}
581 ></sketch-network-status>
Philip Zeyliger99a9a022025-04-27 15:15:25 +0000582
583 <sketch-call-status
584 .llmCalls=${this.containerState?.outstanding_llm_calls || 0}
585 .toolCalls=${this.containerState?.outstanding_tool_calls || []}
586 ></sketch-call-status>
Sean McCullough86b56862025-04-18 13:04:03 -0700587 </div>
588 </div>
589
Pokey Rule4097e532025-04-24 18:55:28 +0100590 <div id="view-container" ${ref(this.scrollContainerRef)}>
591 <div id="view-container-inner">
592 <div
593 class="chat-view ${this.viewMode === "chat" ? "view-active" : ""}"
594 >
595 <sketch-timeline
596 .messages=${this.messages}
597 .scrollContainer=${this.scrollContainerRef}
598 ></sketch-timeline>
599 </div>
600 <div
601 class="diff-view ${this.viewMode === "diff" ? "view-active" : ""}"
602 >
603 <sketch-diff-view
604 .commitHash=${this.currentCommitHash}
605 ></sketch-diff-view>
606 </div>
607 <div
608 class="chart-view ${this.viewMode === "charts"
609 ? "view-active"
610 : ""}"
611 >
612 <sketch-charts .messages=${this.messages}></sketch-charts>
613 </div>
614 <div
615 class="terminal-view ${this.viewMode === "terminal"
616 ? "view-active"
617 : ""}"
618 >
619 <sketch-terminal></sketch-terminal>
620 </div>
Sean McCullough86b56862025-04-18 13:04:03 -0700621 </div>
622 </div>
623
Pokey Rule4097e532025-04-24 18:55:28 +0100624 <div id="chat-input">
625 <sketch-chat-input @send-chat="${this._sendChat}"></sketch-chat-input>
626 </div>
Sean McCullough86b56862025-04-18 13:04:03 -0700627 `;
628 }
629
630 /**
Sean McCullough86b56862025-04-18 13:04:03 -0700631 * Lifecycle callback when component is first connected to DOM
632 */
633 firstUpdated(): void {
634 if (this.viewMode !== "chat") {
635 return;
636 }
637
638 // Initial scroll to bottom when component is first rendered
639 setTimeout(
640 () => this.scrollTo({ top: this.scrollHeight, behavior: "smooth" }),
Philip Zeyliger72682df2025-04-23 13:09:46 -0700641 50,
Sean McCullough86b56862025-04-18 13:04:03 -0700642 );
643
Sean McCullough71941bd2025-04-18 13:31:48 -0700644 const pollToggleCheckbox = this.renderRoot?.querySelector(
Philip Zeyliger72682df2025-04-23 13:09:46 -0700645 "#pollToggle",
Sean McCullough71941bd2025-04-18 13:31:48 -0700646 ) as HTMLInputElement;
Sean McCullough86b56862025-04-18 13:04:03 -0700647 pollToggleCheckbox?.addEventListener("change", () => {
648 this.dataManager.setPollingEnabled(pollToggleCheckbox.checked);
649 if (!pollToggleCheckbox.checked) {
650 this.connectionStatus = "disabled";
651 this.messageStatus = "Polling stopped";
652 } else {
653 this.messageStatus = "Polling for updates...";
654 }
655 });
656 }
657}
658
659declare global {
660 interface HTMLElementTagNameMap {
661 "sketch-app-shell": SketchAppShell;
662 }
663}