@@ -10,25 +10,36 @@ import {
1010 CommandDisplay ,
1111 CommandLabel ,
1212} from "./Modal" ;
13- import { formatCompactCommand } from "@/utils/chatCommands" ;
13+ import { formatCompactCommand , type CompactOptions } from "@/utils/chatCommands" ;
1414
1515interface CompactModalProps {
1616 isOpen : boolean ;
1717 onClose : ( ) => void ;
18- onCompact : ( maxOutputTokens ?: number , model ?: string ) => Promise < void > ;
18+ onCompact : ( options : CompactOptions ) => Promise < void > ;
1919}
2020
2121const CompactModal : React . FC < CompactModalProps > = ( { isOpen, onClose, onCompact } ) => {
22- const [ maxOutputTokens , setMaxOutputTokens ] = useState < string > ( "" ) ;
23- const [ model , setModel ] = useState < string > ( "" ) ;
22+ const [ options , setOptions ] = useState < CompactOptions > ( { } ) ;
23+ const [ maxOutputTokensInput , setMaxOutputTokensInput ] = useState < string > ( "" ) ;
2424 const [ isLoading , setIsLoading ] = useState < boolean > ( false ) ;
2525 const infoId = useId ( ) ;
2626
27+ // Sync options with input fields
28+ useEffect ( ( ) => {
29+ setOptions ( {
30+ maxOutputTokens : maxOutputTokensInput . trim ( )
31+ ? parseInt ( maxOutputTokensInput . trim ( ) , 10 )
32+ : undefined ,
33+ model : options . model ?. trim ( ) || undefined ,
34+ continueMessage : options . continueMessage ?. trim ( ) || undefined ,
35+ } ) ;
36+ } , [ maxOutputTokensInput ] ) ;
37+
2738 // Reset form when modal opens
2839 useEffect ( ( ) => {
2940 if ( isOpen ) {
30- setMaxOutputTokens ( "" ) ;
31- setModel ( "" ) ;
41+ setOptions ( { } ) ;
42+ setMaxOutputTokensInput ( "" ) ;
3243 setIsLoading ( false ) ;
3344 }
3445 } , [ isOpen ] ) ;
@@ -45,12 +56,9 @@ const CompactModal: React.FC<CompactModalProps> = ({ isOpen, onClose, onCompact
4556 setIsLoading ( true ) ;
4657
4758 try {
48- const tokens = maxOutputTokens . trim ( ) ? parseInt ( maxOutputTokens . trim ( ) , 10 ) : undefined ;
49- const modelParam = model . trim ( ) || undefined ;
50-
51- await onCompact ( tokens , modelParam ) ;
52- setMaxOutputTokens ( "" ) ;
53- setModel ( "" ) ;
59+ await onCompact ( options ) ;
60+ setOptions ( { } ) ;
61+ setMaxOutputTokensInput ( "" ) ;
5462 onClose ( ) ;
5563 } catch ( err ) {
5664 console . error ( "Compact failed:" , err ) ;
@@ -60,9 +68,6 @@ const CompactModal: React.FC<CompactModalProps> = ({ isOpen, onClose, onCompact
6068 }
6169 } ;
6270
63- const tokensValue = maxOutputTokens . trim ( ) ? parseInt ( maxOutputTokens . trim ( ) , 10 ) : undefined ;
64- const modelValue = model . trim ( ) || undefined ;
65-
6671 return (
6772 < Modal
6873 isOpen = { isOpen }
@@ -78,8 +83,8 @@ const CompactModal: React.FC<CompactModalProps> = ({ isOpen, onClose, onCompact
7883 < input
7984 id = "maxOutputTokens"
8085 type = "number"
81- value = { maxOutputTokens }
82- onChange = { ( event ) => setMaxOutputTokens ( event . target . value ) }
86+ value = { maxOutputTokensInput }
87+ onChange = { ( event ) => setMaxOutputTokensInput ( event . target . value ) }
8388 disabled = { isLoading }
8489 placeholder = "e.g., 3000"
8590 min = "100"
@@ -94,14 +99,33 @@ const CompactModal: React.FC<CompactModalProps> = ({ isOpen, onClose, onCompact
9499 < input
95100 id = "model"
96101 type = "text"
97- value = { model }
98- onChange = { ( event ) => setModel ( event . target . value ) }
102+ value = { options . model ?? "" }
103+ onChange = { ( event ) =>
104+ setOptions ( { ...options , model : event . target . value || undefined } )
105+ }
99106 disabled = { isLoading }
100107 placeholder = "e.g., claude-3-5-sonnet-20241022"
101108 />
102109 < HelpText > Specify a model for compaction. Leave empty to use current model.</ HelpText >
103110 </ FormGroup >
104111
112+ < FormGroup >
113+ < label htmlFor = "continueMessage" > Continue Message (optional):</ label >
114+ < input
115+ id = "continueMessage"
116+ type = "text"
117+ value = { options . continueMessage ?? "" }
118+ onChange = { ( event ) =>
119+ setOptions ( { ...options , continueMessage : event . target . value || undefined } )
120+ }
121+ disabled = { isLoading }
122+ placeholder = "Message to send after compaction completes"
123+ />
124+ < HelpText >
125+ If provided, this message will be sent automatically after compaction finishes.
126+ </ HelpText >
127+ </ FormGroup >
128+
105129 < ModalInfo id = { infoId } >
106130 < p >
107131 Compaction will summarize your conversation history, allowing you to continue with a
@@ -112,7 +136,7 @@ const CompactModal: React.FC<CompactModalProps> = ({ isOpen, onClose, onCompact
112136
113137 < div >
114138 < CommandLabel > Equivalent command:</ CommandLabel >
115- < CommandDisplay > { formatCompactCommand ( tokensValue , modelValue ) } </ CommandDisplay >
139+ < CommandDisplay > { formatCompactCommand ( options ) } </ CommandDisplay >
116140 </ div >
117141
118142 < ModalActions >
0 commit comments