@@ -251,9 +251,6 @@ import { threadPullRequestPanelTarget } from "./pullRequest/pullRequestDetail.lo
251251import { RightPanelTabs } from "./RightPanelTabs" ;
252252import { LinkPullRequestDialogHost } from "./pullRequest/LinkPullRequestDialog" ;
253253import { useDeviceState } from "~/state/device" ;
254- import { DeviceSetup } from "./device/DeviceSetup" ;
255- import { Dialog } from "./ui/dialog" ;
256- import { WizardPopup } from "./ui/wizard" ;
257254import { BranchToolbar , type BranchToolbarHandle } from "./BranchToolbar" ;
258255import { makeWorkspaceFileDropHandlers } from "./chat/workspaceFileDrop" ;
259256import { isEditableFocused } from "../lib/editableFocus" ;
@@ -387,7 +384,16 @@ import { createPageScrollController, type PageScrollKey } from "./chat/pageScrol
387384import { isTimelineScrollTarget } from "./chat/timelineScrollTarget" ;
388385import { DraftHeroHeadline } from "./chat/DraftHeroHeadline" ;
389386import { ExpandedImageDialog } from "./chat/ExpandedImageDialog" ;
390- import { PullRequestThreadDialog } from "./PullRequestThreadDialog" ;
387+ import {
388+ BranchRestoreConfirmHost ,
389+ DeviceSetupDialogHost ,
390+ openBranchRestoreConfirm ,
391+ openDeviceSetupDialog ,
392+ openPullRequestThreadDialog ,
393+ openRevertConfirm ,
394+ PullRequestThreadDialogHost ,
395+ RevertConfirmHost ,
396+ } from "./chat/ChatOverlayHosts" ;
391397import type { AssistantCitationRequest } from "./chat/AssistantCitationSource" ;
392398import { MessagesTimeline , type MessagesTimelineHistoryControls } from "./chat/MessagesTimeline" ;
393399import { ProviderSubagentBar } from "./chat/ProviderSubagentBar" ;
@@ -479,7 +485,6 @@ import {
479485 LAST_INVOKED_SCRIPT_BY_PROJECT_KEY ,
480486 LastInvokedScriptByProjectSchema ,
481487 type LocalDispatchSnapshot ,
482- PullRequestDialogState ,
483488 cloneComposerImageForRetry ,
484489 deriveLockedProvider ,
485490 readFileAsDataUrl ,
@@ -519,15 +524,6 @@ import { useAtomCommand } from "../state/use-atom-command";
519524import { useOrchestrationCommand } from "../state/use-orchestration-command" ;
520525import { useAtomQueryRunner } from "../state/use-atom-query-runner" ;
521526import { Button , InlineButton } from "./ui/button" ;
522- import {
523- AlertDialog ,
524- AlertDialogClose ,
525- AlertDialogDescription ,
526- AlertDialogFooter ,
527- AlertDialogHeader ,
528- AlertDialogPopup ,
529- AlertDialogTitle ,
530- } from "./ui/alert-dialog" ;
531527import { Tooltip , TooltipPopup , TooltipTrigger } from "./ui/tooltip" ;
532528import { ServerUpdateAction } from "./ServerUpdateAction" ;
533529import { useAutoBalanceUpdateBanner } from "./chat/useAutoBalanceUpdateBanner" ;
@@ -1328,8 +1324,6 @@ export default function ChatView(props: ChatViewProps) {
13281324 const [ workspaceLayoutElement , setWorkspaceLayoutElement ] = useState < HTMLDivElement | null > ( null ) ;
13291325 const threadPanelPopoverAnchorRef = useRef < HTMLElement | null > ( null ) ;
13301326 const [ terminalFocusRequestId , setTerminalFocusRequestId ] = useState ( 0 ) ;
1331- const [ pullRequestDialogState , setPullRequestDialogState ] =
1332- useState < PullRequestDialogState | null > ( null ) ;
13331327 const [ terminalUiLaunchContext , setTerminalUiLaunchContext ] =
13341328 useState < TerminalLaunchContext | null > ( null ) ;
13351329 const [ attachmentPreviewHandoffByMessageId , setAttachmentPreviewHandoffByMessageId ] = useState <
@@ -2089,17 +2083,11 @@ export default function ChatView(props: ChatViewProps) {
20892083 if ( ! canCheckoutPullRequestIntoThread ) {
20902084 return ;
20912085 }
2092- setPullRequestDialogState ( {
2093- initialReference : reference ?? null ,
2094- key : Date . now ( ) ,
2095- } ) ;
2086+ if ( activeThreadKey === null ) return ;
2087+ openPullRequestThreadDialog ( activeThreadKey , reference ) ;
20962088 } ;
20972089 const openPullRequestDialogStable = useStableCallback ( openPullRequestDialog ) ;
20982090
2099- const closePullRequestDialog = ( ) => {
2100- setPullRequestDialogState ( null ) ;
2101- } ;
2102-
21032091 const openOrReuseProjectDraftThread = async ( input : {
21042092 branch : string ;
21052093 worktreePath : string | null ;
@@ -3730,11 +3718,10 @@ export default function ChatView(props: ChatViewProps) {
37303718 const { state : deviceState , loaded : deviceStateLoaded } = useDeviceState (
37313719 activeThreadRef ?. environmentId ?? null ,
37323720 ) ;
3733- const [ deviceSetupThread , setDeviceSetupThread ] = useState < ScopedThreadRef | null > ( null ) ;
37343721 const addDeviceSurface = ( ) => {
37353722 if ( ! activeThreadRef ) return ;
37363723 if ( ! deviceState . onboardingCompleted || deviceState . hostStatus === "disabled" ) {
3737- setDeviceSetupThread ( activeThreadRef ) ;
3724+ openDeviceSetupDialog ( scopedThreadKey ( activeThreadRef ) ) ;
37383725 return ;
37393726 }
37403727 useRightPanelStore . getState ( ) . open ( activeThreadRef , "device" ) ;
@@ -4564,7 +4551,6 @@ export default function ChatView(props: ChatViewProps) {
45644551 if ( timelineThreadReset . threadKey !== activeThreadKey ) {
45654552 const followEnd = readTimelinePosition ( routeThreadKey ) ?. atEnd !== false ;
45664553 setTimelineThreadReset ( { threadKey : activeThreadKey , followEnd } ) ;
4567- setPullRequestDialogState ( null ) ;
45684554 setTimelineLiveFollowEnabled ( followEnd ) ;
45694555 setShowScrollToBottom ( ! followEnd ) ;
45704556 }
@@ -4988,7 +4974,6 @@ export default function ChatView(props: ChatViewProps) {
49884974 } ;
49894975 const handleUnsnoozeActiveThreadStable = useStableCallback ( handleUnsnoozeActiveThread ) ;
49904976 const [ isRestoringThreadBranch , setIsRestoringThreadBranch ] = useState ( false ) ;
4991- const [ branchRestoreConfirmOpen , setBranchRestoreConfirmOpen ] = useState ( false ) ;
49924977 const [ revealedBranchMismatchKey , setRevealedBranchMismatchKey ] = useState < string | null > ( null ) ;
49934978 const [ , setBranchMismatchDismissTick ] = useState ( 0 ) ;
49944979 const composerHasDraftContent = useComposerDraftStore ( ( store ) =>
@@ -5075,6 +5060,9 @@ export default function ChatView(props: ChatViewProps) {
50755060 setIsRestoringThreadBranch ( false ) ;
50765061 scheduleComposerFocus ( ) ;
50775062 } ;
5063+ const handleSwitchCheckoutToThreadStable = useStableCallback ( ( ) => {
5064+ void handleSwitchCheckoutToThread ( ) ;
5065+ } ) ;
50785066 // The interrupt path also accepts a completed run while its provider still
50795067 // has background work.
50805068 const activeBackgroundTasks = ! isWorking && activeThread ? pendingBackgroundTasks : [ ] ;
@@ -5401,7 +5389,7 @@ export default function ChatView(props: ChatViewProps) {
54015389 const handleRestoreThreadBranch = ( ) => {
54025390 if ( ! canWriteSourceControl ) return ;
54035391 if ( gitStatusQuery . data ?. hasWorkingTreeChanges ) {
5404- setBranchRestoreConfirmOpen ( true ) ;
5392+ if ( activeThreadKey !== null ) openBranchRestoreConfirm ( activeThreadKey ) ;
54055393 return ;
54065394 }
54075395 void handleSwitchCheckoutToThread ( ) ;
@@ -5761,16 +5749,6 @@ export default function ChatView(props: ChatViewProps) {
57615749 } ;
57625750 } , [ activeThreadId , composerRef ] ) ;
57635751
5764- const [ pendingRevert , setPendingRevert ] = useState < {
5765- turnCount : number ;
5766- messageId : MessageId ;
5767- routeThreadKey : string ;
5768- } | null > ( null ) ;
5769-
5770- if ( pendingRevert && pendingRevert . routeThreadKey !== routeThreadKey ) {
5771- setPendingRevert ( null ) ;
5772- }
5773-
57745752 const onRevertToTurnCount = async (
57755753 turnCount : number ,
57765754 messageId : MessageId ,
@@ -5819,7 +5797,7 @@ export default function ChatView(props: ChatViewProps) {
58195797 return ;
58205798 }
58215799 if ( restoreFiles === undefined ) {
5822- setPendingRevert ( { turnCount, messageId, routeThreadKey } ) ;
5800+ openRevertConfirm ( routeThreadKey , { turnCount, messageId } ) ;
58235801 return ;
58245802 }
58255803
@@ -5858,6 +5836,10 @@ export default function ChatView(props: ChatViewProps) {
58585836 }
58595837 } ;
58605838 const onRevertToTurnCountStable = useStableCallback ( onRevertToTurnCount ) ;
5839+ const onConfirmRevert = ( turnCount : number , messageId : MessageId , restoreFiles : boolean ) => {
5840+ void onRevertToTurnCount ( turnCount , messageId , restoreFiles ) ;
5841+ } ;
5842+ const onConfirmRevertStable = useStableCallback ( onConfirmRevert ) ;
58615843
58625844 const onRollbackCheckpoint = async ( input : {
58635845 readonly checkpointId : string ;
@@ -7953,29 +7935,11 @@ export default function ChatView(props: ChatViewProps) {
79537935 ref = { setWorkspaceLayoutElement }
79547936 className = "relative flex min-h-0 min-w-0 flex-1 overflow-hidden bg-background"
79557937 >
7956- < Dialog
7957- open = {
7958- deviceSetupThread !== null &&
7959- deviceSetupThread . environmentId === activeThreadRef ?. environmentId &&
7960- deviceSetupThread . threadId === activeThreadRef ?. threadId
7961- }
7962- onOpenChange = { ( open ) => {
7963- if ( ! open ) setDeviceSetupThread ( null ) ;
7964- } }
7965- >
7966- < WizardPopup >
7967- { activeThreadRef ? (
7968- < DeviceSetup
7969- environmentId = { activeThreadRef . environmentId }
7970- state = { deviceState }
7971- onComplete = { ( ) => {
7972- useRightPanelStore . getState ( ) . open ( activeThreadRef , "device" ) ;
7973- setDeviceSetupThread ( null ) ;
7974- } }
7975- />
7976- ) : null }
7977- </ WizardPopup >
7978- </ Dialog >
7938+ < DeviceSetupDialogHost
7939+ threadKey = { activeThreadKey }
7940+ threadRef = { activeThreadRef }
7941+ state = { deviceState }
7942+ />
79797943 { rightPanelControlsAtRoot ? panelLayoutControls : null }
79807944 < div
79817945 className = { cn (
@@ -8561,55 +8525,22 @@ export default function ChatView(props: ChatViewProps) {
85618525 />
85628526 ) : null }
85638527
8564- < AlertDialog open = { branchRestoreConfirmOpen } onOpenChange = { setBranchRestoreConfirmOpen } >
8565- < AlertDialogPopup >
8566- < AlertDialogHeader >
8567- < AlertDialogTitle >
8568- Switch to{ " " }
8569- < code className = "font-medium" >
8570- { localCheckoutBranchMismatch ?. threadBranch ?? "" }
8571- </ code >
8572- ?
8573- </ AlertDialogTitle >
8574- < AlertDialogDescription >
8575- You have uncommitted changes. They'll carry over to the other branch, or block
8576- the switch if they conflict.
8577- </ AlertDialogDescription >
8578- </ AlertDialogHeader >
8579- < AlertDialogFooter >
8580- < AlertDialogClose render = { < Button variant = "outline" /> } > Cancel</ AlertDialogClose >
8581- < Button
8582- variant = "default"
8583- disabled = { ! canWriteSourceControl }
8584- onClick = { ( ) => {
8585- setBranchRestoreConfirmOpen ( false ) ;
8586- void handleSwitchCheckoutToThread ( ) ;
8587- } }
8588- >
8589- Switch branch
8590- </ Button >
8591- </ AlertDialogFooter >
8592- </ AlertDialogPopup >
8593- </ AlertDialog >
8528+ < BranchRestoreConfirmHost
8529+ threadKey = { activeThreadKey }
8530+ threadBranch = { localCheckoutBranchMismatch ?. threadBranch ?? "" }
8531+ canWriteSourceControl = { canWriteSourceControl }
8532+ onConfirm = { handleSwitchCheckoutToThreadStable }
8533+ />
85948534
85958535 < ThreadDetailsPanel { ...threadDetailsPanelProps } />
85968536
8597- { pullRequestDialogState ? (
8598- < PullRequestThreadDialog
8599- key = { pullRequestDialogState . key }
8600- open
8601- environmentId = { activeThread . environmentId }
8602- threadId = { activeThread . id }
8603- cwd = { activeProject ?. workspaceRoot ?? null }
8604- initialReference = { pullRequestDialogState . initialReference }
8605- onOpenChange = { ( open ) => {
8606- if ( ! open ) {
8607- closePullRequestDialog ( ) ;
8608- }
8609- } }
8610- onPrepared = { handlePreparedPullRequestThreadStable }
8611- />
8612- ) : null }
8537+ < PullRequestThreadDialogHost
8538+ threadKey = { activeThreadKey }
8539+ environmentId = { activeThread . environmentId }
8540+ threadId = { activeThread . id }
8541+ cwd = { activeProject ?. workspaceRoot ?? null }
8542+ onPrepared = { handlePreparedPullRequestThreadStable }
8543+ />
86138544 </ ThreadFindCanvas >
86148545 </ div >
86158546
@@ -8736,44 +8667,7 @@ export default function ChatView(props: ChatViewProps) {
87368667 </ RightPanelSheet >
87378668 ) : null }
87388669
8739- < AlertDialog
8740- open = { pendingRevert !== null && pendingRevert . routeThreadKey === routeThreadKey }
8741- onOpenChange = { ( open ) => {
8742- if ( ! open ) setPendingRevert ( null ) ;
8743- } }
8744- >
8745- < AlertDialogPopup >
8746- < AlertDialogHeader >
8747- < AlertDialogTitle > Edit from here?</ AlertDialogTitle >
8748- < AlertDialogDescription >
8749- Rewind chat to before this message. Your prompt and attachments return to the
8750- composer.
8751- </ AlertDialogDescription >
8752- </ AlertDialogHeader >
8753- < AlertDialogFooter >
8754- < AlertDialogClose render = { < Button variant = "outline" /> } > Cancel</ AlertDialogClose >
8755- < Button
8756- variant = "destructive"
8757- onClick = { ( ) => {
8758- if ( ! pendingRevert || pendingRevert . routeThreadKey !== routeThreadKey ) return ;
8759- setPendingRevert ( null ) ;
8760- void onRevertToTurnCount ( pendingRevert . turnCount , pendingRevert . messageId , true ) ;
8761- } }
8762- >
8763- Revert files too
8764- </ Button >
8765- < Button
8766- onClick = { ( ) => {
8767- if ( ! pendingRevert || pendingRevert . routeThreadKey !== routeThreadKey ) return ;
8768- setPendingRevert ( null ) ;
8769- void onRevertToTurnCount ( pendingRevert . turnCount , pendingRevert . messageId , false ) ;
8770- } }
8771- >
8772- Revert and keep changes
8773- </ Button >
8774- </ AlertDialogFooter >
8775- </ AlertDialogPopup >
8776- </ AlertDialog >
8670+ < RevertConfirmHost threadKey = { routeThreadKey } onConfirm = { onConfirmRevertStable } />
87778671 < LinkPullRequestDialogHost />
87788672 { expandedImage && (
87798673 < ExpandedImageDialog
0 commit comments