pub struct Chats { /* private fields */ }Expand description
A conversation store on disk.
Implementations§
Source§impl Chats
impl Chats
Sourcepub fn at(root: PathBuf) -> Self
pub fn at(root: PathBuf) -> Self
A store at an explicit root. Tests use this, which is why none of them need the operator’s real home.
Sourcepub fn artifacts_of(&self, id: &str) -> PathBuf
pub fn artifacts_of(&self, id: &str) -> PathBuf
Where one conversation’s prompts and CLI output are kept.
Beside the record rather than inside it, with the same stem convention a run’s nodes use, so a conversation that went wrong can be read back turn by turn - which is the only way to tell “the agent said nothing” apart from “magi never asked it”.
Sourcepub fn attachments_dir(&self, id: &str) -> PathBuf
pub fn attachments_dir(&self, id: &str) -> PathBuf
Where this conversation’s attached images live: a subdirectory of
artifacts_of, so deleting the conversation deletes its attachments
too and nothing here needs its own cleanup path.
Sourcepub fn put_attachment(
&self,
id: &str,
mime: &str,
name: &str,
data: &[u8],
) -> Result<Attachment>
pub fn put_attachment( &self, id: &str, mime: &str, name: &str, data: &[u8], ) -> Result<Attachment>
Persist one already-validated attachment and return its metadata.
web::chat_attachment_post is the only caller: it has already
checked mime against the whitelist and sniffed the bytes, so an
unrecognised mime reaching here is a bug in that caller, not
something an operator did. The id is minted here and never taken
from the client; name is stored for display only and never used to
build a path.
Sourcepub fn attachment_meta(
&self,
id: &str,
att_id: &str,
) -> Result<Option<Attachment>>
pub fn attachment_meta( &self, id: &str, att_id: &str, ) -> Result<Option<Attachment>>
Just the metadata, without reading the image bytes back off disk -
what web::chat_say uses to turn an id the operator referenced into
an Attachment before appending a Turn, where the bytes
themselves are of no interest. None for an id this conversation
never stored - including one that merely looks plausible:
valid_attachment_id is checked here too, not only by the caller,
the same defence-in-depth Questions::panel_asset uses for its own
asset ids.
Sourcepub fn read_attachment(
&self,
id: &str,
att_id: &str,
) -> Result<Option<(Attachment, Vec<u8>)>>
pub fn read_attachment( &self, id: &str, att_id: &str, ) -> Result<Option<(Attachment, Vec<u8>)>>
A stored attachment’s metadata and its bytes together, for serving it
back on GET. None under the same conditions as
Chats::attachment_meta, which this is built on.
Sourcepub fn put(&self, c: &mut Chat) -> Result<()>
pub fn put(&self, c: &mut Chat) -> Result<()>
Write a conversation, atomically, so a process killed mid-write leaves the previous state readable rather than a truncated file that would lose the whole interview.
Sourcepub fn get(&self, id: &str) -> Result<Chat>
pub fn get(&self, id: &str) -> Result<Chat>
Load a conversation by id or unambiguous id prefix.
Sourcepub fn list(&self) -> Vec<Chat>
pub fn list(&self) -> Vec<Chat>
Every conversation on disk: open first, then newest first.
Open first because that ordering is the product - the list exists to show the operator what is still being talked through, and a filed interview is history underneath it. Unreadable files are skipped rather than fatal: one corrupt record must not take the web UI down, and must certainly not hide the open conversation the operator came back for.
Sourcepub fn resolve_id(&self, prefix: &str) -> Result<String>
pub fn resolve_id(&self, prefix: &str) -> Result<String>
Expand an id prefix to exactly one conversation id. The short id the phone shows is a suffix, so that is accepted too.
Sourcepub fn revision(&self) -> u64
pub fn revision(&self) -> u64
Newest modification time in the store, in milliseconds, for change
detection. The web UI compares this instead of re-reading every
conversation, so an idle phone on a slow link costs one stat per file.
Sourcepub fn count_open(&self) -> usize
pub fn count_open(&self) -> usize
How many conversations are still open. The badge on the phone.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Chats
impl RefUnwindSafe for Chats
impl Send for Chats
impl Sync for Chats
impl Unpin for Chats
impl UnsafeUnpin for Chats
impl UnwindSafe for Chats
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more