@@ -194,6 +194,8 @@ import {
194194 useSidebarPendingFileDropStore ,
195195} from "../sidebarPendingFileDropStore" ;
196196import {
197+ browserMiniPlayerSource ,
198+ previewMiniPlayerSourceKey ,
197199 selectThreadPreviewMiniPlayer ,
198200 usePreviewMiniPlayerStore ,
199201} 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) ;
@@ -1962,7 +1966,7 @@ export default function ChatView(props: ChatViewProps) {
19621966 const renderedRightPanelSurface = rightPanelPresence . value ?. activeSurface ?? null ;
19631967 const renderedRightPanelSurfaces = rightPanelPresence . value ?. surfaces ?? [ ] ;
19641968 const previewMiniPlayerVisible = shouldRenderPreviewMiniPlayer (
1965- activePreviewMiniPlayer ?. tabId ?? null ,
1969+ activePreviewMiniPlayer ?. source ?? null ,
19661970 renderedRightPanelSurface ,
19671971 ) ;
19681972 const canMaximizeRightPanel = rightPanelOpen && ! shouldUseRightPanelSheet ;
@@ -1978,8 +1982,10 @@ export default function ChatView(props: ChatViewProps) {
19781982 } , [ activePreviewState . sessions , activeThreadRef ] ) ;
19791983
19801984 useEffect ( ( ) => {
1981- if ( ! activeThreadRef || ! activePreviewMiniPlayer ) return ;
1982- const miniTabStillExists = Boolean ( activePreviewState . sessions [ activePreviewMiniPlayer . tabId ] ) ;
1985+ if ( ! activeThreadRef || activePreviewMiniPlayer ?. source . kind !== "browser" ) return ;
1986+ const miniTabStillExists = Boolean (
1987+ activePreviewState . sessions [ activePreviewMiniPlayer . source . tabId ] ,
1988+ ) ;
19831989 if ( ! miniTabStillExists ) {
19841990 usePreviewMiniPlayerStore . getState ( ) . close ( activeThreadRef ) ;
19851991 }
@@ -4195,9 +4201,12 @@ export default function ChatView(props: ChatViewProps) {
41954201 }
41964202 useRightPanelStore . getState ( ) . open ( activeThreadRef , "device" ) ;
41974203 } , [ activeThreadRef , deviceState . onboardingCompleted , deviceState . hostStatus ] ) ;
4198- // Reconcile new server sessions into separate tabs, including sessions opened
4199- // by an agent or another client. The first snapshot is a baseline: persisted
4200- // tabs restore themselves, and existing sessions must not resurrect closed tabs.
4204+ // A device the agent opens floats over chat like an agent-driven browser,
4205+ // or becomes a panel tab when floating previews are off. Sessions opened by
4206+ // another client arrive the same way. The first snapshot is a baseline:
4207+ // persisted tabs restore themselves, and existing sessions must not
4208+ // resurrect closed tabs.
4209+ const autoShowFloatingPreview = useClientSettings ( selectAutoShowFloatingPreview ) ;
42014210 const previousDeviceSessions = useRef ( new Map < string , Set < string > > ( ) ) ;
42024211 useEffect ( ( ) => {
42034212 if ( ! activeThreadRef || ! deviceStateLoaded ) return ;
@@ -4208,9 +4217,24 @@ export default function ChatView(props: ChatViewProps) {
42084217 const key = ( session : ( typeof sessions ) [ number ] ) => `${ session . hostId } :${ session . deviceId } ` ;
42094218 const previous = previousDeviceSessions . current . get ( threadKey ) ;
42104219 previousDeviceSessions . current . set ( threadKey , new Set ( sessions . map ( key ) ) ) ;
4211- if ( ! previous || shouldUseRightPanelSheet ) return ;
4220+ if ( ! previous ) return ;
42124221 for ( const session of sessions ) {
42134222 if ( previous ?. has ( key ( session ) ) ) continue ;
4223+ const device = deviceState . devices . find (
4224+ ( entry ) => entry . hostId === session . hostId && entry . id === session . deviceId ,
4225+ ) ;
4226+ if ( ! device ) continue ;
4227+ const target = {
4228+ hostId : session . hostId ,
4229+ deviceId : session . deviceId ,
4230+ platform : device . platform ,
4231+ name : device . name ,
4232+ } ;
4233+ if ( autoShowFloatingPreview ) {
4234+ usePreviewMiniPlayerStore . getState ( ) . open ( activeThreadRef , { kind : "device" , ...target } ) ;
4235+ continue ;
4236+ }
4237+ if ( shouldUseRightPanelSheet ) continue ;
42144238 const existing = useRightPanelStore
42154239 . getState ( )
42164240 . byThreadKey [ scopedThreadKey ( activeThreadRef ) ] ?. surfaces . some (
@@ -4220,28 +4244,30 @@ export default function ChatView(props: ChatViewProps) {
42204244 surface . target . deviceId === session . deviceId ,
42214245 ) ;
42224246 if ( existing ) continue ;
4223- const device = deviceState . devices . find (
4224- ( entry ) => entry . hostId === session . hostId && entry . id === session . deviceId ,
4225- ) ;
4226- if ( ! device ) continue ;
4227- useRightPanelStore . getState ( ) . openDevice (
4228- activeThreadRef ,
4229- {
4230- hostId : session . hostId ,
4231- deviceId : session . deviceId ,
4232- platform : device . platform ,
4233- name : device . name ,
4234- } ,
4235- true ,
4236- ) ;
4247+ useRightPanelStore . getState ( ) . openDevice ( activeThreadRef , target , true ) ;
42374248 }
42384249 } , [
42394250 activeThreadRef ,
4251+ autoShowFloatingPreview ,
42404252 deviceStateLoaded ,
42414253 shouldUseRightPanelSheet ,
42424254 deviceState . sessions ,
42434255 deviceState . devices ,
42444256 ] ) ;
4257+ // A floating device follows its session: once the agent or another client
4258+ // closes the device there is nothing left to stream.
4259+ useEffect ( ( ) => {
4260+ if ( ! activeThreadRef || ! deviceStateLoaded ) return ;
4261+ const source = activePreviewMiniPlayer ?. source ;
4262+ if ( source ?. kind !== "device" ) return ;
4263+ const sessionStillExists = deviceState . sessions . some (
4264+ ( session ) =>
4265+ session . threadId === activeThreadRef . threadId &&
4266+ session . hostId === source . hostId &&
4267+ session . deviceId === source . deviceId ,
4268+ ) ;
4269+ if ( ! sessionStillExists ) usePreviewMiniPlayerStore . getState ( ) . close ( activeThreadRef ) ;
4270+ } , [ activePreviewMiniPlayer , activeThreadRef , deviceState . sessions , deviceStateLoaded ] ) ;
42454271 const openFileSurface = useCallback (
42464272 ( relativePath : string ) => {
42474273 if ( ! activeThreadRef || ! activeProject ) return ;
@@ -4401,10 +4427,15 @@ export default function ChatView(props: ChatViewProps) {
44014427 ] ) ;
44024428 const closePreviewPanel = useCallback ( ( ) => {
44034429 if ( activeThreadRef ) {
4430+ // Closing the panel on a live browser or device floats it instead of dropping it.
44044431 if ( activeRightPanelSurface ?. kind === "preview" && activeRightPanelSurface . resourceId ) {
44054432 usePreviewMiniPlayerStore
44064433 . getState ( )
4407- . open ( activeThreadRef , activeRightPanelSurface . resourceId ) ;
4434+ . open ( activeThreadRef , browserMiniPlayerSource ( activeRightPanelSurface . resourceId ) ) ;
4435+ } else if ( activeRightPanelSurface ?. kind === "device" && activeRightPanelSurface . target ) {
4436+ usePreviewMiniPlayerStore
4437+ . getState ( )
4438+ . open ( activeThreadRef , { kind : "device" , ...activeRightPanelSurface . target } ) ;
44084439 }
44094440 setMaximizedRightPanelThreadKey ( null ) ;
44104441 useRightPanelStore . getState ( ) . close ( activeThreadRef ) ;
@@ -8814,9 +8845,9 @@ export default function ChatView(props: ChatViewProps) {
88148845
88158846 { activeThreadRef && activePreviewMiniPlayer && previewMiniPlayerVisible ? (
88168847 < ThreadPreviewMiniPlayer
8817- key = { `${ activeThreadKey } :${ activePreviewMiniPlayer . tabId } ` }
8848+ key = { `${ activeThreadKey } :${ previewMiniPlayerSourceKey ( activePreviewMiniPlayer . source ) } ` }
88188849 threadRef = { activeThreadRef }
8819- tabId = { activePreviewMiniPlayer . tabId }
8850+ miniPlayer = { activePreviewMiniPlayer }
88208851 bottomInset = { isDraftHeroState ? 0 : composerOverlayHeight }
88218852 />
88228853 ) : null }
0 commit comments