pub struct EdSessions { /* private fields */ }Expand description
Multi-session chat state: one Ed, many conversations.
Register it with app.manage(sessions) and the chat_*_session commands.
It owns which session is live in the engine, an in-memory cache, the
generation fence, and approvals; persistence stays with the host’s
SessionStore.
Cheap to clone.
Implementations§
Source§impl EdSessions
impl EdSessions
pub fn builder(app: AppHandle, store: impl SessionStore) -> EdSessionsBuilder
Sourcepub fn ed(&self) -> &Arc<Ed<TauriSink>> ⓘ
pub fn ed(&self) -> &Arc<Ed<TauriSink>> ⓘ
The agent, for loading a model and anything else Ed exposes.
pub fn approvals(&self) -> &Arc<TauriApprovals> ⓘ
Sourcepub fn generation(&self) -> u64
pub fn generation(&self) -> u64
The current generation. Capture it before slow work and compare with
is_current afterwards.
pub fn is_current(&self, generation: u64) -> bool
Sourcepub async fn list(&self) -> Result<Vec<SessionMeta>, SessionError>
pub async fn list(&self) -> Result<Vec<SessionMeta>, SessionError>
Stored sessions, most recently updated first.
Sourcepub async fn activate(&self, session: &str)
pub async fn activate(&self, session: &str)
Make session the live conversation.
The outgoing session’s history is kept in memory; the incoming one comes from memory, then the store. An unknown id starts empty.
Sourcepub async fn new_session(&self) -> String
pub async fn new_session(&self) -> String
Start an empty session and make it live. Returns its id. The store hears about it when the first turn completes.
Sourcepub async fn history(&self, session: &str) -> Vec<ChatMessage>
pub async fn history(&self, session: &str) -> Vec<ChatMessage>
The messages of session, activating it.
Sourcepub async fn peek(&self, session: &str) -> Vec<ChatMessage>
pub async fn peek(&self, session: &str) -> Vec<ChatMessage>
The messages of session without switching to it: the live history if it is the active
session, else the cache, else the store. For rendering a session that is not on screen,
without disturbing a turn that is running in another.
Sourcepub async fn delete(&self, session: &str) -> Result<(), SessionError>
pub async fn delete(&self, session: &str) -> Result<(), SessionError>
Delete a session from the store and memory. If it was live, the engine is cleared and no session is live until the next activate.
Sourcepub async fn reset(&self)
pub async fn reset(&self)
Drop all in-memory state and fence off in-flight turns. For logout and account switches: the next account must never see this one’s chats. Stored sessions are left alone.
Sourcepub async fn save(&self, session: &str, generation: u64)
pub async fn save(&self, session: &str, generation: u64)
Save the live history under session, unless generation is stale.
Sourcepub async fn submit(&self, session: &str, id: &str, message: impl Into<String>)
pub async fn submit(&self, session: &str, id: &str, message: impl Into<String>)
Run one agent turn in session and deliver the result as a
chat_reply event.
Returns as soon as the session is active and the turn is spawned. A
long-pending invoke can be dropped by a mobile webview, so the answer
travels by event: {id, session, reply, duration, error}.
Sourcepub async fn submit_with<F, Fut>(&self, session: &str, id: &str, turn: F)where
F: FnOnce(Arc<Ed<TauriSink>>) -> Fut + Send + 'static,
Fut: Future<Output = Result<AgentReply, AgentError>> + Send + 'static,
pub async fn submit_with<F, Fut>(&self, session: &str, id: &str, turn: F)where
F: FnOnce(Arc<Ed<TauriSink>>) -> Fut + Send + 'static,
Fut: Future<Output = Result<AgentReply, AgentError>> + Send + 'static,
Like submit, with the turn supplied by the
host: rewrite the message, or recover and retry on a known engine
failure. The closure runs on the spawned task.
Sourcepub async fn respond_approval(
&self,
request_id: &str,
decision: ApprovalDecision,
) -> Result<(), String>
pub async fn respond_approval( &self, request_id: &str, decision: ApprovalDecision, ) -> Result<(), String>
Answer a pending approval.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for EdSessions
impl !UnwindSafe for EdSessions
impl Forget for EdSessions
impl Freeze for EdSessions
impl Move for EdSessions
impl Send for EdSessions
impl Sync for EdSessions
impl Unpin for EdSessions
impl UnsafeUnpin for EdSessions
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for T
impl<T> Downcast for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
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 moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
impl<T> MaybeSend for T
impl<T> MaybeSync for T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> SpeculativeProposePreparation for T
impl<T> SpeculativeProposePreparation for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.