Skip to main content

max / everycycle

3.2 KB · 94 lines History Blame Raw
1 //! Daemon → client events.
2
3 use crate::request::RequestId;
4
5 /// One event in the daemon's response stream for some request.
6 ///
7 /// Streams are unordered across requests but ordered within a
8 /// single `RequestId`. Every terminal event sets some semantic
9 /// equivalent of "finished"; clients should not assume the stream
10 /// continues after a terminal event for a given request id.
11 #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
12 pub enum ServerEvent {
13 /// The supervisor has admitted the request and queued it.
14 /// `queue_position` is zero when work begins immediately.
15 Accepted {
16 request_id: RequestId,
17 queue_position: u32,
18 },
19 /// One chunk of generated tokens. Terminal when `finished`.
20 Tokens {
21 request_id: RequestId,
22 chunk: TokenChunk,
23 finished: bool,
24 },
25 /// Response to a `DescribeFleet` request. Terminal for that
26 /// request.
27 FleetDescription(FleetSnapshot),
28 /// Terminal error for a request.
29 Error {
30 request_id: RequestId,
31 kind: ErrorKind,
32 message: String,
33 },
34 }
35
36 /// Generated tokens plus the rendered text. The text is what most
37 /// clients display; the IDs let token-counting clients (rate
38 /// limiters, billing surfaces) operate without re-tokenizing.
39 #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
40 pub struct TokenChunk {
41 /// UTF-8 text the tokenizer produced for these IDs.
42 pub text: String,
43 /// Token IDs in this chunk, in generation order. Opaque to the
44 /// client; the value space is the model's vocabulary.
45 pub ids: Vec<u32>,
46 }
47
48 /// Snapshot of the fleet as the daemon sees it right now.
49 /// Deliberately minimal at A1; expanded as Thread D (audit) and
50 /// Thread G (operator UX) grow.
51 #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
52 pub struct FleetSnapshot {
53 pub hostname: String,
54 pub executors: Vec<ExecutorSummary>,
55 pub loaded_models: Vec<LoadedModel>,
56 pub active_requests: u32,
57 }
58
59 /// One executor's externally visible summary.
60 #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
61 pub struct ExecutorSummary {
62 pub name: String,
63 pub vendor: String,
64 pub device_count: u32,
65 }
66
67 /// A model the daemon has resident.
68 #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
69 pub struct LoadedModel {
70 pub name: String,
71 pub revision: Option<String>,
72 pub assigned_executor: String,
73 }
74
75 /// Closed enum of error kinds at the API layer. Vendor-specific
76 /// detail goes in the accompanying `message`. Adding a variant is
77 /// semver-minor; renaming or removing is semver-major.
78 #[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
79 pub enum ErrorKind {
80 /// Request payload failed validation (shape, range, dtype).
81 Invalid,
82 /// Referenced model is not loaded and the daemon will not
83 /// auto-load it for this request.
84 ModelNotLoaded,
85 /// Supervisor refused the request — out of capacity, over
86 /// quota, or rate-limited.
87 Rejected,
88 /// Request was cancelled, either by the client or by the
89 /// supervisor enforcing a deadline.
90 Cancelled,
91 /// Internal daemon error. `message` carries the detail.
92 Internal,
93 }
94