Open History to see the last commit
1import { pullRequestHostOf, type SourceControlProviderKind } from "@t3tools/contracts";
2import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
3import { useProjects, useServerConfigs, useThreadShells } from "~/state/entities";
4import {
5 threadPullRequestKeysEqual,
6 visibleThreadPullRequests,
7} from "@t3tools/shared/threadPullRequests";
8import type {
9 ContextMenuItem,
10 EnvironmentId,
11 PreviewSessionSnapshot,
12 ProjectId,
13 PullRequestState,
14} from "@t3tools/contracts";
15import { getTerminalLabel } from "@t3tools/shared/terminalLabels";
16import {
17 Bot,
18 ChevronDown,
19 ChevronLeft,
20 ChevronRight,
21 FileDiff,
22 Files,
23 GitPullRequest,
24 GitPullRequestArrow,
25 Globe2,
26 Plus,
27 TerminalSquare,
28 Volume2,
29 VolumeOff,
30} from "lucide-react";
31import {
32 type KeyboardEvent as ReactKeyboardEvent,
33 type MouseEvent as ReactMouseEvent,
34 type ReactElement,
35 type ReactNode,
36 useCallback,
37 useEffect,
38 useRef,
39 useState,
40} from "react";
41
42import { isElectron } from "~/env";
43import type { DesktopPreviewOverlay } from "~/previewStateStore";
44import type { RightPanelSurface } from "~/rightPanelStore";
45import { cn } from "~/lib/utils";
46import { readLocalApi } from "~/localApi";
47import { Button } from "~/components/ui/button";
48import { Tooltip, TooltipPopup, TooltipTrigger } from "~/components/ui/tooltip";
49import { Kbd } from "~/components/ui/kbd";
50import {
51 Menu,
52 MenuItem,
53 MenuPopup,
54 MenuShortcut,
55 MenuSub,
56 MenuSubPopup,
57 MenuSubTrigger,
58 MenuTrigger,
59} from "~/components/ui/menu";
60import { useBrowserDefaults } from "~/browser/browserDefaults";
61import { ScrollArea } from "~/components/ui/scroll-area";
62import { PanelTabCloseButton } from "~/components/ui/panel-tab-close-button";
63import { faviconUrlForOrigin } from "~/lib/favicon";
64import { useTheme } from "~/hooks/useTheme";
65import { pullRequestEnvironment } from "~/state/pullRequests";
66import { useEnvironmentQuery } from "~/state/query";
67import { COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS } from "~/workspaceTitlebar";
68
69import { PreviewPanelShell, type PreviewPanelMode } from "./preview/PreviewPanelShell";
70import { FaviconImage } from "./preview/PreviewFaviconIcon";
71import { previewBridge } from "./preview/previewBridge";
72import { PierreEntryIcon } from "./chat/PierreEntryIcon";
73import { resolvePullRequestState } from "./pullRequest/pullRequestPresentation";
74
75interface RightPanelTabsProps {
76 mode: PreviewPanelMode;
77 maximized?: boolean;
78 open?: boolean;
79 /** Forwarded to PreviewPanelShell so this surface persists its own width. */
80 widthStorageKey?: string;
81 /** Forwarded to PreviewPanelShell as the initial width before a user resize. */
82 defaultWidth?: number;
83 layoutControls?: ReactNode;
84 surfaces: readonly RightPanelSurface[];
85 /** Fallback environment for surfaces that do not carry their own. */
86 environmentId: EnvironmentId | null;
87 activeSurfaceId: string | null;
88 pendingSurfaceIds: ReadonlySet<string>;
89 previewSessions: Readonly<Record<string, PreviewSessionSnapshot>>;
90 desktopByTabId: Readonly<Record<string, DesktopPreviewOverlay>>;
91 /**
92 * Maps a server session tab id to the desktop runtime tab id the Electron
93 * preview manager is keyed by. Session ids are only unique within one server
94 * process, so desktop operations must not be addressed with them.
95 */
96 previewRuntimeTabId?: ((tabId: string) => string) | undefined;
97 terminalLabelsById: ReadonlyMap<string, string>;
98 onActivate: (surface: RightPanelSurface) => void;
99 onCloseSurface: (surface: RightPanelSurface) => void;
100 onCloseOtherSurfaces: (surface: RightPanelSurface) => void;
101 onCloseSurfacesToRight: (surface: RightPanelSurface) => void;
102 onCloseAllSurfaces: () => void;
103 onCopyFilePath: (relativePath: string) => void;
104 onAddBrowser: () => void;
105 /**
106 * Separate from `onAddBrowser` on purpose: that one is passed directly as a
107 * DOM click handler, and a `(profileId?: string)` signature would silently
108 * accept the MouseEvent as a profile id.
109 */
110 onAddBrowserInProfile: (profileId: string) => void;
111 onAddTerminal: () => void;
112 onAddDiff: () => void;
113 onAddFiles: () => void;
114 onAddPullRequest: () => void;
115 onAddPullRequests: () => void;
116 onAddAgents: () => void;
117 browserAvailable: boolean;
118 terminalAvailable: boolean;
119 diffAvailable: boolean;
120 filesAvailable: boolean;
121 pullRequestAvailable: boolean;
122 pullRequestsAvailable: boolean;
123 agentsAvailable: boolean;
124 pullRequestStatusSeeds?: Readonly<Record<string, PullRequestTabStatusSeed>>;
125 /** Running + waiting subagents; badges the Agents card in the empty state. */
126 liveAgentCount: number;
127 children: ReactNode;
128}
129
130export interface PullRequestTabStatus {
131 projectId: string;
132 repository: string;
133 number: number;
134 state: PullRequestState;
135 isDraft: boolean;
136}
137
138export type PullRequestTabStatusSeed = Pick<PullRequestTabStatus, "state" | "isDraft">;
139
140export function shouldOpenDefaultBrowserProfileFromMenuClick(
141 pointerType: string | undefined,
142): boolean {
143 return pointerType !== "touch";
144}
145
146const SURFACE_DISABLED_REASONS = {
147 browser: "Browser previews are only available in the T3 Code desktop app.",
148 terminal: "Terminal surfaces are only available from a project thread.",
149 files: "Files are only available when a project is open.",
150 diff: "Diff is only available for server threads in Git repositories.",
151 pullRequest: "This thread's branch has no pull request yet.",
152 pullRequests: "Linked pull requests are only available for server threads.",
153 agents: "Agents are only available from a thread.",
154} as const;
155
156/** Overlays that must win over the launcher's letter shortcuts. */
157const LAUNCHER_SHORTCUT_BLOCKING_LAYERS = [
158 '[data-slot="dialog-popup"]',
159 '[data-slot="alert-dialog-popup"]',
160 '[data-slot="command-dialog-popup"]',
161 '[data-slot="menu-popup"]',
162 '[data-slot="select-popup"]',
163 '[data-slot="popover-popup"]',
164 '[data-slot="combobox-popup"]',
165 '[data-slot="autocomplete-popup"]',
166].join(",");
167
168/** One-line unavailability hints for the empty-state cards. */
169const SURFACE_UNAVAILABLE_HINTS = {
170 browser: "Only available in the desktop app.",
171 terminal: "Available when a project is open.",
172 files: "Available when a project is open.",
173 diff: "Available for Git repositories.",
174 pullRequest: "No pull request on this branch yet.",
175 pullRequests: "Available for server threads.",
176 agents: "Available from a thread.",
177} as const;
178
179type TabContextMenuAction =
180 | "copy-path"
181 | "toggle-mute"
182 | "close"
183 | "close-others"
184 | "close-to-right"
185 | "close-all";
186
187const TAB_SCROLL_EDGE_TOLERANCE = 1;
188
189function tabScrollViewport(root: HTMLDivElement | null): HTMLDivElement | null {
190 return root?.querySelector<HTMLDivElement>('[data-slot="scroll-area-viewport"]') ?? null;
191}
192
193/**
194 * Desktop preview tab backing a surface, or null for non-preview surfaces, the
195 * "new browser tab" placeholder, and the web build where no desktop tab exists.
196 */
197function previewTabIdOf(
198 surface: RightPanelSurface,
199 sessions: Readonly<Record<string, PreviewSessionSnapshot>>,
200): string | null {
201 if (surface.kind !== "preview" || !surface.resourceId) return null;
202 return sessions[surface.resourceId]?.tabId ?? null;
203}
204
205/**
206 * Label and enabled state for a preview tab's mute menu entry.
207 * Stays disabled until desktop overlay state arrives: a server session id can
208 * resolve while the preview manager's createTab is still in flight, and muting
209 * then fails with a PreviewTabNotFoundError nothing surfaces to the user.
210 */
211export function tabMuteMenuItem(input: {
212 overlay: DesktopPreviewOverlay | null;
213 canResolveRuntimeTabId: boolean;
214}): { label: string; disabled: boolean } {
215 const muted = input.overlay?.audioMuted ?? false;
216 return {
217 label: muted ? "Unmute tab" : "Mute tab",
218 disabled: input.overlay === null || !input.canResolveRuntimeTabId,
219 };
220}
221
222type TabAudioState = "none" | "audible" | "muted";
223
224/**
225 * A muted tab that is not making sound shows nothing: mute is armed silently,
226 * and the indicator only appears once there is audio to speak of.
227 */
228function tabAudioState(overlay: DesktopPreviewOverlay | null): TabAudioState {
229 if (!overlay?.audible) return "none";
230 return overlay.audioMuted ? "muted" : "audible";
231}
232
233type SurfaceShortcutEvent = Pick<
234 KeyboardEvent,
235 "altKey" | "ctrlKey" | "defaultPrevented" | "isComposing" | "key" | "metaKey"
236>;
237
238export function surfaceShortcutActionForKey<
239 const Action extends { available: boolean; shortcut: string },
240>(actions: readonly Action[], event: SurfaceShortcutEvent): Action | null {
241 if (event.defaultPrevented || event.isComposing) return null;
242 if (event.metaKey || event.ctrlKey || event.altKey) return null;
243 return (
244 actions.find(
245 (action) => action.available && action.shortcut.toLowerCase() === event.key.toLowerCase(),
246 ) ?? null
247 );
248}
249
250/**
251 * A focused editable is a typing context whether or not it has text yet: an
252 * empty chat composer at rest is still where the user's next keystrokes are
253 * meant to land, and claiming launcher letters from it would redirect prompts
254 * into whatever surface opens. The `:not` clause lets `closest` see past
255 * non-editable islands (`contenteditable="false"`) to an editable host around
256 * them, matching ComposerPendingUserInputPanel's typing guard.
257 */
258export function surfaceShortcutTargetsTypingContext(
259 target: { closest(selectors: string): unknown } | null,
260): boolean {
261 return (
262 target?.closest('input, textarea, select, [contenteditable]:not([contenteditable="false"])') !=
263 null
264 );
265}
266
267function DisabledReasonTooltip(props: { reason: string; trigger: ReactElement }) {
268 return (
269 <Tooltip>
270 <TooltipTrigger render={props.trigger} />
271 <TooltipPopup side="top">{props.reason}</TooltipPopup>
272 </Tooltip>
273 );
274}
275
276function SurfaceMenuItem(props: {
277 available: boolean;
278 disabledReason?: string;
279 shortcut: string;
280 onClick: () => void;
281 children: ReactNode;
282}) {
283 const item = (
284 <MenuItem
285 className={!props.available ? "data-disabled:pointer-events-auto" : undefined}
286 onClick={props.onClick}
287 disabled={!props.available}
288 aria-keyshortcuts={props.shortcut}
289 >
290 {props.children}
291 <MenuShortcut>{props.shortcut}</MenuShortcut>
292 </MenuItem>
293 );
294 if (props.available || !props.disabledReason) return item;
295 return <DisabledReasonTooltip reason={props.disabledReason} trigger={item} />;
296}
297
298/**
299 * Card launcher shown when the right panel has no surfaces. Keyboard-first
300 * without palette chrome: a surface's letter opens it directly from anywhere
301 * outside a typing context, and arrows plus Enter work while the launcher is
302 * focused. The highlight only appears on hover or arrow use. Unavailable
303 * surfaces stay visible with a one-line reason.
304 */
305function RightPanelEmptyState(props: {
306 onAddBrowser: () => void;
307 onAddBrowserInProfile: (profileId: string) => void;
308 browserProfiles: ReadonlyArray<{ readonly id: string; readonly name: string }>;
309 onAddTerminal: () => void;
310 onAddDiff: () => void;
311 onAddFiles: () => void;
312 onAddPullRequest: () => void;
313 onAddPullRequests: () => void;
314 onAddAgents: () => void;
315 browserAvailable: boolean;
316 terminalAvailable: boolean;
317 diffAvailable: boolean;
318 filesAvailable: boolean;
319 pullRequestAvailable: boolean;
320 pullRequestsAvailable: boolean;
321 agentsAvailable: boolean;
322 liveAgentCount: number;
323}) {
324 // -1 means no highlight: it only appears on hover or arrow use.
325 const [highlight, setHighlight] = useState(-1);
326
327 const actions = [
328 {
329 label: "Browser",
330 description: "Open a local app or URL.",
331 icon: Globe2,
332 shortcut: "B",
333 available: props.browserAvailable,
334 disabledReason: SURFACE_UNAVAILABLE_HINTS.browser,
335 onClick: props.onAddBrowser,
336 badgeCount: 0,
337 },
338 {
339 label: "Terminal",
340 description: "Start a shell in this workspace.",
341 icon: TerminalSquare,
342 shortcut: "T",
343 available: props.terminalAvailable,
344 disabledReason: SURFACE_UNAVAILABLE_HINTS.terminal,
345 onClick: props.onAddTerminal,
346 badgeCount: 0,
347 },
348 {
349 label: "Files",
350 description: "Browse and read workspace files.",
351 icon: Files,
352 shortcut: "F",
353 available: props.filesAvailable,
354 disabledReason: SURFACE_UNAVAILABLE_HINTS.files,
355 onClick: props.onAddFiles,
356 badgeCount: 0,
357 },
358 {
359 label: "Diff",
360 description: "Review changes in this thread.",
361 icon: FileDiff,
362 shortcut: "D",
363 available: props.diffAvailable,
364 disabledReason: SURFACE_UNAVAILABLE_HINTS.diff,
365 onClick: props.onAddDiff,
366 badgeCount: 0,
367 },
368 {
369 label: "Pull request",
370 description: "Open this branch's pull request.",
371 icon: GitPullRequest,
372 shortcut: "P",
373 available: props.pullRequestAvailable,
374 disabledReason: SURFACE_UNAVAILABLE_HINTS.pullRequest,
375 onClick: props.onAddPullRequest,
376 badgeCount: 0,
377 },
378 {
379 label: "Linked pull requests",
380 description: "Every pull request this thread has linked, stacks included.",
381 icon: GitPullRequestArrow,
382 shortcut: "L",
383 available: props.pullRequestsAvailable,
384 disabledReason: SURFACE_UNAVAILABLE_HINTS.pullRequests,
385 onClick: props.onAddPullRequests,
386 badgeCount: 0,
387 },
388 {
389 label: "Agents",
390 description: "Follow subagents and workflows.",
391 icon: Bot,
392 shortcut: "A",
393 available: props.agentsAvailable,
394 disabledReason: SURFACE_UNAVAILABLE_HINTS.agents,
395 onClick: props.onAddAgents,
396 badgeCount: props.liveAgentCount,
397 },
398 ] as const;
399
400 type SurfaceAction = (typeof actions)[number];
401
402 const availableActions = actions.filter((action) => action.available);
403 const highlightIndex =
404 availableActions.length === 0 ? -1 : Math.min(highlight, availableActions.length - 1);
405
406 // Letter shortcuts work while the launcher is visible, not only while it
407 // is focused; focus moves around too easily (stray clicks) to carry them.
408 // Capture phase so app-level key handlers cannot swallow the event first;
409 // typing contexts and already-handled events are left alone.
410 const shortcutActionsRef = useRef(availableActions);
411 useEffect(() => {
412 shortcutActionsRef.current = availableActions;
413 });
414 useEffect(() => {
415 const handler = (event: KeyboardEvent) => {
416 const action = surfaceShortcutActionForKey(shortcutActionsRef.current, event);
417 if (!action) return;
418 if (document.querySelector(LAUNCHER_SHORTCUT_BLOCKING_LAYERS)) return;
419 const target = event.target;
420 if (target instanceof Element && surfaceShortcutTargetsTypingContext(target)) return;
421 event.preventDefault();
422 event.stopPropagation();
423 action.onClick();
424 };
425 window.addEventListener("keydown", handler, true);
426 return () => window.removeEventListener("keydown", handler, true);
427 }, []);
428
429 const handleKeyDown = (event: ReactKeyboardEvent<HTMLDivElement>) => {
430 if (event.defaultPrevented || event.metaKey || event.ctrlKey || event.altKey) return;
431 if (availableActions.length === 0) return;
432 if (event.key === "ArrowDown" || event.key === "ArrowRight") {
433 event.preventDefault();
434 setHighlight((highlightIndex + 1) % availableActions.length);
435 return;
436 }
437 if (event.key === "ArrowUp" || event.key === "ArrowLeft") {
438 event.preventDefault();
439 setHighlight(
440 highlightIndex === -1
441 ? availableActions.length - 1
442 : (highlightIndex - 1 + availableActions.length) % availableActions.length,
443 );
444 return;
445 }
446 if (event.key === "Enter") {
447 // A focused card button owns its own activation; only open from the
448 // highlight when the container itself has focus.
449 if (event.target instanceof HTMLElement && event.target.closest("button")) return;
450 const action = availableActions[highlightIndex];
451 if (!action) return;
452 event.preventDefault();
453 action.onClick();
454 }
455 };
456
457 // Stable identity so React only runs this callback ref on mount/unmount;
458 // an inline arrow would re-attach and re-focus on every render.
459 const focusOnMount = useCallback((node: HTMLDivElement | null) => {
460 node?.focus();
461 }, []);
462
463 const isHighlighted = (action: SurfaceAction) =>
464 highlightIndex !== -1 && availableActions[highlightIndex] === action;
465
466 const actionIcon = (action: SurfaceAction, iconClassName = "size-4") => {
467 const Icon = action.icon;
468 return (
469 <span className="relative inline-flex shrink-0">
470 <Icon className={iconClassName} />
471 {action.badgeCount > 0 ? (
472 <span
473 aria-hidden
474 className="absolute -top-1.5 -right-2 flex h-3.5 min-w-3.5 items-center justify-center rounded-full bg-info px-1 text-[9px] font-semibold tabular-nums text-white"
475 >
476 {action.badgeCount}
477 </span>
478 ) : null}
479 </span>
480 );
481 };
482
483 const cardShellClass =
484 "rounded-lg border border-border/80 bg-card dark:border-transparent dark:shadow-none dark:inset-ring-1 dark:inset-ring-white/5";
485 const highlightedCardClass = "bg-accent/60 dark:inset-ring-white/20";
486
487 return (
488 <div
489 ref={focusOnMount}
490 tabIndex={0}
491 onKeyDown={handleKeyDown}
492 aria-label="Open a surface"
493 data-surface-launcher-keys={availableActions.map((action) => action.shortcut).join("")}
494 className={cn(
495 "flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-6 pt-6 outline-none",
496 // The panel topbar sits above this container; matching bottom padding
497 // keeps the cards centered against the full panel, not the leftover.
498 "pb-[calc(var(--workspace-topbar-height)+--spacing(6))]",
499 )}
500 >
501 <div className="relative w-full max-w-lg">
502 <div className="absolute inset-x-0 bottom-full mb-5 text-center">
503 <h3 className="font-medium text-foreground text-sm">Open a surface</h3>
504 <p className="mt-1 text-muted-foreground text-xs">
505 Choose what to show in the right panel.
506 </p>
507 </div>
508 <div className="grid grid-cols-2 gap-2">
509 {actions.map((action) =>
510 action.available ? (
511 // The card is itself a button, so the profile chooser sits beside
512 // it in a wrapper rather than inside it. Hover lives on the
513 // wrapper: the chooser overlays the card, and a pointer moving
514 // onto it must not read as leaving the card.
515 <div
516 key={action.label}
517 className="group relative"
518 onMouseEnter={() => setHighlight(availableActions.indexOf(action))}
519 onMouseLeave={() =>
520 setHighlight((current) =>
521 current === availableActions.indexOf(action) ? -1 : current,
522 )
523 }
524 >
525 <button
526 type="button"
527 onClick={action.onClick}
528 className={cn(
529 // Full height: the wrapper is the grid item that stretches
530 // to the row, so the button must fill it to stay level with
531 // its neighbour and keep the chooser anchored inside.
532 "relative flex h-full w-full cursor-pointer flex-col items-start p-4 text-left transition group-hover:border-border group-hover:bg-accent/60",
533 cardShellClass,
534 isHighlighted(action) && highlightedCardClass,
535 )}
536 >
537 <Kbd className="absolute top-3 right-3">{action.shortcut}</Kbd>
538 <span className="flex items-center gap-2 pe-8">
539 {actionIcon(action)}
540 <span className="font-medium text-sm">{action.label}</span>
541 </span>
542 <span className="mt-1.5 text-muted-foreground text-xs leading-relaxed">
543 {action.description}
544 </span>
545 </button>
546 {/*
547 Same choice the tab bar's "+" menu offers: the card opens the
548 default profile, the chevron picks another. Only worth showing
549 once there is something to choose between.
550 */}
551 {action.label === "Browser" && props.browserProfiles.length > 1 ? (
552 <Menu>
553 <MenuTrigger
554 render={
555 <Button
556 aria-label="Open browser in a profile"
557 className="absolute right-3 bottom-3 [--control-icon-color:currentColor]"
558 size="icon-xs"
559 variant="ghost-muted"
560 />
561 }
562 >
563 <ChevronDown className="size-3.5" />
564 </MenuTrigger>
565 <MenuPopup
566 align="end"
567 side="bottom"
568 sideOffset={6}
569 className="min-w-40 max-w-56"
570 >
571 {props.browserProfiles.map((profile) => (
572 <MenuItem
573 key={profile.id}
574 onClick={() => props.onAddBrowserInProfile(profile.id)}
575 >
576 <span className="min-w-0 truncate">{profile.name}</span>
577 </MenuItem>
578 ))}
579 </MenuPopup>
580 </Menu>
581 ) : null}
582 </div>
583 ) : (
584 <div
585 key={action.label}
586 className={cn(
587 "relative flex w-full flex-col items-start p-4 opacity-40",
588 cardShellClass,
589 )}
590 >
591 <Kbd className="absolute top-3 right-3">{action.shortcut}</Kbd>
592 <span className="flex items-center gap-2 pe-8">
593 {actionIcon(action)}
594 <span className="font-medium text-sm">{action.label}</span>
595 </span>
596 <span className="mt-1.5 text-muted-foreground text-xs leading-relaxed">
597 {action.disabledReason}
598 </span>
599 </div>
600 ),
601 )}
602 </div>
603 </div>
604 </div>
605 );
606}
607
608function surfaceTitle(
609 surface: RightPanelSurface,
610 sessions: Readonly<Record<string, PreviewSessionSnapshot>>,
611 terminalLabelsById: ReadonlyMap<string, string>,
612): string {
613 switch (surface.kind) {
614 case "diff":
615 return "Diff";
616 case "files":
617 return "Files";
618 case "file":
619 return surface.relativePath.slice(
620 Math.max(surface.relativePath.lastIndexOf("/"), surface.relativePath.lastIndexOf("\\")) + 1,
621 );
622 case "terminal":
623 return (
624 terminalLabelsById.get(surface.activeTerminalId) ??
625 getTerminalLabel(surface.activeTerminalId)
626 );
627 case "pull-request":
628 return `#${surface.number}`;
629 case "pull-requests":
630 return "Pull requests";
631 case "agents":
632 return "Agents";
633 case "preview": {
634 const snapshot = surface.resourceId ? sessions[surface.resourceId] : null;
635 if (!snapshot || snapshot.navStatus._tag === "Idle") return "Browser";
636 if (snapshot.navStatus.title.trim().length > 0) return snapshot.navStatus.title;
637 try {
638 return new URL(snapshot.navStatus.url).host || "Browser";
639 } catch {
640 return "Browser";
641 }
642 }
643 }
644}
645
646function PreviewFavicon({ capturedUrl, url }: { capturedUrl: string | null; url: string | null }) {
647 const publicProviderUrl = faviconUrlForOrigin(url, 32);
648 return (
649 <FaviconImage
650 sources={[capturedUrl, publicProviderUrl]}
651 fallback={<Globe2 className="size-3 shrink-0" />}
652 className="size-3 shrink-0 rounded-sm object-contain"
653 />
654 );
655}
656
657function sameOrigin(left: string, right: string): boolean {
658 try {
659 return new URL(left).origin === new URL(right).origin;
660 } catch {
661 return false;
662 }
663}
664
665function SurfaceIcon({
666 surface,
667 sessions,
668 desktopByTabId,
669 theme,
670 environmentId,
671 pullRequestStatusSeeds,
672}: {
673 surface: RightPanelSurface;
674 sessions: Readonly<Record<string, PreviewSessionSnapshot>>;
675 desktopByTabId: Readonly<Record<string, DesktopPreviewOverlay>>;
676 theme: "light" | "dark";
677 environmentId: EnvironmentId | null;
678 pullRequestStatusSeeds: Readonly<Record<string, PullRequestTabStatusSeed>> | undefined;
679}) {
680 switch (surface.kind) {
681 case "preview": {
682 const snapshot = surface.resourceId ? sessions[surface.resourceId] : null;
683 const url = !snapshot || snapshot.navStatus._tag === "Idle" ? null : snapshot.navStatus.url;
684 const favicon = snapshot ? (desktopByTabId[snapshot.tabId]?.favicon ?? null) : null;
685 const capturedUrl =
686 favicon && url && sameOrigin(favicon.pageUrl, url) ? favicon.dataUrl : null;
687 return <PreviewFavicon capturedUrl={capturedUrl} url={url} />;
688 }
689 case "diff":
690 return <FileDiff className="size-3 shrink-0" />;
691 case "files":
692 return <Files className="size-3 shrink-0" />;
693 case "file":
694 return (
695 <PierreEntryIcon
696 pathValue={surface.relativePath}
697 kind="file"
698 theme={theme}
699 className="size-3"
700 />
701 );
702 case "terminal":
703 return <TerminalSquare className="size-3 shrink-0" />;
704 case "pull-request":
705 return (
706 <PullRequestSurfaceIcon
707 surface={surface}
708 environmentId={environmentId}
709 seed={pullRequestStatusSeeds?.[surface.id]}
710 />
711 );
712 case "pull-requests":
713 return <GitPullRequestArrow className="size-3 shrink-0" />;
714 case "agents":
715 return <Bot className="size-3 shrink-0" />;
716 }
717}
718
719export function resolvePullRequestTabLink(
720 threads: readonly Pick<EnvironmentThreadShell, "environmentId" | "pullRequests">[],
721 environmentId: EnvironmentId | null,
722 host: string | null,
723 reference: { repository: string; number: number },
724) {
725 if (environmentId === null || host === null) return undefined;
726 let newest: EnvironmentThreadShell["pullRequests"][number] | undefined;
727 for (const thread of threads) {
728 if (thread.environmentId !== environmentId) continue;
729 for (const link of visibleThreadPullRequests(thread.pullRequests)) {
730 if (
731 !threadPullRequestKeysEqual(link, {
732 host,
733 repository: reference.repository,
734 number: reference.number,
735 })
736 )
737 continue;
738 if (
739 newest === undefined ||
740 (link.snapshot?.syncedAt ?? "") > (newest.snapshot?.syncedAt ?? "")
741 )
742 newest = link;
743 }
744 }
745 return newest;
746}
747
748function PullRequestSurfaceIcon({
749 surface,
750 environmentId,
751 seed,
752}: {
753 surface: Extract<RightPanelSurface, { kind: "pull-request" }>;
754 environmentId: EnvironmentId | null;
755 seed: PullRequestTabStatusSeed | undefined;
756}) {
757 const resolvedEnvironmentId =
758 (surface.environmentId as EnvironmentId | undefined) ?? environmentId;
759 const projects = useProjects();
760 const threads = useThreadShells();
761 const project = projects.find(
762 (entry) => entry.environmentId === resolvedEnvironmentId && entry.id === surface.projectId,
763 );
764 const identity = project?.repositoryIdentity;
765 const host =
766 surface.host ??
767 (identity?.provider
768 ? pullRequestHostOf(identity, identity.provider as SourceControlProviderKind)
769 : null);
770 const configs = useServerConfigs();
771 const capabilities =
772 resolvedEnvironmentId === null
773 ? undefined
774 : configs.get(resolvedEnvironmentId)?.environment.capabilities;
775 const linkedSnapshot =
776 capabilities?.threadPullRequests === true
777 ? (resolvePullRequestTabLink(threads, resolvedEnvironmentId, host, surface)?.snapshot ?? null)
778 : null;
779 const detail = useEnvironmentQuery(
780 resolvedEnvironmentId === null || capabilities?.pullRequests !== true || linkedSnapshot !== null
781 ? null
782 : pullRequestEnvironment.detail({
783 environmentId: resolvedEnvironmentId,
784 input: {
785 projectId: surface.projectId as ProjectId,
786 ...(capabilities?.threadPullRequests === true && surface.host !== undefined
787 ? { host: surface.host }
788 : {}),
789 repository: surface.repository,
790 number: surface.number,
791 },
792 }),
793 ).data;
794 // Only state and draft reach the tab. A list seed cannot know mergeability, so feeding the
795 // full detail would flip an open tab to the conflict glyph the moment its read lands.
796 const status =
797 linkedSnapshot !== null
798 ? linkedSnapshot
799 : detail === null
800 ? (seed ?? null)
801 : { state: detail.state, isDraft: detail.isDraft };
802 if (status === null) {
803 return <GitPullRequest className="size-3 shrink-0 text-muted-foreground" />;
804 }
805 const presentation = resolvePullRequestState({ state: status.state, isDraft: status.isDraft });
806 return <presentation.Icon className={cn("size-3 shrink-0", presentation.toneClassName)} />;
807}
808
809export function RightPanelTabs(props: RightPanelTabsProps) {
810 const ownsDesktopTitleBar = isElectron && props.mode === "inline";
811 const browserProfiles = useBrowserDefaults().profiles;
812 const { resolvedTheme } = useTheme();
813 const tabListRef = useRef<HTMLDivElement>(null);
814 const [addSurfaceMenuOpen, setAddSurfaceMenuOpen] = useState(false);
815 const [tabScrollState, setTabScrollState] = useState({
816 hasOverflow: false,
817 canScrollLeft: false,
818 canScrollRight: false,
819 });
820
821 const updateTabScrollState = useCallback(() => {
822 const viewport = tabScrollViewport(tabListRef.current);
823 if (!viewport) return;
824
825 const hasOverflow = viewport.scrollWidth - viewport.clientWidth > TAB_SCROLL_EDGE_TOLERANCE;
826 const canScrollLeft = hasOverflow && viewport.scrollLeft > TAB_SCROLL_EDGE_TOLERANCE;
827 const canScrollRight =
828 hasOverflow &&
829 viewport.scrollLeft + viewport.clientWidth < viewport.scrollWidth - TAB_SCROLL_EDGE_TOLERANCE;
830 setTabScrollState((current) => {
831 if (
832 current.hasOverflow === hasOverflow &&
833 current.canScrollLeft === canScrollLeft &&
834 current.canScrollRight === canScrollRight
835 ) {
836 return current;
837 }
838 return { hasOverflow, canScrollLeft, canScrollRight };
839 });
840 }, []);
841
842 const scrollTabs = useCallback((direction: -1 | 1) => {
843 const viewport = tabScrollViewport(tabListRef.current);
844 if (!viewport) return;
845 const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
846 viewport.scrollBy({
847 left: direction * Math.max(120, viewport.clientWidth * 0.75),
848 behavior: reduceMotion ? "auto" : "smooth",
849 });
850 }, []);
851
852 const addSurfaceActions = [
853 {
854 label: "Browser",
855 icon: Globe2,
856 shortcut: "B",
857 available: props.browserAvailable,
858 disabledReason: SURFACE_DISABLED_REASONS.browser,
859 onClick: props.onAddBrowser,
860 },
861 {
862 label: "Terminal",
863 icon: TerminalSquare,
864 shortcut: "T",
865 available: props.terminalAvailable,
866 disabledReason: SURFACE_DISABLED_REASONS.terminal,
867 onClick: props.onAddTerminal,
868 },
869 {
870 label: "Files",
871 icon: Files,
872 shortcut: "F",
873 available: props.filesAvailable,
874 disabledReason: SURFACE_DISABLED_REASONS.files,
875 onClick: props.onAddFiles,
876 },
877 {
878 label: "Diff",
879 icon: FileDiff,
880 shortcut: "D",
881 available: props.diffAvailable,
882 disabledReason: SURFACE_DISABLED_REASONS.diff,
883 onClick: props.onAddDiff,
884 },
885 {
886 label: "Pull request",
887 icon: GitPullRequest,
888 shortcut: "P",
889 available: props.pullRequestAvailable,
890 disabledReason: SURFACE_DISABLED_REASONS.pullRequest,
891 onClick: props.onAddPullRequest,
892 },
893 {
894 label: "Linked pull requests",
895 icon: GitPullRequestArrow,
896 shortcut: "L",
897 available: props.pullRequestsAvailable,
898 disabledReason: SURFACE_DISABLED_REASONS.pullRequests,
899 onClick: props.onAddPullRequests,
900 },
901 {
902 label: "Agents",
903 icon: Bot,
904 shortcut: "A",
905 available: props.agentsAvailable,
906 disabledReason: SURFACE_DISABLED_REASONS.agents,
907 onClick: props.onAddAgents,
908 },
909 ] as const;
910
911 const handleAddSurfaceMenuKeyDown = (event: ReactKeyboardEvent<HTMLDivElement>) => {
912 const action = surfaceShortcutActionForKey(addSurfaceActions, event.nativeEvent);
913 if (!action) return;
914 event.preventDefault();
915 event.stopPropagation();
916 setAddSurfaceMenuOpen(false);
917 action.onClick();
918 };
919
920 const handleTabContextMenu = useCallback(
921 async (event: ReactMouseEvent, surface: RightPanelSurface) => {
922 event.preventDefault();
923 event.stopPropagation();
924
925 const api = readLocalApi();
926 if (!api) return;
927
928 const surfaceIndex = props.surfaces.findIndex((entry) => entry.id === surface.id);
929 if (surfaceIndex < 0) return;
930
931 const items: ContextMenuItem<TabContextMenuAction>[] = [];
932 if (surface.kind === "file" && surface.attachment === undefined) {
933 items.push({ id: "copy-path", label: "Copy path" });
934 }
935 const menuPreviewTabId = previewTabIdOf(surface, props.previewSessions);
936 // Desktop overlay state only arrives once the preview manager has created
937 // the tab. A server session id alone can still be ahead of that, and
938 // muting then fails with PreviewTabNotFoundError that nobody surfaces.
939 const menuOverlay = menuPreviewTabId
940 ? (props.desktopByTabId[menuPreviewTabId] ?? null)
941 : null;
942 const menuMuted = menuOverlay?.audioMuted ?? false;
943 if (surface.kind === "preview") {
944 // Not gated on audibility: silencing a quiet tab ahead of time is the
945 // point, so the item is offered whenever the tab is mutable at all.
946 items.push({
947 id: "toggle-mute",
948 ...tabMuteMenuItem({
949 overlay: menuOverlay,
950 canResolveRuntimeTabId: props.previewRuntimeTabId !== undefined,
951 }),
952 });
953 }
954 items.push(
955 { id: "close", label: "Close" },
956 {
957 id: "close-others",
958 label: "Close others",
959 disabled: props.surfaces.length <= 1,
960 },
961 {
962 id: "close-to-right",
963 label: "Close to the right",
964 disabled: surfaceIndex >= props.surfaces.length - 1,
965 },
966 {
967 id: "close-all",
968 label: "Close all",
969 disabled: props.surfaces.length === 0,
970 },
971 );
972
973 const action = await api.contextMenu.show(items, { x: event.clientX, y: event.clientY });
974 switch (action) {
975 case "copy-path":
976 if (surface.kind === "file" && surface.attachment === undefined) {
977 props.onCopyFilePath(surface.relativePath);
978 }
979 break;
980 case "toggle-mute": {
981 // menuOverlay repeats the disabled gate above: the desktop tab must
982 // exist before it can be addressed, however the menu was dismissed.
983 const runtimeTabId =
984 menuPreviewTabId && menuOverlay
985 ? (props.previewRuntimeTabId?.(menuPreviewTabId) ?? null)
986 : null;
987 if (runtimeTabId) {
988 void previewBridge?.setAudioMuted(runtimeTabId, !menuMuted).catch(() => undefined);
989 }
990 break;
991 }
992 case "close":
993 props.onCloseSurface(surface);
994 break;
995 case "close-others":
996 props.onCloseOtherSurfaces(surface);
997 break;
998 case "close-to-right":
999 props.onCloseSurfacesToRight(surface);
1000 break;
1001 case "close-all":
1002 props.onCloseAllSurfaces();
1003 break;
1004 case null:
1005 break;
1006 }
1007 },
1008 [props],
1009 );
1010 const handleTabMouseDown = useCallback((event: ReactMouseEvent) => {
1011 if (event.button !== 1) return;
1012 event.preventDefault();
1013 }, []);
1014 const handleTabAuxClick = useCallback(
1015 (event: ReactMouseEvent, surface: RightPanelSurface) => {
1016 if (event.button !== 1) return;
1017 event.preventDefault();
1018 event.stopPropagation();
1019 props.onCloseSurface(surface);
1020 },
1021 [props],
1022 );
1023
1024 useEffect(() => {
1025 if (!props.activeSurfaceId || !tabScrollState.hasOverflow) return;
1026 const activeTab = tabListRef.current?.querySelector<HTMLElement>("[data-active-tab='true']");
1027 activeTab?.scrollIntoView({ block: "nearest", inline: "nearest" });
1028 }, [props.activeSurfaceId, tabScrollState.hasOverflow]);
1029
1030 useEffect(() => {
1031 const viewport = tabScrollViewport(tabListRef.current);
1032 if (!viewport) return;
1033
1034 const content = viewport.firstElementChild;
1035 const resizeObserver = new ResizeObserver(updateTabScrollState);
1036 resizeObserver.observe(viewport);
1037 if (content) resizeObserver.observe(content);
1038 viewport.addEventListener("scroll", updateTabScrollState, { passive: true });
1039 updateTabScrollState();
1040
1041 return () => {
1042 resizeObserver.disconnect();
1043 viewport.removeEventListener("scroll", updateTabScrollState);
1044 };
1045 }, [updateTabScrollState]);
1046
1047 useEffect(() => {
1048 const viewport = tabScrollViewport(tabListRef.current);
1049 if (!viewport) return;
1050
1051 const handleWheel = (event: WheelEvent) => {
1052 if (event.ctrlKey) return;
1053 let delta = Math.abs(event.deltaX) > Math.abs(event.deltaY) ? event.deltaX : event.deltaY;
1054 if (event.deltaMode === WheelEvent.DOM_DELTA_LINE) delta *= 16;
1055 if (event.deltaMode === WheelEvent.DOM_DELTA_PAGE) delta *= viewport.clientWidth;
1056 if (delta === 0) return;
1057
1058 const previousScrollLeft = viewport.scrollLeft;
1059 viewport.scrollLeft += delta;
1060 if (viewport.scrollLeft === previousScrollLeft) return;
1061 event.preventDefault();
1062 updateTabScrollState();
1063 };
1064
1065 viewport.addEventListener("wheel", handleWheel, { passive: false });
1066 return () => viewport.removeEventListener("wheel", handleWheel);
1067 }, [updateTabScrollState]);
1068
1069 return (
1070 <PreviewPanelShell
1071 mode={props.mode}
1072 {...(props.maximized !== undefined ? { maximized: props.maximized } : {})}
1073 {...(props.open !== undefined ? { open: props.open } : {})}
1074 {...(props.widthStorageKey !== undefined ? { widthStorageKey: props.widthStorageKey } : {})}
1075 {...(props.defaultWidth !== undefined ? { defaultWidth: props.defaultWidth } : {})}
1076 >
1077 <div
1078 className={cn(
1079 "flex h-[var(--workspace-topbar-height)] min-h-[var(--workspace-topbar-height)] shrink-0 items-center gap-1 pl-2",
1080 // The sheet overlays from the viewport top, so its tab bar keeps
1081 // the titlebar's height: a compact row re-centers the layout
1082 // controls a few pixels higher and the cluster jumps on open.
1083 props.mode === "inline" && !props.layoutControls ? "pr-28" : "pr-3",
1084 ownsDesktopTitleBar && "drag-region",
1085 ownsDesktopTitleBar &&
1086 (props.layoutControls
1087 ? "wco:pr-[var(--workspace-native-controls-inset)]"
1088 : "wco:pr-[calc(var(--workspace-native-controls-inset)+6rem)]"),
1089 props.mode === "inline" && props.maximized && COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS,
1090 )}
1091 data-right-panel-tabbar
1092 >
1093 <ScrollArea
1094 ref={tabListRef}
1095 hideScrollbars
1096 scrollFade
1097 className="min-w-0 flex-1 rounded-none"
1098 data-right-panel-tab-list
1099 >
1100 <div className="flex h-full w-max min-w-full items-center gap-1">
1101 {props.surfaces.map((surface) => {
1102 const active = surface.id === props.activeSurfaceId;
1103 const pending = props.pendingSurfaceIds.has(surface.id);
1104 const title = surfaceTitle(surface, props.previewSessions, props.terminalLabelsById);
1105 const previewTabId = previewTabIdOf(surface, props.previewSessions);
1106 // Desktop state is keyed by the session id, but desktop actions
1107 // must be addressed with the runtime id.
1108 const audio = tabAudioState(
1109 previewTabId ? (props.desktopByTabId[previewTabId] ?? null) : null,
1110 );
1111 const audioRuntimeTabId = previewTabId
1112 ? (props.previewRuntimeTabId?.(previewTabId) ?? null)
1113 : null;
1114 return (
1115 <div
1116 key={surface.id}
1117 data-active-tab={active}
1118 onMouseDown={handleTabMouseDown}
1119 onAuxClick={(event) => handleTabAuxClick(event, surface)}
1120 onContextMenu={(event) => void handleTabContextMenu(event, surface)}
1121 className={cn(
1122 "cursor-pointer group/tab flex h-6 max-w-36 shrink-0 items-center gap-0.5 rounded-md pr-2 pl-1.5 text-xs",
1123 ownsDesktopTitleBar && "[-webkit-app-region:no-drag]",
1124 active
1125 ? "bg-accent text-foreground"
1126 : "text-muted-foreground hover:bg-accent/60 hover:text-foreground",
1127 )}
1128 >
1129 <PanelTabCloseButton
1130 label={`Close ${title}`}
1131 onClick={() => props.onCloseSurface(surface)}
1132 >
1133 <SurfaceIcon
1134 surface={surface}
1135 sessions={props.previewSessions}
1136 desktopByTabId={props.desktopByTabId}
1137 theme={resolvedTheme}
1138 environmentId={props.environmentId}
1139 pullRequestStatusSeeds={props.pullRequestStatusSeeds}
1140 />
1141 {pending ? (
1142 <span
1143 className="absolute -right-0.5 -bottom-0.5 size-1.5 rounded-full bg-current"
1144 aria-hidden
1145 />
1146 ) : null}
1147 </PanelTabCloseButton>
1148 {audio === "none" || !audioRuntimeTabId ? null : (
1149 <Tooltip>
1150 <TooltipTrigger
1151 render={
1152 <button
1153 type="button"
1154 className="cursor-pointer flex size-4 shrink-0 items-center justify-center rounded-sm hover:bg-muted"
1155 aria-label={audio === "muted" ? `Unmute ${title}` : `Mute ${title}`}
1156 onClick={(event) => {
1157 // Sibling of the close button, inside a tab that
1158 // activates on click: keep this to the toggle.
1159 event.stopPropagation();
1160 void previewBridge
1161 ?.setAudioMuted(audioRuntimeTabId, audio !== "muted")
1162 .catch(() => undefined);
1163 }}
1164 >
1165 {audio === "muted" ? (
1166 <VolumeOff className="size-3" />
1167 ) : (
1168 <Volume2 className="size-3" />
1169 )}
1170 </button>
1171 }
1172 />
1173 <TooltipPopup>{audio === "muted" ? "Unmute tab" : "Mute tab"}</TooltipPopup>
1174 </Tooltip>
1175 )}
1176 <Tooltip>
1177 <TooltipTrigger
1178 render={
1179 <button
1180 type="button"
1181 className="cursor-pointer flex min-w-0 items-center"
1182 onClick={() => props.onActivate(surface)}
1183 >
1184 <span className="truncate">{title}</span>
1185 </button>
1186 }
1187 />
1188 <TooltipPopup>{title}</TooltipPopup>
1189 </Tooltip>
1190 </div>
1191 );
1192 })}
1193 {props.surfaces.length > 0 ? (
1194 <Menu open={addSurfaceMenuOpen} onOpenChange={setAddSurfaceMenuOpen}>
1195 <MenuTrigger
1196 render={
1197 <Button
1198 aria-label="Add panel surface"
1199 className="size-6 shrink-0 text-muted-foreground hover:text-foreground"
1200 size="icon-xs"
1201 variant="ghost"
1202 />
1203 }
1204 >
1205 <Plus className="size-3.5" />
1206 </MenuTrigger>
1207 <MenuPopup
1208 align="start"
1209 side="bottom"
1210 sideOffset={6}
1211 className="min-w-44"
1212 onKeyDownCapture={handleAddSurfaceMenuKeyDown}
1213 >
1214 {addSurfaceActions.map((action) => {
1215 const Icon = action.icon;
1216 // Browser collapses into one row: clicking the trigger opens
1217 // the default profile (the common case stays one click),
1218 // while hover or arrow reveals the profiles. The choice
1219 // lives at open time because a tab's profile is fixed then —
1220 // Electron only honours a partition before attach.
1221 if (action.label === "Browser" && action.available) {
1222 return (
1223 <MenuSub key={action.label}>
1224 <MenuSubTrigger
1225 className="[&>svg:last-child]:ms-0"
1226 aria-keyshortcuts={action.shortcut}
1227 onClick={(event) => {
1228 const pointerType =
1229 "pointerType" in event.nativeEvent &&
1230 typeof event.nativeEvent.pointerType === "string"
1231 ? event.nativeEvent.pointerType
1232 : undefined;
1233 // Touch has no hover path to the profile choices:
1234 // its first tap opens the submenu, then a profile
1235 // is selected there. Mouse click keeps the common
1236 // default-profile action at one click.
1237 if (!shouldOpenDefaultBrowserProfileFromMenuClick(pointerType))
1238 return;
1239 setAddSurfaceMenuOpen(false);
1240 action.onClick();
1241 }}
1242 >
1243 <Icon />
1244 {action.label}
1245 <MenuShortcut>{action.shortcut}</MenuShortcut>
1246 </MenuSubTrigger>
1247 {/*
1248 Capped and truncated: profile names are user-supplied
1249 and run to 48 characters, which would otherwise widen
1250 the popup to fit-content and wrap.
1251 */}
1252 <MenuSubPopup className="min-w-40 max-w-56">
1253 {browserProfiles.map((profile) => (
1254 <MenuItem
1255 key={profile.id}
1256 onClick={() => props.onAddBrowserInProfile(profile.id)}
1257 >
1258 <span className="min-w-0 truncate">{profile.name}</span>
1259 </MenuItem>
1260 ))}
1261 </MenuSubPopup>
1262 </MenuSub>
1263 );
1264 }
1265 return (
1266 <SurfaceMenuItem
1267 key={action.label}
1268 available={action.available}
1269 disabledReason={action.disabledReason}
1270 shortcut={action.shortcut}
1271 onClick={action.onClick}
1272 >
1273 <Icon />
1274 {action.label}
1275 </SurfaceMenuItem>
1276 );
1277 })}
1278 </MenuPopup>
1279 </Menu>
1280 ) : null}
1281 </div>
1282 </ScrollArea>
1283 {tabScrollState.hasOverflow ? (
1284 <div
1285 className="flex shrink-0 items-center gap-0.5 [-webkit-app-region:no-drag]"
1286 role="group"
1287 aria-label="Scroll panel tabs"
1288 >
1289 <Tooltip>
1290 <TooltipTrigger
1291 render={
1292 <span className="inline-flex">
1293 <Button
1294 aria-label="Scroll tabs left"
1295 disabled={!tabScrollState.canScrollLeft}
1296 onClick={() => scrollTabs(-1)}
1297 size="icon-xs"
1298 variant="ghost"
1299 >
1300 <ChevronLeft />
1301 </Button>
1302 </span>
1303 }
1304 />
1305 <TooltipPopup>Scroll tabs left</TooltipPopup>
1306 </Tooltip>
1307 <Tooltip>
1308 <TooltipTrigger
1309 render={
1310 <span className="inline-flex">
1311 <Button
1312 aria-label="Scroll tabs right"
1313 disabled={!tabScrollState.canScrollRight}
1314 onClick={() => scrollTabs(1)}
1315 size="icon-xs"
1316 variant="ghost"
1317 >
1318 <ChevronRight />
1319 </Button>
1320 </span>
1321 }
1322 />
1323 <TooltipPopup>Scroll tabs right</TooltipPopup>
1324 </Tooltip>
1325 </div>
1326 ) : null}
1327 {props.layoutControls}
1328 {ownsDesktopTitleBar ? (
1329 <span
1330 aria-hidden
1331 className="pointer-events-none fixed top-[var(--workspace-controls-top)] right-[var(--workspace-controls-right)] h-[var(--workspace-topbar-height)] w-28 [-webkit-app-region:no-drag]"
1332 />
1333 ) : null}
1334 </div>
1335 <div className="flex min-h-0 flex-1 flex-col" data-right-panel-surface-content>
1336 {props.activeSurfaceId === null ? (
1337 <RightPanelEmptyState
1338 onAddBrowser={props.onAddBrowser}
1339 onAddBrowserInProfile={props.onAddBrowserInProfile}
1340 browserProfiles={browserProfiles}
1341 onAddTerminal={props.onAddTerminal}
1342 onAddDiff={props.onAddDiff}
1343 onAddFiles={props.onAddFiles}
1344 onAddPullRequest={props.onAddPullRequest}
1345 onAddPullRequests={props.onAddPullRequests}
1346 onAddAgents={props.onAddAgents}
1347 browserAvailable={props.browserAvailable}
1348 terminalAvailable={props.terminalAvailable}
1349 diffAvailable={props.diffAvailable}
1350 filesAvailable={props.filesAvailable}
1351 pullRequestAvailable={props.pullRequestAvailable}
1352 pullRequestsAvailable={props.pullRequestsAvailable}
1353 agentsAvailable={props.agentsAvailable}
1354 liveAgentCount={props.liveAgentCount}
1355 />
1356 ) : (
1357 props.children
1358 )}
1359 </div>
1360 </PreviewPanelShell>
1361 );
1362}