@@ -195,6 +195,8 @@ import {
195195 useSidebarPendingFileDropStore ,
196196} from "../sidebarPendingFileDropStore" ;
197197import {
198+ browserMiniPlayerSource ,
199+ previewMiniPlayerSourceKey ,
198200 selectThreadPreviewMiniPlayer ,
199201 usePreviewMiniPlayerStore ,
200202} from "../previewMiniPlayerStore" ;
@@ -566,6 +568,8 @@ const PreviewPanel = lazy(() =>
566568 import ( "./preview/PreviewPanel" ) . then ( ( module ) => ( { default : module . PreviewPanel } ) ) ,
567569) ;
568570const DiffPanel = lazy ( ( ) => import ( "./DiffPanel" ) ) ;
571+ const selectAutoShowFloatingPreview = ( settings : { browserAutoShowFloatingPreview : boolean } ) =>
572+ settings . browserAutoShowFloatingPreview ;
569573const DevicePanel = lazy ( ( ) =>
570574 import ( "./device/DevicePanel" ) . then ( ( module ) => ( { default : module . DevicePanel } ) ) ,
571575) ;
@@ -1958,7 +1962,7 @@ export default function ChatView(props: ChatViewProps) {
19581962 const renderedRightPanelSurface = rightPanelPresence . value ?. activeSurface ?? null ;
19591963 const renderedRightPanelSurfaces = rightPanelPresence . value ?. surfaces ?? [ ] ;
19601964 const previewMiniPlayerVisible = shouldRenderPreviewMiniPlayer (
1961- activePreviewMiniPlayer ?. tabId ?? null ,
1965+ activePreviewMiniPlayer ?. source ?? null ,
19621966 renderedRightPanelSurface ,
19631967 ) ;
19641968 const canMaximizeRightPanel = rightPanelOpen && ! shouldUseRightPanelSheet ;
@@ -1974,8 +1978,10 @@ export default function ChatView(props: ChatViewProps) {
19741978 } , [ activePreviewState . sessions , activeThreadRef ] ) ;
19751979
19761980 useEffect ( ( ) => {
1977- if ( ! activeThreadRef || ! activePreviewMiniPlayer ) return ;
1978- const miniTabStillExists = Boolean ( activePreviewState . sessions [ activePreviewMiniPlayer . tabId ] ) ;
1981+ if ( ! activeThreadRef || activePreviewMiniPlayer ?. source . kind !== "browser" ) return ;
1982+ const miniTabStillExists = Boolean (
1983+ activePreviewState . sessions [ activePreviewMiniPlayer . source . tabId ] ,
1984+ ) ;
19791985 if ( ! miniTabStillExists ) {
19801986 usePreviewMiniPlayerStore . getState ( ) . close ( activeThreadRef ) ;
19811987 }
@@ -4215,9 +4221,13 @@ export default function ChatView(props: ChatViewProps) {
42154221 }
42164222 useRightPanelStore . getState ( ) . open ( activeThreadRef , "device" ) ;
42174223 } , [ activeThreadRef , deviceState . onboardingCompleted , deviceState . hostStatus ] ) ;
4218- // Reconcile new server sessions into separate tabs, including sessions opened
4219- // by an agent or another client. The first snapshot is a baseline: persisted
4220- // tabs restore themselves, and existing sessions must not resurrect closed tabs.
4224+ // A device the agent opens floats over chat like an agent-driven browser,
4225+ // or becomes a panel tab when floating previews are off. Sessions opened by
4226+ // another client arrive the same way; sheet layouts get neither. The first
4227+ // snapshot is a baseline: persisted tabs restore themselves, and existing
4228+ // sessions must not resurrect closed tabs. A session whose device summary
4229+ // has not arrived yet stays out of the baseline so a later snapshot opens it.
4230+ const autoShowFloatingPreview = useClientSettings ( selectAutoShowFloatingPreview ) ;
42214231 const previousDeviceSessions = useRef ( new Map < string , Set < string > > ( ) ) ;
42224232 useEffect ( ( ) => {
42234233 if ( ! activeThreadRef || ! deviceStateLoaded ) return ;
@@ -4226,11 +4236,30 @@ export default function ChatView(props: ChatViewProps) {
42264236 ( session ) => session . threadId === activeThreadRef . threadId ,
42274237 ) ;
42284238 const key = ( session : ( typeof sessions ) [ number ] ) => `${ session . hostId } :${ session . deviceId } ` ;
4239+ const deviceFor = ( session : ( typeof sessions ) [ number ] ) =>
4240+ deviceState . devices . find (
4241+ ( entry ) => entry . hostId === session . hostId && entry . id === session . deviceId ,
4242+ ) ;
42294243 const previous = previousDeviceSessions . current . get ( threadKey ) ;
4230- previousDeviceSessions . current . set ( threadKey , new Set ( sessions . map ( key ) ) ) ;
4244+ previousDeviceSessions . current . set (
4245+ threadKey ,
4246+ new Set ( sessions . filter ( ( session ) => deviceFor ( session ) !== undefined ) . map ( key ) ) ,
4247+ ) ;
42314248 if ( ! previous || shouldUseRightPanelSheet ) return ;
42324249 for ( const session of sessions ) {
4233- if ( previous ?. has ( key ( session ) ) ) continue ;
4250+ if ( previous . has ( key ( session ) ) ) continue ;
4251+ const device = deviceFor ( session ) ;
4252+ if ( ! device ) continue ;
4253+ const target = {
4254+ hostId : session . hostId ,
4255+ deviceId : session . deviceId ,
4256+ platform : device . platform ,
4257+ name : device . name ,
4258+ } ;
4259+ if ( autoShowFloatingPreview ) {
4260+ usePreviewMiniPlayerStore . getState ( ) . open ( activeThreadRef , { kind : "device" , ...target } ) ;
4261+ continue ;
4262+ }
42344263 const existing = useRightPanelStore
42354264 . getState ( )
42364265 . byThreadKey [ scopedThreadKey ( activeThreadRef ) ] ?. surfaces . some (
@@ -4240,28 +4269,30 @@ export default function ChatView(props: ChatViewProps) {
42404269 surface . target . deviceId === session . deviceId ,
42414270 ) ;
42424271 if ( existing ) continue ;
4243- const device = deviceState . devices . find (
4244- ( entry ) => entry . hostId === session . hostId && entry . id === session . deviceId ,
4245- ) ;
4246- if ( ! device ) continue ;
4247- useRightPanelStore . getState ( ) . openDevice (
4248- activeThreadRef ,
4249- {
4250- hostId : session . hostId ,
4251- deviceId : session . deviceId ,
4252- platform : device . platform ,
4253- name : device . name ,
4254- } ,
4255- true ,
4256- ) ;
4272+ useRightPanelStore . getState ( ) . openDevice ( activeThreadRef , target , true ) ;
42574273 }
42584274 } , [
42594275 activeThreadRef ,
4276+ autoShowFloatingPreview ,
42604277 deviceStateLoaded ,
42614278 shouldUseRightPanelSheet ,
42624279 deviceState . sessions ,
42634280 deviceState . devices ,
42644281 ] ) ;
4282+ // A floating device follows its session: once the agent or another client
4283+ // closes the device there is nothing left to stream.
4284+ useEffect ( ( ) => {
4285+ if ( ! activeThreadRef || ! deviceStateLoaded ) return ;
4286+ const source = activePreviewMiniPlayer ?. source ;
4287+ if ( source ?. kind !== "device" ) return ;
4288+ const sessionStillExists = deviceState . sessions . some (
4289+ ( session ) =>
4290+ session . threadId === activeThreadRef . threadId &&
4291+ session . hostId === source . hostId &&
4292+ session . deviceId === source . deviceId ,
4293+ ) ;
4294+ if ( ! sessionStillExists ) usePreviewMiniPlayerStore . getState ( ) . close ( activeThreadRef ) ;
4295+ } , [ activePreviewMiniPlayer , activeThreadRef , deviceState . sessions , deviceStateLoaded ] ) ;
42654296 const openFileSurface = useCallback (
42664297 ( relativePath : string ) => {
42674298 if ( ! activeThreadRef || ! activeProject ) return ;
@@ -4421,10 +4452,15 @@ export default function ChatView(props: ChatViewProps) {
44214452 ] ) ;
44224453 const closePreviewPanel = useCallback ( ( ) => {
44234454 if ( activeThreadRef ) {
4455+ // Closing the panel on a live browser or device floats it instead of dropping it.
44244456 if ( activeRightPanelSurface ?. kind === "preview" && activeRightPanelSurface . resourceId ) {
44254457 usePreviewMiniPlayerStore
44264458 . getState ( )
4427- . open ( activeThreadRef , activeRightPanelSurface . resourceId ) ;
4459+ . open ( activeThreadRef , browserMiniPlayerSource ( activeRightPanelSurface . resourceId ) ) ;
4460+ } else if ( activeRightPanelSurface ?. kind === "device" && activeRightPanelSurface . target ) {
4461+ usePreviewMiniPlayerStore
4462+ . getState ( )
4463+ . open ( activeThreadRef , { kind : "device" , ...activeRightPanelSurface . target } ) ;
44284464 }
44294465 setMaximizedRightPanelThreadKey ( null ) ;
44304466 useRightPanelStore . getState ( ) . close ( activeThreadRef ) ;
@@ -8834,9 +8870,9 @@ export default function ChatView(props: ChatViewProps) {
88348870
88358871 { activeThreadRef && activePreviewMiniPlayer && previewMiniPlayerVisible ? (
88368872 < ThreadPreviewMiniPlayer
8837- key = { `${ activeThreadKey } :${ activePreviewMiniPlayer . tabId } ` }
8873+ key = { `${ activeThreadKey } :${ previewMiniPlayerSourceKey ( activePreviewMiniPlayer . source ) } ` }
88388874 threadRef = { activeThreadRef }
8839- tabId = { activePreviewMiniPlayer . tabId }
8875+ miniPlayer = { activePreviewMiniPlayer }
88408876 bottomInset = { isDraftHeroState ? 0 : composerOverlayHeight }
88418877 />
88428878 ) : null }
0 commit comments