@@ -36,6 +36,8 @@ interface ChatPanelProps {
3636 sessionData : MutableRefObject < string >
3737 onSessionDataChange : ( data : string ) => void
3838 onGenerated : ( data : GeneratedData ) => void
39+ /** Clear preview in parent when user resets the chat. */
40+ onChatReset : ( ) => void
3941 onCreateNotes : ( ) => void
4042 onPreviewPage : ( page : { title : string ; content : string } ) => void
4143 generatedData : GeneratedData | null
@@ -48,6 +50,7 @@ export function ChatPanel({
4850 sessionData,
4951 onSessionDataChange,
5052 onGenerated,
53+ onChatReset,
5154 onCreateNotes,
5255 onPreviewPage,
5356 generatedData,
@@ -98,7 +101,7 @@ export function ChatPanel({
98101 } )
99102 } , [ config . apiKey , config . apiEndpoint , config . teamPath , prepareSendMessagesRequest ] )
100103
101- const { messages, sendMessage, status, error } = useChat ( {
104+ const { messages, sendMessage, status, error, setMessages , stop , clearError } = useChat ( {
102105 transport,
103106 } )
104107
@@ -184,6 +187,21 @@ export function ChatPanel({
184187 }
185188 }
186189
190+ const canStartOver = messages . length > 0 || generatedData !== null
191+
192+ function handleStartOver ( ) {
193+ if ( ! canStartOver ) return
194+ if ( ! window . confirm ( t ( 'chat.startOverConfirm' ) ) ) return
195+ if ( status === 'submitted' || status === 'streaming' ) {
196+ stop ( )
197+ }
198+ clearError ( )
199+ setMessages ( [ ] )
200+ previewAppliedRef . current = null
201+ setInputValue ( '' )
202+ onChatReset ( )
203+ }
204+
187205 return (
188206 < div className = "flex h-full flex-col bg-zinc-50/80 dark:bg-zinc-950/50" >
189207 { /* Header */ }
@@ -197,6 +215,16 @@ export function ChatPanel({
197215 </ span >
198216 </ div >
199217 < div className = "flex shrink-0 items-center gap-2" >
218+ { canStartOver && (
219+ < button
220+ type = "button"
221+ onClick = { handleStartOver }
222+ title = { t ( 'chat.startOverTitle' ) }
223+ className = "rounded-lg border border-zinc-300 bg-white px-2.5 py-1.5 text-xs font-medium text-zinc-700 transition hover:bg-zinc-50 dark:border-zinc-600 dark:bg-zinc-900 dark:text-zinc-200 dark:hover:bg-zinc-800 sm:px-3 sm:text-sm"
224+ >
225+ { t ( 'chat.startOver' ) }
226+ </ button >
227+ ) }
200228 < AppSettingsBar className = "hidden sm:inline-flex" />
201229 { generatedData && (
202230 < button
@@ -213,7 +241,17 @@ export function ChatPanel({
213241 ) }
214242 </ div >
215243 </ div >
216- < div className = "flex justify-end border-b border-zinc-200/60 px-4 py-2 dark:border-zinc-800 sm:hidden" >
244+ < div className = "flex justify-end gap-2 border-b border-zinc-200/60 px-4 py-2 dark:border-zinc-800 sm:hidden" >
245+ { canStartOver && (
246+ < button
247+ type = "button"
248+ onClick = { handleStartOver }
249+ title = { t ( 'chat.startOverTitle' ) }
250+ className = "rounded-lg border border-zinc-300 bg-white px-2.5 py-1.5 text-xs font-medium text-zinc-700 transition hover:bg-zinc-50 dark:border-zinc-600 dark:bg-zinc-900 dark:text-zinc-200 dark:hover:bg-zinc-800"
251+ >
252+ { t ( 'chat.startOver' ) }
253+ </ button >
254+ ) }
217255 < AppSettingsBar />
218256 </ div >
219257
0 commit comments