(
&mut self,
os: &mut Os,
custom_prompt: Option<String>,
show_summary: bool,
strategy: CompactStrategy,
request_metadata_lock: Arc<Mutex<Option<RequestM
| 1530 | } |
| 1531 | |
| 1532 | async fn compact_history_impl( |
| 1533 | &mut self, |
| 1534 | os: &mut Os, |
| 1535 | custom_prompt: Option<String>, |
| 1536 | show_summary: bool, |
| 1537 | strategy: CompactStrategy, |
| 1538 | request_metadata_lock: Arc<Mutex<Option<RequestMetadata>>>, |
| 1539 | ) -> Result<ChatState, ChatError> { |
| 1540 | let hist = self.conversation.history(); |
| 1541 | debug!(?strategy, ?hist, "compacting history"); |
| 1542 | |
| 1543 | if self.conversation.history().is_empty() { |
| 1544 | execute!( |
| 1545 | self.stderr, |
| 1546 | StyledText::warning_fg(), |
| 1547 | style::Print("\nConversation too short to compact.\n\n"), |
| 1548 | StyledText::reset(), |
| 1549 | )?; |
| 1550 | |
| 1551 | return Ok(ChatState::PromptUser { |
| 1552 | skip_printing_tools: true, |
| 1553 | }); |
| 1554 | } |
| 1555 | |
| 1556 | if strategy.truncate_large_messages { |
| 1557 | info!("truncating large messages"); |
| 1558 | execute!( |
| 1559 | self.stderr, |
| 1560 | terminal::Clear(terminal::ClearType::CurrentLine), |
| 1561 | cursor::MoveToColumn(0), |
| 1562 | StyledText::warning_fg(), |
| 1563 | style::Print("Truncating large messages..."), |
| 1564 | StyledText::reset_attributes(), |
| 1565 | style::Print("\n\n"), |
| 1566 | )?; |
| 1567 | } |
| 1568 | |
| 1569 | let summary_state = self |
| 1570 | .conversation |
| 1571 | .create_summary_request(os, custom_prompt.as_ref(), strategy) |
| 1572 | .await?; |
| 1573 | |
| 1574 | if self.interactive { |
| 1575 | self.spinner = Some(Spinner::new(Spinners::Dots, "Creating summary...".to_string())); |
| 1576 | } |
| 1577 | |
| 1578 | let mut response = match self |
| 1579 | .send_message( |
| 1580 | os, |
| 1581 | summary_state, |
| 1582 | request_metadata_lock, |
| 1583 | Some(vec![MessageMetaTag::Compact]), |
| 1584 | ) |
| 1585 | .await |
| 1586 | { |
| 1587 | Ok(res) => res, |
| 1588 | Err(err) => { |
| 1589 | if self.interactive { |
nothing calls this directly
no test coverage detected