Open History to see the last commit
1"use client";
2
3import { scopedThreadKey } from "@t3tools/client-runtime/environment";
4import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
5import {
6 FILL_PREVIEW_VIEWPORT,
7 type PreviewAnnotationPayload,
8 type PreviewViewportSetting,
9 type ScopedThreadRef,
10} from "@t3tools/contracts";
11import { normalizePreviewUrl } from "@t3tools/shared/preview";
12import { useCallback, useEffect, useRef, useState } from "react";
13
14import { type ComposerImageAttachment, useComposerDraftStore } from "~/composerDraftStore";
15import { previewAnnotationScreenshotFile } from "~/lib/previewAnnotation";
16import { ensureLocalApi } from "~/localApi";
17import {
18 rememberPreviewUrl,
19 updatePreviewServerSnapshot,
20 useThreadPreviewState,
21} from "~/previewStateStore";
22import { resolveDiscoveredServerUrl } from "~/browser/browserTargetResolver";
23import { previewEnvironment } from "~/state/preview";
24import { useAtomCommand } from "~/state/use-atom-command";
25import { selectThreadPreviewMiniPlayer, usePreviewMiniPlayerStore } from "~/previewMiniPlayerStore";
26import { useRightPanelStore } from "~/rightPanelStore";
27
28import { previewBridge } from "./previewBridge";
29import { subscribePreviewAction } from "./previewActionBus";
30import { openPreviewSession } from "./openPreviewSession";
31import { PreviewChromeRow } from "./PreviewChromeRow";
32import { PreviewEmptyState } from "./PreviewEmptyState";
33import { PreviewMoreMenu } from "./PreviewMoreMenu";
34import {
35 commitBrowserViewportChange,
36 subscribeBrowserViewportChange,
37} from "~/browser/browserViewportActions";
38import { resolveResponsiveBrowserViewportSize } from "~/browser/browserViewportLayout";
39import { previewRuntimeTabId } from "~/browser/previewRuntimeTabId";
40import { PreviewUnreachable } from "./PreviewUnreachable";
41import { revealInFileExplorerLabel } from "./fileExplorerLabel";
42import { shouldShowPreviewEmptyState } from "./previewEmptyStateLogic";
43import { BrowserSurfaceSlot } from "~/browser/BrowserSurfaceSlot";
44import { useBrowserSurfaceStore } from "~/browser/browserSurfaceStore";
45import { useLoadingProgress } from "./useLoadingProgress";
46import { usePreviewSession } from "./usePreviewSession";
47import { ZoomIndicator } from "./ZoomIndicator";
48import { AgentBrowserCursor } from "./AgentBrowserCursor";
49import {
50 findActiveBrowserRecordingRuntimeTabId,
51 startBrowserRecording,
52 stopBrowserRecording,
53 useActiveBrowserRecordingTabIds,
54} from "~/browser/browserRecording";
55import { stackedThreadToast, toastManager } from "~/components/ui/toast";
56
57interface Props {
58 threadRef: ScopedThreadRef;
59 tabId?: string | null;
60 configuredUrls?: ReadonlyArray<string> | undefined;
61 visible: boolean;
62 onSendAnnotation?: (
63 annotation: PreviewAnnotationPayload,
64 image: ComposerImageAttachment | null,
65 ) => void;
66}
67
68const localApi = typeof window === "undefined" ? null : ensureLocalApi();
69
70/**
71 * Single-tab preview surface: chrome row on top, one webview below, empty
72 * state when no session exists for the thread.
73 */
74export function PreviewView({
75 threadRef,
76 tabId: requestedTabId,
77 configuredUrls,
78 visible,
79 onSendAnnotation,
80}: Props) {
81 const [focusUrlNonce, setFocusUrlNonce] = useState<number | undefined>(undefined);
82 const [pickActive, setPickActive] = useState(false);
83 const activeRecordingTabIds = useActiveBrowserRecordingTabIds();
84 const pickActiveRef = useRef(false);
85 const isMountedRef = useRef(true);
86 const previewState = useThreadPreviewState(threadRef);
87 const miniPlayer = usePreviewMiniPlayerStore((state) =>
88 selectThreadPreviewMiniPlayer(state.byThreadKey, threadRef),
89 );
90 const addPreviewAnnotation = useComposerDraftStore((store) => store.addPreviewAnnotation);
91 const addImage = useComposerDraftStore((store) => store.addImage);
92 const open = useAtomCommand(previewEnvironment.open);
93 const resize = useAtomCommand(previewEnvironment.resize, "preview viewport resize");
94
95 usePreviewSession(threadRef);
96
97 useEffect(() => {
98 isMountedRef.current = true;
99 return () => {
100 isMountedRef.current = false;
101 };
102 }, []);
103
104 const tabId = requestedTabId ?? previewState.activeTabId;
105 const runtimeTabId = tabId
106 ? previewRuntimeTabId(threadRef, previewState.serverEpoch, tabId)
107 : null;
108 const recordingRuntimeTabId =
109 tabId && runtimeTabId
110 ? activeRecordingTabIds.has(runtimeTabId)
111 ? runtimeTabId
112 : findActiveBrowserRecordingRuntimeTabId(threadRef, tabId)
113 : null;
114 const snapshot = tabId ? (previewState.sessions[tabId] ?? null) : null;
115 const desktopOverlay = tabId ? (previewState.desktopByTabId[tabId] ?? null) : null;
116 const navStatus = snapshot?.navStatus ?? { _tag: "Idle" as const };
117 const url = navStatus._tag === "Idle" ? "" : navStatus.url;
118 const loading = desktopOverlay?.loading ?? navStatus._tag === "Loading";
119 const canGoBack = desktopOverlay?.canGoBack ?? snapshot?.canGoBack ?? false;
120 const canGoForward = desktopOverlay?.canGoForward ?? snapshot?.canGoForward ?? false;
121 const refreshDisabled = navStatus._tag === "Idle";
122 const isUnreachable = navStatus._tag === "LoadFailed";
123 const showEmptyState = shouldShowPreviewEmptyState(snapshot);
124 const controller = desktopOverlay?.controller ?? "none";
125 const loadProgress = useLoadingProgress(loading);
126 const viewport = snapshot?.viewport ?? FILL_PREVIEW_VIEWPORT;
127 const panelRect = useBrowserSurfaceStore((state) =>
128 runtimeTabId ? (state.byTabId[runtimeTabId]?.rect ?? null) : null,
129 );
130
131 const navigateToResolvedUrl = useCallback(
132 async (resolvedUrl: string) => {
133 if (runtimeTabId && previewBridge) {
134 // Drive the webview imperatively; `usePreviewBridge` mirrors the
135 // resolved URL back to the server so other clients stay in sync.
136 await previewBridge.navigate(runtimeTabId, resolvedUrl);
137 rememberPreviewUrl(threadRef, resolvedUrl);
138 } else {
139 await openPreviewSession({
140 openPreview: open,
141 threadRef,
142 url: resolvedUrl,
143 });
144 }
145 },
146 [open, runtimeTabId, threadRef],
147 );
148
149 const handleSubmitUrl = useCallback(
150 async (next: string) => {
151 try {
152 await navigateToResolvedUrl(normalizePreviewUrl(next));
153 } catch {
154 // Server-side `failed` event renders the unreachable view.
155 }
156 },
157 [navigateToResolvedUrl],
158 );
159
160 const handleOpenServerUrl = useCallback(
161 async (next: string) => {
162 try {
163 await navigateToResolvedUrl(resolveDiscoveredServerUrl(threadRef.environmentId, next));
164 } catch {
165 // Server-side `failed` event renders the unreachable view.
166 }
167 },
168 [navigateToResolvedUrl, threadRef.environmentId],
169 );
170
171 const handleRefresh = useCallback(() => {
172 if (previewBridge && runtimeTabId) void previewBridge.refresh(runtimeTabId);
173 }, [runtimeTabId]);
174
175 const handleZoomIn = useCallback(() => {
176 if (previewBridge && runtimeTabId) void previewBridge.zoomIn(runtimeTabId);
177 }, [runtimeTabId]);
178
179 const handleZoomOut = useCallback(() => {
180 if (previewBridge && runtimeTabId) void previewBridge.zoomOut(runtimeTabId);
181 }, [runtimeTabId]);
182
183 const handleResetZoom = useCallback(() => {
184 if (previewBridge && runtimeTabId) void previewBridge.resetZoom(runtimeTabId);
185 }, [runtimeTabId]);
186
187 const handleViewportChange = useCallback(
188 async (nextViewport: PreviewViewportSetting) => {
189 if (!tabId) return;
190 const result = await resize({
191 environmentId: threadRef.environmentId,
192 input: {
193 threadId: threadRef.threadId,
194 tabId,
195 viewport: nextViewport,
196 },
197 });
198 if (result._tag === "Failure") {
199 const error = squashAtomCommandFailure(result);
200 toastManager.add({
201 type: "error",
202 title: "Unable to resize browser viewport",
203 description: error instanceof Error ? error.message : "An error occurred.",
204 });
205 throw error;
206 }
207 updatePreviewServerSnapshot(threadRef, result.value);
208 },
209 [resize, tabId, threadRef],
210 );
211
212 const handleToggleDeviceToolbar = () => {
213 if (!runtimeTabId) return;
214 if (viewport._tag !== "fill") {
215 void commitBrowserViewportChange(runtimeTabId, FILL_PREVIEW_VIEWPORT).catch(() => undefined);
216 return;
217 }
218
219 const responsiveSize = panelRect
220 ? resolveResponsiveBrowserViewportSize(panelRect, desktopOverlay?.zoomFactor)
221 : { width: 1024, height: 768 };
222 void commitBrowserViewportChange(runtimeTabId, { _tag: "freeform", ...responsiveSize }).catch(
223 () => undefined,
224 );
225 };
226
227 useEffect(() => {
228 if (!runtimeTabId) return;
229 return subscribeBrowserViewportChange(runtimeTabId, handleViewportChange);
230 }, [handleViewportChange, runtimeTabId]);
231
232 const handleBack = useCallback(() => {
233 if (previewBridge && runtimeTabId) void previewBridge.goBack(runtimeTabId);
234 }, [runtimeTabId]);
235
236 const handleForward = useCallback(() => {
237 if (previewBridge && runtimeTabId) void previewBridge.goForward(runtimeTabId);
238 }, [runtimeTabId]);
239
240 const handleOpenInBrowser = useCallback(() => {
241 if (!localApi || !url) return;
242 void localApi.shell.openExternal(url).catch(() => undefined);
243 }, [url]);
244
245 const handlePictureInPicture = useCallback(() => {
246 if (!tabId) return;
247 if (miniPlayer?.tabId === tabId) {
248 usePreviewMiniPlayerStore.getState().close(threadRef);
249 return;
250 }
251 usePreviewMiniPlayerStore.getState().open(threadRef, tabId);
252 useRightPanelStore.getState().close(threadRef);
253 }, [miniPlayer?.tabId, tabId, threadRef]);
254
255 const handleNativePictureInPicture = useCallback(() => {
256 if (!previewBridge || !runtimeTabId) return;
257 const operation = desktopOverlay?.pictureInPicture
258 ? previewBridge.pictureInPicture.close
259 : previewBridge.pictureInPicture.open;
260 void operation(runtimeTabId).catch((error) => {
261 toastManager.add({
262 type: "error",
263 title: "Unable to update popped-out preview",
264 description: error instanceof Error ? error.message : "An error occurred.",
265 });
266 });
267 }, [desktopOverlay?.pictureInPicture, runtimeTabId]);
268
269 const handleCapture = useCallback(
270 (record: boolean) => {
271 if (!previewBridge || !runtimeTabId || !tabId) return;
272 const bridge = previewBridge;
273 if (recordingRuntimeTabId) {
274 void stopBrowserRecording(recordingRuntimeTabId).then(
275 (artifact) => {
276 if (!artifact) return;
277 let pathCopied = false;
278 let toastId: ReturnType<typeof toastManager.add>;
279
280 const copyPath = () => {
281 if (!navigator.clipboard?.writeText) {
282 toastManager.update(
283 toastId,
284 stackedThreadToast({
285 type: "error",
286 title: "Unable to copy recording path",
287 description: "Clipboard API unavailable.",
288 actionProps: revealAction,
289 }),
290 );
291 return;
292 }
293
294 void navigator.clipboard.writeText(artifact.path).then(
295 () => {
296 pathCopied = true;
297 updateRecordingToast();
298 window.setTimeout(() => {
299 pathCopied = false;
300 updateRecordingToast();
301 }, 2_000);
302 },
303 (error) => {
304 toastManager.update(
305 toastId,
306 stackedThreadToast({
307 type: "error",
308 title: "Unable to copy recording path",
309 description: error instanceof Error ? error.message : "An error occurred.",
310 actionProps: revealAction,
311 }),
312 );
313 },
314 );
315 };
316
317 const revealAction = {
318 children: revealInFileExplorerLabel(navigator.platform),
319 onClick: () => void bridge.revealArtifact(artifact.path),
320 };
321 const updateRecordingToast = () => {
322 toastManager.update(
323 toastId,
324 stackedThreadToast({
325 type: "success",
326 title: "Recording saved",
327 actionProps: revealAction,
328 data: {
329 secondaryActionProps: {
330 children: pathCopied ? "Copied!" : "Copy path",
331 disabled: pathCopied,
332 onClick: copyPath,
333 },
334 secondaryActionVariant: "outline",
335 },
336 }),
337 );
338 };
339
340 toastId = toastManager.add(
341 stackedThreadToast({
342 type: "success",
343 title: "Recording saved",
344 actionProps: revealAction,
345 data: {
346 secondaryActionProps: {
347 children: "Copy path",
348 onClick: copyPath,
349 },
350 secondaryActionVariant: "outline",
351 },
352 }),
353 );
354 },
355 (error) => {
356 toastManager.add({
357 type: "error",
358 title: "Unable to stop recording",
359 description: error instanceof Error ? error.message : "An error occurred.",
360 });
361 },
362 );
363 return;
364 }
365 if (record) {
366 void startBrowserRecording(runtimeTabId, threadRef, tabId).catch((error) => {
367 toastManager.add({
368 type: "error",
369 title: "Unable to start recording",
370 description: error instanceof Error ? error.message : "An error occurred.",
371 });
372 });
373 return;
374 }
375 void bridge.captureScreenshot(runtimeTabId).then(
376 (artifact) => {
377 const revealAction = {
378 children: revealInFileExplorerLabel(navigator.platform),
379 onClick: () => void bridge.revealArtifact(artifact.path),
380 };
381 let pathCopied = false;
382 let imageCopied = false;
383 let toastId: ReturnType<typeof toastManager.add>;
384
385 const updateScreenshotToast = (
386 type: "success" | "error" = "success",
387 title = "Screenshot saved",
388 description?: string,
389 ) => {
390 toastManager.update(
391 toastId,
392 stackedThreadToast({
393 type,
394 title,
395 description,
396 actionProps: {
397 children: imageCopied ? "Copied!" : "Copy image",
398 disabled: imageCopied,
399 onClick: copyImage,
400 },
401 data: {
402 additionalActions: [
403 {
404 id: "copy-path",
405 props: {
406 children: pathCopied ? "Copied!" : "Copy path",
407 disabled: pathCopied,
408 onClick: copyPath,
409 },
410 },
411 ],
412 secondaryActionProps: {
413 ...revealAction,
414 },
415 secondaryActionVariant: "outline",
416 },
417 }),
418 );
419 };
420
421 const copyPath = () => {
422 if (!navigator.clipboard?.writeText) {
423 updateScreenshotToast(
424 "error",
425 "Unable to copy screenshot path",
426 "Clipboard API unavailable.",
427 );
428 return;
429 }
430
431 void navigator.clipboard.writeText(artifact.path).then(
432 () => {
433 pathCopied = true;
434 updateScreenshotToast();
435 window.setTimeout(() => {
436 pathCopied = false;
437 updateScreenshotToast();
438 }, 2_000);
439 },
440 (error) => {
441 updateScreenshotToast(
442 "error",
443 "Unable to copy screenshot path",
444 error instanceof Error ? error.message : "An error occurred.",
445 );
446 },
447 );
448 };
449
450 const copyImage = () => {
451 void bridge.copyArtifactToClipboard(artifact.path).then(
452 () => {
453 imageCopied = true;
454 updateScreenshotToast();
455 window.setTimeout(() => {
456 imageCopied = false;
457 updateScreenshotToast();
458 }, 2_000);
459 },
460 (error) => {
461 updateScreenshotToast(
462 "error",
463 "Unable to copy screenshot",
464 error instanceof Error ? error.message : "An error occurred.",
465 );
466 },
467 );
468 };
469
470 toastId = toastManager.add(
471 stackedThreadToast({
472 type: "success",
473 title: "Screenshot saved",
474 actionProps: {
475 children: "Copy image",
476 onClick: copyImage,
477 },
478 data: {
479 additionalActions: [
480 {
481 id: "copy-path",
482 props: {
483 children: "Copy path",
484 onClick: copyPath,
485 },
486 },
487 ],
488 secondaryActionProps: {
489 ...revealAction,
490 },
491 secondaryActionVariant: "outline",
492 },
493 }),
494 );
495 },
496 (error) => {
497 toastManager.add({
498 type: "error",
499 title: "Unable to capture screenshot",
500 description: error instanceof Error ? error.message : "An error occurred.",
501 });
502 },
503 );
504 },
505 [recordingRuntimeTabId, runtimeTabId, tabId, threadRef],
506 );
507
508 const handlePickElement = useCallback(() => {
509 if (!previewBridge || !runtimeTabId) return;
510 if (pickActiveRef.current) {
511 void previewBridge.cancelPickElement(runtimeTabId).catch(() => undefined);
512 return;
513 }
514 // Snapshot whatever the user was focused on (typically the chat
515 // composer textarea or the chrome-row pick button) BEFORE main steals
516 // focus into the guest webContents. We restore it when the pick
517 // resolves so the user's typing context isn't lost — otherwise after
518 // every pick they'd have to click back into the textarea.
519 const previouslyFocused =
520 typeof document !== "undefined" ? (document.activeElement as HTMLElement | null) : null;
521 pickActiveRef.current = true;
522 setPickActive(true);
523 void (async () => {
524 try {
525 const result = await previewBridge.pickElement(runtimeTabId);
526 if (!result) return;
527 const { annotation, submission } = result;
528 addPreviewAnnotation(threadRef, annotation);
529 let screenshotFile: File | null = null;
530 try {
531 screenshotFile = await previewAnnotationScreenshotFile(annotation);
532 } catch {
533 // The structured annotation is still sendable when converting its
534 // optional screenshot into a composer attachment fails.
535 }
536 const image =
537 screenshotFile && annotation.screenshot
538 ? ({
539 type: "image",
540 id: annotation.id,
541 name: screenshotFile.name,
542 mimeType: screenshotFile.type,
543 sizeBytes: screenshotFile.size,
544 previewUrl: annotation.screenshot.dataUrl,
545 file: screenshotFile,
546 } satisfies ComposerImageAttachment)
547 : null;
548 if (image) {
549 addImage(threadRef, image);
550 }
551 if (submission === "send") {
552 onSendAnnotation?.(annotation, image);
553 }
554 } catch {
555 // Picker failed (e.g. webview navigated). Treat as silent cancel.
556 } finally {
557 pickActiveRef.current = false;
558 // Avoid `setState on unmounted component` if the panel/thread closed
559 // while the pick was in flight.
560 if (isMountedRef.current) setPickActive(false);
561 // Best-effort: restore focus to whatever the user had before the
562 // pick stole it into the guest webContents. Skip if the previously-
563 // focused element was unmounted or is no longer focusable.
564 if (
565 previouslyFocused &&
566 previouslyFocused.isConnected &&
567 typeof previouslyFocused.focus === "function"
568 ) {
569 try {
570 previouslyFocused.focus({ preventScroll: true });
571 } catch {
572 // Some elements throw on .focus() (detached iframes, etc.).
573 }
574 }
575 }
576 })();
577 }, [addImage, addPreviewAnnotation, onSendAnnotation, runtimeTabId, threadRef]);
578
579 // If the active tab changes mid-pick (close, thread switch, hot restart),
580 // tell main to tear down the in-flight session AND reset our local toggle
581 // state so the button doesn't get stuck pressed against a stale tab id.
582 useEffect(() => {
583 return () => {
584 if (!pickActiveRef.current) return;
585 pickActiveRef.current = false;
586 if (previewBridge && runtimeTabId) {
587 void previewBridge.cancelPickElement(runtimeTabId).catch(() => undefined);
588 }
589 if (isMountedRef.current) setPickActive(false);
590 };
591 }, [runtimeTabId]);
592
593 // Subscribe only while visible; `toggle-panel` is owned by ChatView's
594 // URL-aware handler regardless of whether the panel is currently mounted.
595 useEffect(() => {
596 if (!visible) return;
597 return subscribePreviewAction((action) => {
598 switch (action) {
599 case "refresh":
600 handleRefresh();
601 return;
602 case "focus-url":
603 setFocusUrlNonce((value) => (value ?? 0) + 1);
604 return;
605 case "zoom-in":
606 handleZoomIn();
607 return;
608 case "zoom-out":
609 handleZoomOut();
610 return;
611 case "reset-zoom":
612 handleResetZoom();
613 return;
614 case "toggle-panel":
615 return;
616 }
617 });
618 }, [handleRefresh, handleResetZoom, handleZoomIn, handleZoomOut, visible]);
619
620 return (
621 <div
622 className="flex min-h-0 flex-1 flex-col bg-background"
623 data-thread-key={scopedThreadKey(threadRef)}
624 >
625 <PreviewChromeRow
626 url={url}
627 loading={loading}
628 loadProgress={loadProgress}
629 canGoBack={canGoBack}
630 canGoForward={canGoForward}
631 refreshDisabled={refreshDisabled}
632 focusUrlNonce={focusUrlNonce}
633 onBack={handleBack}
634 onForward={handleForward}
635 onRefresh={handleRefresh}
636 onSubmit={(next) => void handleSubmitUrl(next)}
637 onOpenInBrowser={tabId ? handleOpenInBrowser : undefined}
638 onCapture={previewBridge && tabId ? handleCapture : undefined}
639 captureDisabled={!desktopOverlay || isUnreachable}
640 recording={recordingRuntimeTabId !== null}
641 onPictureInPicture={previewBridge && tabId ? handlePictureInPicture : undefined}
642 pictureInPicture={miniPlayer?.tabId === tabId}
643 pictureInPictureDisabled={!desktopOverlay?.hasWebContents || isUnreachable}
644 onPickElement={previewBridge && tabId ? handlePickElement : undefined}
645 pickActive={pickActive}
646 // Disable when there's no tab (nothing to pick on) OR the page
647 // failed to load (a React overlay covers the webview, so the
648 // user wouldn't be able to actually click anything underneath).
649 pickDisabled={!tabId || isUnreachable}
650 pickDisabledReason={
651 isUnreachable ? "Page didn't load — pick unavailable until the page renders" : undefined
652 }
653 trailingActions={
654 previewBridge ? (
655 <PreviewMoreMenu
656 tabId={runtimeTabId}
657 hasWebContents={desktopOverlay?.hasWebContents ?? false}
658 zoomFactor={desktopOverlay?.zoomFactor ?? 1}
659 colorScheme={desktopOverlay?.colorScheme ?? "system"}
660 deviceToolbarVisible={viewport._tag !== "fill"}
661 onToggleDeviceToolbar={handleToggleDeviceToolbar}
662 nativePictureInPicture={desktopOverlay?.pictureInPicture ?? false}
663 onNativePictureInPicture={handleNativePictureInPicture}
664 />
665 ) : null
666 }
667 />
668
669 <div className="relative min-h-0 flex-1 overflow-hidden">
670 {runtimeTabId && snapshot && !showEmptyState ? (
671 <BrowserSurfaceSlot
672 key={runtimeTabId}
673 tabId={runtimeTabId}
674 visible={visible && !isUnreachable}
675 className="absolute inset-0 h-full w-full"
676 />
677 ) : null}
678 {showEmptyState ? (
679 <PreviewEmptyState
680 environmentId={threadRef.environmentId}
681 configuredUrls={configuredUrls}
682 recentlySeenUrls={previewState.recentlySeenUrls}
683 onOpenUrl={(next) => void handleOpenServerUrl(next)}
684 />
685 ) : null}
686 {snapshot && desktopOverlay ? (
687 <ZoomIndicator zoomFactor={desktopOverlay.zoomFactor} />
688 ) : null}
689 {runtimeTabId && desktopOverlay && !showEmptyState && !isUnreachable ? (
690 <AgentBrowserCursor
691 tabId={runtimeTabId}
692 zoomFactor={desktopOverlay.zoomFactor}
693 controller={controller}
694 />
695 ) : null}
696 {controller !== "none" ? (
697 <div className="pointer-events-none absolute left-3 top-3 z-40 rounded-full border border-border/70 bg-background/90 px-2.5 py-1 text-[11px] font-medium shadow-sm backdrop-blur">
698 {controller === "agent" ? "Agent controlling browser" : "Human control"}
699 </div>
700 ) : null}
701 {navStatus._tag === "LoadFailed" ? (
702 <div className="absolute inset-0 z-10 bg-background">
703 <PreviewUnreachable
704 url={navStatus.url}
705 code={navStatus.code}
706 description={navStatus.description}
707 onReload={handleRefresh}
708 />
709 </div>
710 ) : null}
711 </div>
712 </div>
713 );
714}