feat(ui): implement StepErrorEvent handling in AppModel

Render step errors above the BT region via tea.Println() using the
existing RenderErrorMessage() renderers, mirroring the StepCompleteEvent
pattern. Reset stream state and transition back to stateInput on error.
This commit is contained in:
Ed Zynda
2026-02-26 01:02:34 +03:00
parent be77e716cb
commit 6398b3e637
+24 -3
View File
@@ -354,10 +354,12 @@ func (m *AppModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.canceling = false
case app.StepErrorEvent:
// Render the error inline in the stream area, then return to input.
// Render the error above the BT region via tea.Println, reset stream, return to input.
if msg.Err != nil {
cmds = append(cmds, m.printErrorResponse(msg))
}
if m.stream != nil {
_, cmd := m.stream.Update(msg)
cmds = append(cmds, cmd)
m.stream.Reset()
}
m.state = stateInput
m.canceling = false
@@ -484,6 +486,25 @@ func (m *AppModel) printCompletedResponse(evt app.StepCompleteEvent) tea.Cmd {
return tea.Println(rendered)
}
// printErrorResponse builds a tea.Cmd that emits a styled error message above
// the BT-managed region using tea.Println. This is used on StepErrorEvent.
func (m *AppModel) printErrorResponse(evt app.StepErrorEvent) tea.Cmd {
if evt.Err == nil {
return nil
}
var rendered string
if m.compactMode {
msg := m.compactRdr.RenderErrorMessage(evt.Err.Error(), time.Now())
rendered = msg.Content
} else {
msg := m.renderer.RenderErrorMessage(evt.Err.Error(), time.Now())
rendered = msg.Content
}
return tea.Println(rendered)
}
// distributeHeight recalculates child component heights after a window resize.
// The input region has a fixed height; the stream region gets the remainder.
func (m *AppModel) distributeHeight() {