pub struct LocalThreadRuntime { /* private fields */ }Expand description
A single thread with its branches, driving one model adapter.
Implementations§
Source§impl LocalThreadRuntime
impl LocalThreadRuntime
Sourcepub fn new(
adapter: impl ChatModelAdapter + 'static,
options: LocalRuntimeOptions,
) -> Self
pub fn new( adapter: impl ChatModelAdapter + 'static, options: LocalRuntimeOptions, ) -> Self
A runtime that runs adapter for each message sent.
Sourcepub fn subscribe(&self, callback: impl Fn() + 'static) -> Subscription
pub fn subscribe(&self, callback: impl Fn() + 'static) -> Subscription
Called after every change. Drop the guard to unsubscribe.
Sourcepub fn messages(&self) -> Arc<[Arc<ThreadMessage>]> ⓘ
pub fn messages(&self) -> Arc<[Arc<ThreadMessage>]> ⓘ
The selected branch, root first. Cheap to call; cached between changes.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Whether a run is in progress.
Sourcepub fn message(&self, id: &MessageId) -> Result<MessageEntry, RuntimeError>
pub fn message(&self, id: &MessageId) -> Result<MessageEntry, RuntimeError>
A message and its position, by id.
Sourcepub fn branches(&self, id: &MessageId) -> Result<Vec<MessageId>, RuntimeError>
pub fn branches(&self, id: &MessageId) -> Result<Vec<MessageId>, RuntimeError>
The message and its siblings, for a branch picker.
Sourcepub fn switch_to_branch(&self, id: &MessageId) -> Result<(), RuntimeError>
pub fn switch_to_branch(&self, id: &MessageId) -> Result<(), RuntimeError>
Select the branch containing id; subscribers are notified.
Sourcepub fn begin_edit(&self, id: &MessageId) -> Result<Composer, RuntimeError>
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.
Sourcepub fn edit_composer(&self, id: &MessageId) -> Option<Composer>
pub fn edit_composer(&self, id: &MessageId) -> Option<Composer>
The edit composer for a message, while it is being edited.
Sourcepub fn set_tools(&self, tools: ToolRegistry)
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.
Sourcepub fn respond_to_tool_approval(
&self,
message_id: &MessageId,
approval_id: &str,
approved: bool,
reason: Option<String>,
) -> Result<Option<RunFuture>, RuntimeError>
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.
Sourcepub fn set_model_context(&self, context: ModelContext)
pub fn set_model_context(&self, context: ModelContext)
Replace the system prompt, tools and settings sent with later runs.
Sourcepub fn submit_feedback(
&self,
id: &MessageId,
feedback: Option<SubmittedFeedback>,
) -> Result<(), RuntimeError>
pub fn submit_feedback( &self, id: &MessageId, feedback: Option<SubmittedFeedback>, ) -> Result<(), RuntimeError>
Record feedback on an assistant message (submitFeedback); None
clears it.
Sourcepub fn export(&self) -> ExportedRepository
pub fn export(&self) -> ExportedRepository
Persisted messages and the selected head.
Sourcepub fn import(&self, exported: ExportedRepository) -> Result<(), RuntimeError>
pub fn import(&self, exported: ExportedRepository) -> Result<(), RuntimeError>
Load history (for example from a thread history adapter).
Sourcepub fn append(&self, message: AppendMessage) -> Result<RunFuture, RuntimeError>
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.
Sourcepub fn start_run(
&self,
config: StartRunConfig,
) -> Result<RunFuture, RuntimeError>
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.
Sourcepub fn cancel_run(&self)
pub fn cancel_run(&self)
Cancel any run in progress; its message becomes incomplete/cancelled.
Sourcepub fn add_tool_result(
&self,
result: ToolResult,
) -> Result<Option<RunFuture>, RuntimeError>
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
impl Clone for LocalThreadRuntime
Source§impl ThreadRuntime for LocalThreadRuntime
impl ThreadRuntime for LocalThreadRuntime
Source§fn message(&self, id: &MessageId) -> Result<MessageEntry, RuntimeError>
fn message(&self, id: &MessageId) -> Result<MessageEntry, RuntimeError>
Source§fn is_running(&self) -> bool
fn is_running(&self) -> bool
Source§fn capabilities(&self) -> RuntimeCapabilities
fn capabilities(&self) -> RuntimeCapabilities
Source§fn branches(&self, id: &MessageId) -> Result<Vec<MessageId>, RuntimeError>
fn branches(&self, id: &MessageId) -> Result<Vec<MessageId>, RuntimeError>
Source§fn 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.Source§fn structure_version(&self) -> Option<u64>
fn structure_version(&self) -> Option<u64>
branch_position.
None (the default) means unknown: positions must be read again.Source§fn message_changes_since(&self, version: Option<u64>) -> Option<MessageChanges>
fn message_changes_since(&self, version: Option<u64>) -> Option<MessageChanges>
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>
fn switch_to_branch(&self, id: &MessageId) -> Result<(), RuntimeError>
id.Source§fn append(&self, message: AppendMessage) -> Result<RunFuture, RuntimeError>
fn append(&self, message: AppendMessage) -> Result<RunFuture, RuntimeError>
AppendMessage).Source§fn reload(&self, config: StartRunConfig) -> Result<RunFuture, RuntimeError>
fn reload(&self, config: StartRunConfig) -> Result<RunFuture, RuntimeError>
parent_id again (regenerate).Source§fn cancel_run(&self)
fn cancel_run(&self)
Source§fn add_tool_result(
&self,
result: ToolResult,
) -> Result<Option<RunFuture>, RuntimeError>
fn add_tool_result( &self, result: ToolResult, ) -> Result<Option<RunFuture>, RuntimeError>
Source§fn 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>
Source§fn submit_feedback(
&self,
id: &MessageId,
feedback: Option<SubmittedFeedback>,
) -> Result<(), RuntimeError>
fn submit_feedback( &self, id: &MessageId, feedback: Option<SubmittedFeedback>, ) -> Result<(), RuntimeError>
None clears feedback.