@@ -5804,15 +5804,13 @@ export default function ChatView(props: ChatViewProps) {
58045804 pendingApprovals . length > 0 ||
58055805 pendingUserInputs . length > 0 ||
58065806 showPlanFollowUpPrompt ;
5807- const compactDisabled = compactThreadUnavailable || composerHasUnsentContent ;
5807+ const compactDisabled = compactThreadUnavailable ;
58085808 const compactDisabledReason = compactDisabled
5809- ? composerHasUnsentContent
5810- ? "Send or clear your draft before compacting"
5811- : ! activeProject
5812- ? "Choose a project before compacting"
5813- : ! manualCompactionProviderAvailable
5814- ? "Compaction is unavailable for this provider"
5815- : "Compacting is unavailable right now"
5809+ ? ! activeProject
5810+ ? "Choose a project before compacting"
5811+ : ! manualCompactionProviderAvailable
5812+ ? "Compaction is unavailable for this provider"
5813+ : "Compacting is unavailable right now"
58165814 : null ;
58175815 const resumeCompactionBannerItem = useMemo < ComposerBannerStackItem | null > ( ( ) => {
58185816 if (
@@ -6402,6 +6400,78 @@ export default function ChatView(props: ChatViewProps) {
64026400 ] ,
64036401 ) ;
64046402
6403+ const onCompactContext = async ( ) => {
6404+ if ( compactDisabled || ! activeThread || ! clientSettingsHydrated || sendInFlightRef . current ) {
6405+ return ;
6406+ }
6407+ const context = composerRef . current ?. getSendContext ( ) ;
6408+ if ( ! context ?. providerAvailable ) return ;
6409+
6410+ // Compaction is a standalone command; the draft and its attachments stay local.
6411+ const threadId = activeThread . id ;
6412+ const messageId = newMessageId ( ) ;
6413+ const createdAt = new Date ( ) . toISOString ( ) ;
6414+ sendInFlightRef . current = true ;
6415+ beginLocalDispatch ( ) ;
6416+ setThreadError ( threadId , null ) ;
6417+ setOptimisticUserMessages ( ( messages ) => [
6418+ ...messages ,
6419+ {
6420+ id : messageId ,
6421+ role : "user" ,
6422+ text : "/compact" ,
6423+ turnId : null ,
6424+ createdAt,
6425+ updatedAt : createdAt ,
6426+ streaming : false ,
6427+ } ,
6428+ ] ) ;
6429+ scrollToEnd ( ) ;
6430+ try {
6431+ const settingsResult = await persistThreadSettingsForNextTurn ( {
6432+ threadId,
6433+ createdAt,
6434+ modelSelection : context . selectedModelSelection ,
6435+ ...( localCheckoutBranchMismatch
6436+ ? { branch : localCheckoutBranchMismatch . currentBranch }
6437+ : { } ) ,
6438+ runtimeMode,
6439+ interactionMode : context . interactionMode ,
6440+ } ) ;
6441+ const result =
6442+ settingsResult . _tag === "Failure"
6443+ ? settingsResult
6444+ : await startThreadTurn ( {
6445+ environmentId,
6446+ input : {
6447+ threadId,
6448+ message : { messageId, role : "user" , text : "/compact" , attachments : [ ] } ,
6449+ modelSelection : context . selectedModelSelection ,
6450+ runtimeMode,
6451+ interactionMode : context . interactionMode ,
6452+ createdAt,
6453+ } ,
6454+ } ) ;
6455+ if ( result . _tag === "Failure" ) {
6456+ setOptimisticUserMessages ( ( messages ) =>
6457+ messages . filter ( ( message ) => message . id !== messageId ) ,
6458+ ) ;
6459+ resetLocalDispatch ( ) ;
6460+ if ( ! isAtomCommandInterrupted ( result ) ) {
6461+ const error = squashAtomCommandFailure ( result ) ;
6462+ setThreadError (
6463+ threadId ,
6464+ error instanceof Error ? error . message : "Failed to compact context." ,
6465+ ) ;
6466+ }
6467+ } else {
6468+ clearUsageLimitsFor ( routeThreadKey ) ;
6469+ }
6470+ } finally {
6471+ sendInFlightRef . current = false ;
6472+ }
6473+ } ;
6474+
64056475 const onSend = async (
64066476 e ?: { preventDefault : ( ) => void } ,
64076477 submissionIntent : ComposerSubmissionIntent = "foreground" ,
@@ -8461,6 +8531,7 @@ export default function ChatView(props: ChatViewProps) {
84618531 onPageScrollKeyDown = { onComposerPageScrollKeyDown }
84628532 onPageScrollKeyUp = { onComposerPageScrollKeyUp }
84638533 onPageScrollRelease = { onComposerPageScrollRelease }
8534+ onCompactContext = { onCompactContext }
84648535 onSend = { onSend }
84658536 onInterrupt = { onInterrupt }
84668537 onImplementPlanInNewThread = { onImplementPlanInNewThread }
0 commit comments