session-log-decouple-item実装
This commit is contained in:
@@ -21,7 +21,8 @@ use ratatui::widgets::Paragraph;
|
||||
use ratatui::{Frame, TerminalOptions, Viewport};
|
||||
use pod_registry::lookup_session;
|
||||
use session_store::{
|
||||
ContentPart, FsStore, HashedEntry, Item, LogEntry, SessionId, Store,
|
||||
ContentPart, FsStore, HashedEntry, Item, LogEntry, LoggedContentPart, LoggedItem, SessionId,
|
||||
Store,
|
||||
};
|
||||
|
||||
const MAX_ROWS: usize = 10;
|
||||
@@ -181,7 +182,7 @@ fn last_message_preview(entries: &[HashedEntry]) -> Option<String> {
|
||||
}
|
||||
}
|
||||
LogEntry::AssistantItems { items, .. } => {
|
||||
if let Some(text) = items.iter().find_map(first_text) {
|
||||
if let Some(text) = items.iter().find_map(first_text_logged) {
|
||||
return Some(format!("assistant: {}", trim_one_line(&text, 60)));
|
||||
}
|
||||
}
|
||||
@@ -201,6 +202,16 @@ fn first_text(item: &Item) -> Option<String> {
|
||||
}
|
||||
}
|
||||
|
||||
fn first_text_logged(item: &LoggedItem) -> Option<String> {
|
||||
match item {
|
||||
LoggedItem::Message { content, .. } => content.iter().find_map(|p| match p {
|
||||
LoggedContentPart::Text { text } => Some(text.clone()),
|
||||
_ => None,
|
||||
}),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn trim_one_line(s: &str, max_chars: usize) -> String {
|
||||
let collapsed: String = s.chars().map(|c| if c == '\n' { ' ' } else { c }).collect();
|
||||
if collapsed.chars().count() <= max_chars {
|
||||
|
||||
Reference in New Issue
Block a user