@@ -1198,6 +1198,7 @@ func (m *Model) renderChatMessages() string {
11981198 label := m .styles .ChatAssistant .Render (" " + m .llmModelLabel () + " " )
11991199 text := msg .Content
12001200 sql := msg .SQL
1201+ isLastMessage := i == len (m .chat .Messages )- 1
12011202
12021203 var parts []string
12031204
@@ -1220,13 +1221,14 @@ func (m *Model) renderChatMessages() string {
12201221 }
12211222
12221223 // Determine what to show on the label line.
1223- if m .chat .StreamingSQL && sql == "" {
1224+ // Only show spinner for the currently streaming message (last one).
1225+ if isLastMessage && m .chat .StreamingSQL && sql == "" {
12241226 // Stage 1: generating SQL query
12251227 labelLine := label + " " + m .chat .Spinner .View () + " " + m .styles .HeaderHint .Render (
12261228 "generating query" ,
12271229 )
12281230 rendered = labelLine
1229- } else if text == "" && m .chat .Streaming && ! m .chat .StreamingSQL {
1231+ } else if isLastMessage && text == "" && m .chat .Streaming && ! m .chat .StreamingSQL {
12301232 // Stage 2: thinking about response (may have SQL already)
12311233 labelLine := label + " " + m .chat .Spinner .View () + " " + m .styles .HeaderHint .Render ("thinking" )
12321234 // If we have parts (e.g., SQL), show them below the label.
@@ -1349,16 +1351,18 @@ func (m *Model) handleChatKey(key tea.KeyMsg) (tea.Model, tea.Cmd) {
13491351 // Cancel context - this will close the stream channel and any
13501352 // pending waitForChunk/waitForSQLChunk will return nil.
13511353 cancelFn ()
1352- // Remove "generating query" notice and add cancellation message .
1354+ // Remove all trailing notices and incomplete assistant messages .
13531355 m .removeLastNotice ()
1354- // If we have an incomplete assistant message, remove it.
1356+ // Remove the assistant message that was being streamed.
1357+ // It doesn't matter if it has partial content or SQL - if we're
1358+ // cancelling, we don't want to show it.
13551359 if len (m .chat .Messages ) > 0 &&
1356- m .chat .Messages [len (m .chat .Messages )- 1 ].Role == roleAssistant &&
1357- m .chat .Messages [len (m .chat .Messages )- 1 ].Content == "" {
1360+ m .chat .Messages [len (m .chat .Messages )- 1 ].Role == roleAssistant {
13581361 m .chat .Messages = m .chat .Messages [:len (m .chat .Messages )- 1 ]
13591362 }
1363+ // Add cancellation notice.
13601364 m .chat .Messages = append (m .chat .Messages , chatMessage {
1361- Role : roleNotice , Content : "Cancelled " ,
1365+ Role : roleNotice , Content : "Interrupted " ,
13621366 })
13631367 m .refreshChatViewport ()
13641368 return m , nil
0 commit comments