Skip to main content

LocalThreadRuntime

Struct LocalThreadRuntime 

Source
pub struct LocalThreadRuntime { /* private fields */ }
Expand description

A single thread with its branches, driving one model adapter.

Implementations§

Source§

impl LocalThreadRuntime

Source

pub fn new( adapter: impl ChatModelAdapter + 'static, options: LocalRuntimeOptions, ) -> Self

A runtime that runs adapter for each message sent.

Source

pub fn subscribe(&self, callback: impl Fn() + 'static) -> Subscription

Called after every change. Drop the guard to unsubscribe.

Source

pub fn messages(&self) -> Arc<[Arc<ThreadMessage>]> ⓘ

The selected branch, root first. Cheap to call; cached between changes.

Source

pub fn is_running(&self) -> bool

Whether a run is in progress.

Source

pub fn message(&self, id: &MessageId) -> Result<MessageEntry, RuntimeError>

A message and its position, by id.

Source

pub fn branches(&self, id: &MessageId) -> Result<Vec<MessageId>, RuntimeError>

The message and its siblings, for a branch picker.

Source

pub fn switch_to_branch(&self, id: &MessageId) -> Result<(), RuntimeError>

Select the branch containing id; subscribers are notified.

Source

pub fn composer(&self) -> Composer

The composer for the next message (thread.composer).

Source

pub fn begin_edit(&self, id: &MessageId) -> Result<Composer, RuntimeError>

Start editing a message (beginEdit). Sending the edit composer adds a sibling branch; cancelling discards it.

Source

pub fn edit_composer(&self, id: &MessageId) -> Option<Composer>

The edit composer for a message, while it is being edited.

Source

pub fn set_tools(&self, tools: ToolRegistry)

Register the tools this thread offers. Their definitions are added to the model context (replacing earlier tool definitions), and open calls of tools with an execute function run in the app after each step.

Source

pub fn respond_to_tool_approval( &self, message_id: &MessageId, approval_id: &str, approved: bool, reason: Option<String>, ) -> Result<Option<RunFuture>, RuntimeError>

Record the user’s answer to a pending tool approval (respond to a tool approval). An approved call runs; a denied one answers the model with an error. Returns the run that continues the message, if none is in progress, for the host to spawn.

Source

pub fn set_model_context(&self, context: ModelContext)

Replace the system prompt, tools and settings sent with later runs.

Source

pub fn submit_feedback( &self, id: &MessageId, feedback: Option<SubmittedFeedback>, ) -> Result<(), RuntimeError>

Record feedback on an assistant message (submitFeedback); None clears it.

Source

pub fn export(&self) -> ExportedRepository

Persisted messages and the selected head.

Source

pub fn import(&self, exported: ExportedRepository) -> Result<(), RuntimeError>

Load history (for example from a thread history adapter).

Source

pub fn append(&self, message: AppendMessage) -> Result<RunFuture, RuntimeError>

Add a message. A user message (or start_run: Some(true)) starts a run answering it, cancelling any run in progress. Editing is an append with the edited message’s parent and source_id.

Source

pub fn start_run( &self, config: StartRunConfig, ) -> Result<RunFuture, RuntimeError>

Add a running assistant message after parent_id and answer it: a new answer, or a regeneration when source_id names the previous one.

Source

pub fn cancel_run(&self)

Cancel any run in progress; its message becomes incomplete/cancelled.

Source

pub fn add_tool_result( &self, result: ToolResult, ) -> Result<Option<RunFuture>, RuntimeError>

Record a tool result. If that answers the last open call of a paused message, the run continues and its future is returned.

Trait Implementations§

Source§

impl Clone for LocalThreadRuntime

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl ThreadRuntime for LocalThreadRuntime

Source§

fn messages(&self) -> Arc<[Arc<ThreadMessage>]> ⓘ

The selected branch, root first.
Source§

fn message(&self, id: &MessageId) -> Result<MessageEntry, RuntimeError>

A message and its position, by id.
Source§

fn is_running(&self) -> bool

Whether a run is in progress.
Source§

fn capabilities(&self) -> RuntimeCapabilities

What the UI may offer for this thread.
Source§

fn branches(&self, id: &MessageId) -> Result<Vec<MessageId>, RuntimeError>

The message and its siblings.
Source§

fn branch_position( &self, id: &MessageId, ) -> Result<(usize, usize), RuntimeError>

(position, count) of the message among its siblings, 1-based. The default builds branches; runtimes override it to avoid the allocation, which a UI pays once per message per update.
Source§

fn structure_version(&self) -> Option<u64>

A number that changes whenever branches or the selected path change, but not when a message is updated in place. While it is unchanged a UI may keep every message’s branch_position. None (the default) means unknown: positions must be read again.
Source§

fn message_changes_since(&self, version: Option<u64>) -> Option<MessageChanges>

Changed selected-message indices since a consumer’s last version. None (the default) means this runtime does not track changes: scan messages. A supported runtime returns a current version even when the journal requires a full read. Changes must cover every selected message update and be valid for the current messages() snapshot; versions are local to this runtime. Consumers must still refresh when running state or capabilities change.
Source§

fn switch_to_branch(&self, id: &MessageId) -> Result<(), RuntimeError>

Select the branch containing id.
Source§

fn append(&self, message: AppendMessage) -> Result<RunFuture, RuntimeError>

Add a message; a user message answers it (see AppendMessage).
Source§

fn reload(&self, config: StartRunConfig) -> Result<RunFuture, RuntimeError>

Answer parent_id again (regenerate).
Source§

fn cancel_run(&self)

Stop the run in progress, if any.
Source§

fn add_tool_result( &self, result: ToolResult, ) -> Result<Option<RunFuture>, RuntimeError>

Answer a tool call; may resume the run, which is then returned to spawn.
Source§

fn respond_to_tool_approval( &self, message_id: &MessageId, approval_id: &str, approved: bool, reason: Option<String>, ) -> Result<Option<RunFuture>, RuntimeError>

Approve or deny a pending tool approval; may resume the run, which is then returned to spawn.
Source§

fn submit_feedback( &self, id: &MessageId, feedback: Option<SubmittedFeedback>, ) -> Result<(), RuntimeError>

None clears feedback.
Source§

fn composer(&self) -> Composer

The composer for the next message.
Source§

fn begin_edit(&self, id: &MessageId) -> Result<Composer, RuntimeError>

Start editing a message and return its composer.
Source§

fn edit_composer(&self, id: &MessageId) -> Option<Composer>

The composer of a message being edited, if any.
Source§

fn subscribe_dyn(&self, callback: Box<dyn Fn()>) -> Subscription

Called after every change; drop the guard to unsubscribe.
Source§

fn export(&self) -> ExportedRepository

Persisted messages and the selected head.
Source§

fn import(&self, exported: ExportedRepository) -> Result<(), RuntimeError>

Load history.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.