11import { Outlet , createFileRoute , redirect } from "@tanstack/react-router" ;
22import { useAtomValue } from "@effect/atom-react" ;
3+ import {
4+ isAtomCommandInterrupted ,
5+ squashAtomCommandFailure ,
6+ } from "@t3tools/client-runtime/state/runtime" ;
37import { useEffect , useMemo } from "react" ;
48
59import { isCommandPaletteOpen } from "../commandPaletteBus" ;
@@ -11,6 +15,7 @@ import { selectProjectGroupingSettings } from "../logicalProject";
1115import { buildSidebarProjectSnapshots } from "../sidebarProjectGrouping" ;
1216import { dispatchPreviewAction } from "../components/preview/previewActionBus" ;
1317import { useHandleNewThread } from "../hooks/useHandleNewThread" ;
18+ import { useThreadActions } from "../hooks/useThreadActions" ;
1419import { startNewThreadFromContext } from "../lib/chatThreadActions" ;
1520import { isPreviewFocused } from "../lib/previewFocus" ;
1621import { isTerminalFocused } from "../lib/terminalFocus" ;
@@ -27,6 +32,7 @@ function ChatRouteGlobalShortcuts() {
2732 const selectedThreadKeysSize = useThreadSelectionStore ( ( state ) => state . selectedThreadKeys . size ) ;
2833 const { activeDraftThread, activeThread, defaultProjectRef, handleNewThread, routeThreadRef } =
2934 useHandleNewThread ( ) ;
35+ const { settleThread } = useThreadActions ( ) ;
3036 const keybindings = useAtomValue ( primaryServerKeybindingsAtom ) ;
3137 const legacySidebarEnabled = useLegacySidebarEnabled ( ) ;
3238 const projectGroupingSettings = useClientSettings ( selectProjectGroupingSettings ) ;
@@ -108,6 +114,26 @@ function ChatRouteGlobalShortcuts() {
108114 return ;
109115 }
110116
117+ if ( command === "thread.settle" ) {
118+ event . preventDefault ( ) ;
119+ event . stopPropagation ( ) ;
120+ if ( ! routeThreadRef || event . repeat ) return ;
121+ void ( async ( ) => {
122+ const result = await settleThread ( routeThreadRef ) ;
123+ if ( result . _tag === "Failure" && ! isAtomCommandInterrupted ( result ) ) {
124+ const error = squashAtomCommandFailure ( result ) ;
125+ toastManager . add (
126+ stackedThreadToast ( {
127+ type : "error" ,
128+ title : "Failed to settle thread" ,
129+ description : error instanceof Error ? error . message : "An error occurred." ,
130+ } ) ,
131+ ) ;
132+ }
133+ } ) ( ) ;
134+ return ;
135+ }
136+
111137 if ( command === "preview.toggle" ) {
112138 event . preventDefault ( ) ;
113139 event . stopPropagation ( ) ;
@@ -167,6 +193,7 @@ function ChatRouteGlobalShortcuts() {
167193 projectGroupCount ,
168194 routeThreadRef ,
169195 selectedThreadKeysSize ,
196+ settleThread ,
170197 legacySidebarEnabled ,
171198 terminalOpen ,
172199 ] ) ;
0 commit comments