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§
Sourcefn messages(&self) -> Arc<[Arc<ThreadMessage>]> ⓘ
fn messages(&self) -> Arc<[Arc<ThreadMessage>]> ⓘ
The selected branch, root first.
Sourcefn message(&self, id: &MessageId) -> Result<MessageEntry, RuntimeError>
fn message(&self, id: &MessageId) -> Result<MessageEntry, RuntimeError>
A message and its position, by id.
Sourcefn is_running(&self) -> bool
fn is_running(&self) -> bool
Whether a run is in progress.
Sourcefn capabilities(&self) -> RuntimeCapabilities
fn capabilities(&self) -> RuntimeCapabilities
What the UI may offer for this thread.
Sourcefn branches(&self, id: &MessageId) -> Result<Vec<MessageId>, RuntimeError>
fn branches(&self, id: &MessageId) -> Result<Vec<MessageId>, RuntimeError>
The message and its siblings.
Sourcefn switch_to_branch(&self, id: &MessageId) -> Result<(), RuntimeError>
fn switch_to_branch(&self, id: &MessageId) -> Result<(), RuntimeError>
Select the branch containing id.
Sourcefn append(&self, message: AppendMessage) -> Result<RunFuture, RuntimeError>
fn append(&self, message: AppendMessage) -> Result<RunFuture, RuntimeError>
Add a message; a user message answers it (see AppendMessage).
Sourcefn reload(&self, config: StartRunConfig) -> Result<RunFuture, RuntimeError>
fn reload(&self, config: StartRunConfig) -> Result<RunFuture, RuntimeError>
Answer parent_id again (regenerate).
Sourcefn cancel_run(&self)
fn cancel_run(&self)
Stop the run in progress, if any.
Sourcefn add_tool_result(
&self,
result: ToolResult,
) -> Result<Option<RunFuture>, RuntimeError>
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.
Sourcefn respond_to_tool_approval(
&self,
message_id: &MessageId,
approval_id: &str,
approved: bool,
reason: Option<String>,
) -> 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>
Approve or deny a pending tool approval; may resume the run, which is then returned to spawn.
Sourcefn submit_feedback(
&self,
id: &MessageId,
feedback: Option<SubmittedFeedback>,
) -> Result<(), RuntimeError>
fn submit_feedback( &self, id: &MessageId, feedback: Option<SubmittedFeedback>, ) -> Result<(), RuntimeError>
None clears feedback.
Sourcefn begin_edit(&self, id: &MessageId) -> Result<Composer, RuntimeError>
fn begin_edit(&self, id: &MessageId) -> Result<Composer, RuntimeError>
Start editing a message and return its composer.
Sourcefn edit_composer(&self, id: &MessageId) -> Option<Composer>
fn edit_composer(&self, id: &MessageId) -> Option<Composer>
The composer of a message being edited, if any.
Sourcefn subscribe_dyn(&self, callback: Box<dyn Fn()>) -> Subscription
fn subscribe_dyn(&self, callback: Box<dyn Fn()>) -> Subscription
Called after every change; drop the guard to unsubscribe.
Sourcefn export(&self) -> ExportedRepository
fn export(&self) -> ExportedRepository
Persisted messages and the selected head.
Sourcefn import(&self, exported: ExportedRepository) -> Result<(), RuntimeError>
fn import(&self, exported: ExportedRepository) -> Result<(), RuntimeError>
Load history.
Provided Methods§
Sourcefn branch_position(
&self,
id: &MessageId,
) -> Result<(usize, usize), RuntimeError>
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.
Sourcefn structure_version(&self) -> Option<u64>
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.
Sourcefn message_changes_since(&self, _version: Option<u64>) -> Option<MessageChanges>
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".