pub struct Runtime {
pub watcher_exit_path: Option<PathBuf>,
/* private fields */
}Expand description
The core runtime — manages API communication, tool execution, authentication, and streaming for all SynapsCLI binaries (chat, chatui, server, agent, watcher).
Fields§
§watcher_exit_path: Option<PathBuf>Path for watcher_exit tool to write handoff state (agent mode only)
Implementations§
Source§impl Runtime
impl Runtime
pub async fn new() -> Result<Self>
pub fn set_system_prompt(&mut self, prompt: String)
pub fn system_prompt(&self) -> Option<&str>
pub fn set_model(&mut self, model: String)
pub fn set_tools(&mut self, tools: ToolRegistry)
pub fn subagent_registry(&self) -> &Arc<Mutex<SubagentRegistry>>
pub fn event_queue(&self) -> &Arc<EventQueue>
Get a shared reference to the tool registry (for MCP lazy loading).
pub fn model(&self) -> &str
pub fn http_client(&self) -> &Client
pub fn set_thinking_budget(&mut self, budget: u32)
pub fn set_compaction_model(&mut self, model: Option<String>)
pub fn set_context_window(&mut self, window: Option<u64>)
Sourcepub fn compaction_model(&self) -> &str
pub fn compaction_model(&self) -> &str
Effective context window for the current model — user override if set,
otherwise the model’s native window from models::context_window_for_model.
pub fn context_window(&self) -> u64
Sourcepub fn apply_config(&mut self, config: &SynapsConfig)
pub fn apply_config(&mut self, config: &SynapsConfig)
Apply a parsed config file to this runtime (model, thinking budget, etc.)
pub fn thinking_budget(&self) -> u32
pub fn max_tool_output(&self) -> usize
pub fn bash_timeout(&self) -> u64
pub fn bash_max_timeout(&self) -> u64
pub fn subagent_timeout(&self) -> u64
pub fn api_retries(&self) -> u32
pub fn set_max_tool_output(&mut self, v: usize)
pub fn set_bash_timeout(&mut self, v: u64)
pub fn set_bash_max_timeout(&mut self, v: u64)
pub fn set_subagent_timeout(&mut self, v: u64)
pub fn set_api_retries(&mut self, v: u32)
pub fn thinking_level(&self) -> &str
Sourcepub async fn refresh_if_needed(&self) -> Result<()>
pub async fn refresh_if_needed(&self) -> Result<()>
Check if the OAuth token is expired and refresh it if needed.
Sourcepub async fn compact_call(&self, messages: Vec<Value>) -> Result<String>
pub async fn compact_call(&self, messages: Vec<Value>) -> Result<String>
Make a simple non-streaming API call for compaction (no tools).
Uses a dedicated summarization system prompt (not the user’s), omits all tools, and returns the raw text response. Caller supplies the full message array including the serialized conversation.
Sourcepub async fn run_single(&self, prompt: &str) -> Result<String>
pub async fn run_single(&self, prompt: &str) -> Result<String>
Run a single prompt synchronously (non-streaming). Handles tool execution internally, looping until the model produces a final text response.
Sourcepub async fn run_stream(
&self,
prompt: String,
cancel: CancellationToken,
) -> Pin<Box<dyn Stream<Item = StreamEvent> + Send>>
pub async fn run_stream( &self, prompt: String, cancel: CancellationToken, ) -> Pin<Box<dyn Stream<Item = StreamEvent> + Send>>
Run a prompt as a cancellable stream of StreamEvents. Convenience wrapper
around [run_stream_with_messages] for single-turn usage.
Sourcepub async fn run_stream_with_messages(
&self,
messages: Vec<Value>,
cancel: CancellationToken,
steering_rx: Option<UnboundedReceiver<String>>,
secret_prompt: Option<SecretPromptHandle>,
) -> Pin<Box<dyn Stream<Item = StreamEvent> + Send>>
pub async fn run_stream_with_messages( &self, messages: Vec<Value>, cancel: CancellationToken, steering_rx: Option<UnboundedReceiver<String>>, secret_prompt: Option<SecretPromptHandle>, ) -> Pin<Box<dyn Stream<Item = StreamEvent> + Send>>
Run a multi-turn conversation as a cancellable stream of StreamEvents.
This is the main entry point for chat UIs and agents. Handles tool execution,
API retries, and dynamic tool registration (MCP) internally.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Runtime
impl !RefUnwindSafe for Runtime
impl Send for Runtime
impl Sync for Runtime
impl Unpin for Runtime
impl UnsafeUnpin for Runtime
impl !UnwindSafe for Runtime
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.