pub struct Writer(/* private fields */);Expand description
A running session’s logs, the harness’s appender. Every method takes
&self, so clones share them. Nothing is logged before
start, nor once a write failed; a default writer has no
store and logs nothing.
Implementations§
Source§impl Writer
impl Writer
Sourcepub fn open(store: Arc<dyn Store>) -> Result<(Self, Session), SessionError>
pub fn open(store: Arc<dyn Store>) -> Result<(Self, Session), SessionError>
Opens the session in store to go on with it, and returns the
session as read (retired agents and their subagents left out).
Reads like Session::read, so a broken session, or one of
another format, is refused before anything is written. Then each torn tail
is moved to recovered/<log>-<sha256 of the tail>.part
(Repair::TornTail).
Nothing is logged until start.
§Errors
As Session::read, or when setting a torn tail aside fails.
Sourcepub fn start(&self)
pub fn start(&self)
Starts logging, once the host restored the session: what it did to restore is not logged.
Sourcepub fn is_live(&self) -> bool
pub fn is_live(&self) -> bool
Whether records are logged: the writer was started, and no write failed.
Sourcepub fn has_written(&self) -> bool
pub fn has_written(&self) -> bool
Whether a flush wrote a record to the store, such
as for a host that marks its session saved once something is.
Sourcepub fn open_log(&self, log: &str, parent: Option<&str>)
pub fn open_log(&self, log: &str, parent: Option<&str>)
Starts the log log, of an agent spawned by the agent parent,
unless it has one.
Sourcepub fn save(
&self,
log: &str,
conversation: &mut Conversation,
) -> Vec<ChangeRecord>
pub fn save( &self, log: &str, conversation: &mut Conversation, ) -> Vec<ChangeRecord>
Queues the unsaved changes of conversation for the log log and
empties its outbox: the changes, each stamped with when it was made
(ChangeRecord::at). When the conversation does not continue the log
(Conversation::continues), as when a value made elsewhere
replaced it, one Change::Reset to the whole value is queued
instead. Either way the conversation then continues the log.
Sourcepub fn save_value(
&self,
log: &str,
key: &str,
value: Option<Value>,
starts: bool,
)
pub fn save_value( &self, log: &str, key: &str, value: Option<Value>, starts: bool, )
Queues the saved value key of the log log, an agent’s id or
SESSION, when it changed; None or a null value when it was
removed. With starts, the change starts the log.
Sourcepub fn fork_log(
&self,
from: &str,
to: &str,
through: Option<MessageId>,
) -> Result<SavedAgent, SessionError>
pub fn fork_log( &self, from: &str, to: &str, through: Option<MessageId>, ) -> Result<SavedAgent, SessionError>
Starts the log to as a copy of the log from up to a turn
boundary at or before message through (its end with None): through
the last record after which no turn runs, no tool call waits for its
result, the model owes no answer and nothing after through is in the
conversation. What is queued is written first. The copy keeps the
records’ stamps, so as_of and
undo_summary read it as they read from,
and has its own header and lineage. Returns the agent of the copy:
its conversation continues the new log, and its saved values are
those from had at the cut.
§Errors
When nothing is logged, the log to exists, from does not read or
never held through, or a write fails.
Sourcepub fn flush(&self) -> Result<(), SessionError>
pub fn flush(&self) -> Result<(), SessionError>
Writes every queued record: each started log’s records with one
write, a subagent’s log before its parent’s, so a parent never
refers to a subagent message that is not stored, and the SESSION
log once any is started. No fsync: written is not yet proof against
a power cut. A failed write stops the logging (Self::failure).
§Errors
When the logging stopped, now or before: a write failed, so what was queued is not stored and nothing more will be. A writer without a store keeps nothing and never fails.