//! Client → daemon requests. use core::time::Duration; use crate::model::{ModelRef, Priority, PromptSpec, SamplingParams}; /// Opaque request identifier. Clients pick the value (typically a /// monotonic counter or a UUID); the daemon echoes it on every /// event for the request. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] pub struct RequestId(pub u64); /// One client request envelope. #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] pub struct ClientRequest { pub id: RequestId, pub kind: RequestKind, } /// The discriminated union of every operation the native API /// supports. New variants are additive in semver-minor; removing /// or changing a variant is semver-major. #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] pub enum RequestKind { /// Run an inference. Token stream returned as a sequence of /// `ServerEvent::Tokens` events. Inference(InferenceRequest), /// Snapshot of fleet state. Returns one /// `ServerEvent::FleetDescription` event. DescribeFleet, /// Ask the daemon to load a model into memory. Returns an /// `Accepted` event followed by progress or an error. LoadModel(ModelRef), /// Ask the daemon to evict a model. Returns `Accepted` and a /// terminal `Tokens { finished: true }` shaped event (empty /// chunk) when complete; this lets clients treat completion as /// the same primitive across all request kinds. UnloadModel(ModelRef), /// Cancel a previously-submitted request. The request being /// cancelled receives a terminal event with `finished: true` /// and a cancellation `ErrorKind`. Cancel(RequestId), } /// Body of an `Inference` request. #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] pub struct InferenceRequest { pub model: ModelRef, pub prompt: PromptSpec, pub sampling: SamplingParams, pub stream: bool, pub priority: Priority, /// Soft wall-clock deadline. The supervisor will not start /// work it believes cannot finish inside the deadline; it does /// not interrupt work already started. `None` means no deadline. pub deadline: Option, }