Skip to main content

codetether_rlm/router/
types.rs

1//! Public types used by all router submodules.
2
3use serde::{Deserialize, Serialize};
4use std::sync::Arc;
5use uuid::Uuid;
6
7use crate::traits::{LlmProvider, RlmEventBus, ToolCallRewriter};
8
9/// Context for a routing decision.
10#[derive(Debug, Clone)]
11pub struct RoutingContext {
12    pub tool_id: String,
13    pub session_id: String,
14    pub call_id: Option<String>,
15    pub model_context_limit: usize,
16    pub current_context_tokens: Option<usize>,
17}
18
19/// Outcome of a routing decision.
20#[derive(Debug, Clone, Serialize, Deserialize)]
21pub struct RoutingResult {
22    pub should_route: bool,
23    pub reason: String,
24    pub estimated_tokens: usize,
25}
26
27/// Progress tick during auto-processing.
28#[derive(Debug, Clone)]
29pub struct ProcessProgress {
30    pub iteration: usize,
31    pub max_iterations: usize,
32    pub status: String,
33}
34
35/// Internal context for the crate's auto-process loop.
36///
37/// The host crate converts its own context into this via
38/// [`IntoCrateCtx`]. End users never construct this directly.
39pub struct CrateAutoProcessContext<'a> {
40    pub tool_id: &'a str,
41    pub tool_args: serde_json::Value,
42    pub session_id: &'a str,
43    pub abort: Option<tokio::sync::watch::Receiver<bool>>,
44    pub on_progress: Option<Box<dyn Fn(ProcessProgress) + Send + Sync>>,
45    pub provider: Arc<dyn LlmProvider>,
46    pub model: String,
47    pub bus: Option<Arc<dyn RlmEventBus>>,
48    pub trace_id: Option<Uuid>,
49    pub subcall_provider: Option<Arc<dyn LlmProvider>>,
50    pub subcall_model: Option<String>,
51    pub rewriter: Option<Arc<dyn ToolCallRewriter>>,
52}
53
54/// Trait for converting a host context into the crate's internal form.
55pub trait IntoCrateCtx<'a> {
56    /// Convert into the crate's internal context.
57    fn into_crate_ctx(self) -> CrateAutoProcessContext<'a>;
58}
59
60/// Outcome of the iterative RLM loop.
61pub struct LoopOutcome {
62    pub final_answer: Option<String>,
63    pub iterations: usize,
64    pub subcalls: usize,
65    pub aborted: bool,
66    pub last_error: Option<String>,
67}