1515 pre { @apply whitespace-pre-wrap; }
1616 /* TODO: fix markdown table */
1717 }
18+ .bg-base-100 {background-color : var (--fallback-b1 , oklch (var (--b1 )/ 1 ))}
19+ .bg-base-200 {background-color : var (--fallback-b2 , oklch (var (--b2 )/ 1 ))}
20+ .bg-base-300 {background-color : var (--fallback-b3 , oklch (var (--b3 )/ 1 ))}
1821 </ style >
1922</ head >
2023
@@ -134,7 +137,7 @@ <h2 class="font-bold mb-4 ml-4">Conversations</h2>
134137 // markdown support
135138 const VueMarkdown = defineComponent (
136139 ( props ) => {
137- const md = shallowRef ( new markdownit ( props . options ?? { } ) ) ;
140+ const md = shallowRef ( new markdownit ( props . options ?? { breaks : true } ) ) ;
138141 for ( const plugin of props . plugins ?? [ ] ) {
139142 md . value . use ( plugin ) ;
140143 }
@@ -182,15 +185,20 @@ <h2 class="font-bold mb-4 ml-4">Conversations</h2>
182185 } ,
183186 } ;
184187
185- // format of message: { id: number, role: 'user' | 'assistant', content: string }
188+ // scroll to bottom of chat messages
189+ const chatScrollToBottom = ( ) => {
190+ const msgListElem = document . getElementById ( 'messages-list' ) ;
191+ setTimeout ( ( ) => msgListElem . scrollTo ( { top : msgListElem . scrollHeight } ) , 1 ) ;
192+ } ;
193+
186194 createApp ( {
187195 components : {
188196 VueMarkdown,
189197 } ,
190198 data ( ) {
191199 return {
192200 conversations : Conversations . getAll ( ) ,
193- messages : [ ] ,
201+ messages : [ ] , // { id: number, role: 'user' | 'assistant', content: string }
194202 viewingConvId : Conversations . getNewConvId ( ) ,
195203 inputMsg : '' ,
196204 isGenerating : false ,
@@ -204,11 +212,8 @@ <h2 class="font-bold mb-4 ml-4">Conversations</h2>
204212 mounted ( ) {
205213 // scroll to the bottom when the pending message height is updated
206214 const pendingMsgElem = document . getElementById ( 'pending-msg' ) ;
207- const msgListElem = document . getElementById ( 'messages-list' ) ;
208215 const resizeObserver = new ResizeObserver ( ( ) => {
209- if ( this . isGenerating ) {
210- msgListElem . scrollTo ( { top : msgListElem . scrollHeight } ) ;
211- }
216+ if ( this . isGenerating ) chatScrollToBottom ( ) ;
212217 } ) ;
213218 resizeObserver . observe ( pendingMsgElem ) ;
214219 } ,
@@ -217,11 +222,13 @@ <h2 class="font-bold mb-4 ml-4">Conversations</h2>
217222 if ( this . isGenerating ) return ;
218223 this . viewingConvId = Conversations . getNewConvId ( ) ;
219224 this . fetchMessages ( ) ;
225+ chatScrollToBottom ( ) ;
220226 } ,
221227 setViewingConv ( convId ) {
222228 if ( this . isGenerating ) return ;
223229 this . viewingConvId = convId ;
224230 this . fetchMessages ( ) ;
231+ chatScrollToBottom ( ) ;
225232 } ,
226233 deleteConv ( convId ) {
227234 if ( this . isGenerating ) return ;
@@ -280,9 +287,7 @@ <h2 class="font-bold mb-4 ml-4">Conversations</h2>
280287 this . fetchMessages ( ) ;
281288 this . pendingMsg = null ;
282289 this . isGenerating = false ;
283- setTimeout ( ( ) => {
284- document . getElementById ( 'msg-input' ) . focus ( ) ;
285- } , 1 ) ;
290+ setTimeout ( ( ) => document . getElementById ( 'msg-input' ) . focus ( ) , 1 ) ;
286291 } catch ( error ) {
287292 console . error ( error ) ;
288293 alert ( error ) ;
0 commit comments