feat(tui): add support for reasoning in chat messages and update transcript handling
This commit is contained in:
@@ -88,28 +88,73 @@ fn render_one_message(
|
||||
),
|
||||
];
|
||||
|
||||
let mut first_line_handled = false;
|
||||
|
||||
if !msg.reasoning.trim().is_empty() {
|
||||
let reasoning_str = format!("[Thinking...]\n{}", msg.reasoning.trim());
|
||||
let reasoning_spans = super::markdown::render_markdown(&reasoning_str, content_width, false);
|
||||
// Dim the reasoning text
|
||||
let dimmed_spans: Vec<Span> = reasoning_spans.into_iter().map(|mut s| {
|
||||
s.style = s.style.fg(Theme::TEXT_DIM);
|
||||
s
|
||||
}).collect();
|
||||
let reasoning_lines = split_spans_into_lines(dimmed_spans);
|
||||
let mut lines_iter = reasoning_lines.into_iter();
|
||||
|
||||
if let Some(first) = lines_iter.next() {
|
||||
let mut spans = header_prefix.clone();
|
||||
spans.extend(first.spans);
|
||||
lines.push(Line::from(spans));
|
||||
first_line_handled = true;
|
||||
}
|
||||
|
||||
for line in lines_iter {
|
||||
let mut spans = vec![Span::raw(" ".repeat(PREFIX_WIDTH))];
|
||||
spans.extend(line.spans);
|
||||
lines.push(Line::from(spans));
|
||||
}
|
||||
}
|
||||
|
||||
let content_str = if msg.content.trim().is_empty() {
|
||||
"(tool execution)".to_string()
|
||||
if msg.reasoning.trim().is_empty() {
|
||||
"(tool execution)".to_string()
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
} else {
|
||||
msg.content.clone()
|
||||
};
|
||||
|
||||
let content_spans = super::markdown::render_markdown(&content_str, content_width, false);
|
||||
let content_lines = split_spans_into_lines(content_spans);
|
||||
let mut lines_iter = content_lines.into_iter();
|
||||
if !content_str.is_empty() {
|
||||
let content_spans = super::markdown::render_markdown(&content_str, content_width, false);
|
||||
let content_lines = split_spans_into_lines(content_spans);
|
||||
let mut lines_iter = content_lines.into_iter();
|
||||
|
||||
if let Some(first) = lines_iter.next() {
|
||||
let mut spans = header_prefix;
|
||||
spans.extend(first.spans);
|
||||
lines.push(Line::from(spans));
|
||||
} else {
|
||||
lines.push(Line::from(header_prefix));
|
||||
if !first_line_handled {
|
||||
if let Some(first) = lines_iter.next() {
|
||||
let mut spans = header_prefix.clone();
|
||||
spans.extend(first.spans);
|
||||
lines.push(Line::from(spans));
|
||||
first_line_handled = true;
|
||||
}
|
||||
} else {
|
||||
// Header already printed by reasoning, just indent
|
||||
if let Some(first) = lines_iter.next() {
|
||||
let mut spans = vec![Span::raw(" ".repeat(PREFIX_WIDTH))];
|
||||
spans.extend(first.spans);
|
||||
lines.push(Line::from(spans));
|
||||
}
|
||||
}
|
||||
|
||||
for line in lines_iter {
|
||||
let mut spans = vec![Span::raw(" ".repeat(PREFIX_WIDTH))];
|
||||
spans.extend(line.spans);
|
||||
lines.push(Line::from(spans));
|
||||
}
|
||||
}
|
||||
|
||||
for line in lines_iter {
|
||||
let mut spans = vec![Span::raw(" ".repeat(PREFIX_WIDTH))];
|
||||
spans.extend(line.spans);
|
||||
lines.push(Line::from(spans));
|
||||
|
||||
if !first_line_handled {
|
||||
lines.push(Line::from(header_prefix));
|
||||
}
|
||||
|
||||
lines
|
||||
|
||||
Reference in New Issue
Block a user