pub struct ConversationWatcher { /* private fields */ }Expand description
Watches a conversation for new entries.
Tracks which entries have been seen (by UUID) and only returns new entries on subsequent polls.
§Example
use toolpath_claude::{ClaudeConvo, ConversationWatcher};
let manager = ClaudeConvo::new();
let mut watcher = ConversationWatcher::new(
manager,
"/path/to/project".to_string(),
"session-uuid".to_string(),
);
// First poll returns all existing entries
let entries = watcher.poll().unwrap();
println!("Initial entries: {}", entries.len());
// Subsequent polls return only new entries
loop {
std::thread::sleep(std::time::Duration::from_secs(1));
let new_entries = watcher.poll().unwrap();
for entry in new_entries {
println!("New entry: {:?}", entry.uuid);
}
}Implementations§
Source§impl ConversationWatcher
impl ConversationWatcher
Sourcepub fn new(manager: ClaudeConvo, project: String, session_id: String) -> Self
pub fn new(manager: ClaudeConvo, project: String, session_id: String) -> Self
Creates a new watcher for the given conversation.
Sourcepub fn with_role_filter(self, role: MessageRole) -> Self
pub fn with_role_filter(self, role: MessageRole) -> Self
Sets a role filter - only entries with this role will be returned.
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
Returns the session ID being watched.
Sourcepub fn seen_count(&self) -> usize
pub fn seen_count(&self) -> usize
Returns the number of entries that have been seen.
Sourcepub fn poll(&mut self) -> Result<Vec<ConversationEntry>>
pub fn poll(&mut self) -> Result<Vec<ConversationEntry>>
Polls for new conversation entries.
On the first call, returns all existing entries (optionally filtered by role). On subsequent calls, returns only entries that haven’t been seen before.
Sourcepub fn poll_with_full(
&mut self,
) -> Result<(Conversation, Vec<ConversationEntry>)>
pub fn poll_with_full( &mut self, ) -> Result<(Conversation, Vec<ConversationEntry>)>
Polls and returns the full conversation along with just the new entries.
Useful when you need both the full state and the delta.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Resets the watcher, clearing all seen UUIDs.
The next poll will return all entries as if it were the first call.
Sourcepub fn mark_seen(&mut self, entries: &[ConversationEntry])
pub fn mark_seen(&mut self, entries: &[ConversationEntry])
Pre-marks entries as seen without returning them.
Useful for initializing the watcher to only return future entries.
Sourcepub fn skip_existing(&mut self) -> Result<usize>
pub fn skip_existing(&mut self) -> Result<usize>
Skips existing entries - next poll will only return new entries.