use serde::{Deserialize, Serialize};
use std::sync::Arc;
use crate::patch_engine::{CompiledArtifact, PatchEngine, RuntimePatch};
pub trait RuntimeHandle: Send + Sync {
fn send_patch(&self, patch: RuntimePatch);
fn request_state(&self) -> RuntimeStateSnapshot;
fn send_event(&self, event: RuntimeEvent);
}
pub struct DevRuntimeController {
runtime: Arc<dyn RuntimeHandle>,
patch_engine: PatchEngine,
}
impl DevRuntimeController {
pub fn new(runtime: Arc<dyn RuntimeHandle>) -> Self {
Self {
runtime,
patch_engine: PatchEngine::new(),
}
}
pub fn apply_code_update(&mut self, compiled_artifact: CompiledArtifact) {
let patch = self.patch_engine.generate_patch(compiled_artifact);
self.runtime.send_patch(patch);
}
pub fn inject_agent_stream(&self, stream: Vec<RuntimeEvent>) {
for event in stream {
self.runtime.send_event(event);
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum RuntimeEvent {
Agent(AgentEvent),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum AgentEvent {
Token(String),
ToolCall(String),
StateChange(String),
Error(String),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RuntimeStateSnapshot {
pub data: String,
}
impl RuntimeStateSnapshot {
pub fn new(data: String) -> Self {
Self { data }
}
}