Skip to main content

ThreadRuntime

Trait ThreadRuntime 

Source
pub trait ThreadRuntime {
Show 21 methods // Required methods fn messages(&self) -> Arc<[Arc<ThreadMessage>]> ⓘ; fn message(&self, id: &MessageId) -> Result<MessageEntry, RuntimeError>; fn is_running(&self) -> bool; fn capabilities(&self) -> RuntimeCapabilities; fn branches(&self, id: &MessageId) -> Result<Vec<MessageId>, RuntimeError>; fn switch_to_branch(&self, id: &MessageId) -> Result<(), RuntimeError>; fn append(&self, message: AppendMessage) -> Result<RunFuture, RuntimeError>; fn reload(&self, config: StartRunConfig) -> Result<RunFuture, RuntimeError>; fn cancel_run(&self); fn add_tool_result( &self, result: ToolResult, ) -> Result<Option<RunFuture>, RuntimeError>; fn respond_to_tool_approval( &self, message_id: &MessageId, approval_id: &str, approved: bool, reason: Option<String>, ) -> Result<Option<RunFuture>, RuntimeError>; fn submit_feedback( &self, id: &MessageId, feedback: Option<SubmittedFeedback>, ) -> Result<(), RuntimeError>; fn composer(&self) -> Composer; fn begin_edit(&self, id: &MessageId) -> Result<Composer, RuntimeError>; fn edit_composer(&self, id: &MessageId) -> Option<Composer>; fn subscribe_dyn(&self, callback: Box<dyn Fn()>) -> Subscription; fn export(&self) -> ExportedRepository; fn import(&self, exported: ExportedRepository) -> Result<(), RuntimeError>; // Provided methods fn branch_position( &self, id: &MessageId, ) -> Result<(usize, usize), RuntimeError> { ... } fn structure_version(&self) -> Option<u64> { ... } fn message_changes_since( &self, _version: Option<u64>, ) -> Option<MessageChanges> { ... }
}
Expand description

One thread: its messages, branches, composers and actions.

Methods change state synchronously and notify subscribers. A method that needs asynchronous work returns a RunFuture for the host to spawn.

Required Methods§

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 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.

Provided Methods§

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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§