Skip to content

Commit 450baa5

Browse files
AlexMikhalevclaude
andcommitted
feat(rlm): add LLM bridge for VM-to-host communication
Implements HTTP endpoint for recursive LLM queries from VMs: - Session token validation via X-Session-Token header - Single query endpoint with budget tracking - Batched query support with concurrent execution - Budget consumption tracking (tokens, time, recursion) - Add InvalidSessionToken and BatchSizeTooLarge error variants All 43 tests passing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 6e0fa2f commit 450baa5

3 files changed

Lines changed: 465 additions & 1 deletion

File tree

crates/terraphim_rlm/src/error.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ pub enum RlmError {
134134
#[error("LLM bridge authentication failed: invalid session token")]
135135
LlmBridgeAuthFailed,
136136

137+
/// Invalid session token format.
138+
#[error("Invalid session token: {token}")]
139+
InvalidSessionToken { token: String },
140+
141+
/// Batch query size too large.
142+
#[error("Batch size {size} exceeds maximum {max}")]
143+
BatchSizeTooLarge { size: usize, max: usize },
144+
137145
// Output errors
138146
/// Output too large for inline return.
139147
#[error("Output exceeds inline limit ({size} > {limit} bytes), streamed to {file_path}")]

crates/terraphim_rlm/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub mod executor;
5454

5555
// Session and budget management (Phase 2)
5656
pub mod budget;
57+
pub mod llm_bridge;
5758
pub mod session;
5859

5960
// RLM orchestration (to be implemented in later phases)
@@ -62,7 +63,6 @@ pub mod session;
6263
// pub mod validator;
6364
// pub mod command;
6465
// pub mod preamble;
65-
// pub mod llm_bridge;
6666
// pub mod logger;
6767
// pub mod autoscaler;
6868
// pub mod dns_security;
@@ -77,6 +77,7 @@ pub use executor::{
7777
Capability, ExecutionContext, ExecutionEnvironment, ExecutionResult, SnapshotId,
7878
ValidationResult,
7979
};
80+
pub use llm_bridge::{LlmBridge, LlmBridgeConfig, QueryRequest, QueryResponse};
8081
pub use session::{SessionManager, SessionStats};
8182
pub use types::{
8283
BudgetStatus, Command, CommandHistory, QueryMetadata, SessionId, SessionInfo, SessionState,

0 commit comments

Comments
 (0)