Skip to main content

kernel/records/
identifiers.rs

1//! The vocabulary types that identify a model and its runtime.
2//!
3//! `Modality`, `Capability`, `SourceKind`, and `RuntimeId` are open string sets
4//! (new values can appear without a code change), modeled as string newtypes with
5//! constructors for the well-known values. The remaining enums are closed.
6
7macro_rules! string_id {
8    (
9        $(#[$meta:meta])*
10        $name:ident { $( $ctor:ident => $value:literal ),* $(,)? }
11    ) => {
12        $(#[$meta])*
13        #[derive(
14            Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord,
15            serde::Serialize, serde::Deserialize,
16        )]
17        #[serde(transparent)]
18        pub struct $name(String);
19
20        impl $name {
21            $(
22                #[doc = concat!("The well-known `", $value, "` value.")]
23                pub fn $ctor() -> Self {
24                    Self(String::from($value))
25                }
26            )*
27
28            /// The underlying string value.
29            pub fn as_str(&self) -> &str {
30                &self.0
31            }
32        }
33
34        impl AsRef<str> for $name {
35            fn as_ref(&self) -> &str {
36                &self.0
37            }
38        }
39
40        impl From<&str> for $name {
41            fn from(value: &str) -> Self {
42                Self(value.to_owned())
43            }
44        }
45
46        impl From<String> for $name {
47            fn from(value: String) -> Self {
48                Self(value)
49            }
50        }
51
52        impl From<$name> for String {
53            fn from(value: $name) -> Self {
54                value.0
55            }
56        }
57
58        impl std::fmt::Display for $name {
59            fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
60                formatter.write_str(&self.0)
61            }
62        }
63    };
64}
65
66string_id! {
67    /// A model's primary output modality.
68    Modality {
69        unknown => "unknown",
70        text => "text",
71        image => "image",
72        speech => "speech",
73        audio => "audio",
74        video => "video",
75        vision => "vision",
76        embedding => "embedding",
77    }
78}
79
80string_id! {
81    /// Something a model can be asked to do.
82    Capability {
83        chat => "chat",
84        complete => "complete",
85        embed => "embed",
86        see => "see",
87        image => "image",
88        speak => "speak",
89        transcribe => "transcribe",
90    }
91}
92
93string_id! {
94    /// Where a model was found or installed from.
95    SourceKind {
96        ollama => "ollama",
97        huggingface_cache => "huggingface-cache",
98        lm_studio => "lm-studio",
99        builtin => "builtin",
100        endpoint => "endpoint",
101        file => "file",
102        folder => "folder",
103    }
104}
105
106string_id! {
107    /// The identifier of a runtime adapter that can execute a model.
108    RuntimeId {
109        llama_cpp => "llama-cpp",
110        whisper_cpp => "whisper-cpp",
111        ollama => "ollama",
112        mlx_swift => "mlx-swift",
113        apple_foundation => "apple-foundation",
114        openai_endpoint => "generic:openai-server",
115        mflux => "python:mflux",
116        diffusers => "python:diffusers",
117        mlx_lm => "python:mlx-lm",
118        mlx_audio => "python:mlx-audio",
119        mlx_vlm => "python:mlx-vlm",
120        embeddings => "python:embeddings",
121        comfy_ui => "comfyui",
122        a1111 => "a1111",
123    }
124}
125
126/// How a runtime delivers a model's output.
127#[derive(
128    Debug, Clone, Copy, PartialEq, Eq, Hash, Default, serde::Serialize, serde::Deserialize,
129)]
130#[serde(rename_all = "lowercase")]
131pub enum ExecutionMode {
132    /// Tokens stream back incrementally.
133    Stream,
134    /// A long-running job produces an artifact.
135    Job,
136    /// A single synchronous request/response.
137    #[default]
138    Sync,
139}
140
141/// How much support a model needs before it can run.
142#[derive(
143    Debug, Clone, Copy, PartialEq, Eq, Hash, Default, serde::Serialize, serde::Deserialize,
144)]
145#[serde(rename_all = "kebab-case")]
146pub enum RunTier {
147    /// Runs directly, no extra runtime to install.
148    Native,
149    /// Runs via a managed sidecar the app provisions.
150    Managed,
151    /// Runs on a remote endpoint.
152    Remote,
153    /// Needs a runtime recipe that is not yet available.
154    #[default]
155    RecipeNeeded,
156}
157
158/// The lifecycle state of a model record.
159#[derive(
160    Debug, Clone, Copy, PartialEq, Eq, Hash, Default, serde::Serialize, serde::Deserialize,
161)]
162#[serde(rename_all = "lowercase")]
163pub enum ModelState {
164    /// Resolved to a runtime and present on disk.
165    Ready,
166    /// Not yet resolved to a runtime.
167    #[default]
168    Unresolved,
169    /// Known but its weights are no longer on disk.
170    Missing,
171}
172
173/// The bid preference numbers runtime adapters use to compete for a model. Lower
174/// wins. This is the single global ordering; adapters must not mint their own.
175pub struct BidPreference;
176
177impl BidPreference {
178    /// llama.cpp GGUF text runtime.
179    pub const LLAMA_CPP: i64 = 10;
180    /// whisper.cpp transcription runtime.
181    pub const WHISPER_CPP: i64 = 10;
182    /// OpenAI-compatible remote endpoint.
183    pub const ENDPOINT: i64 = 10;
184    /// mlx-vlm vision-language sidecar.
185    pub const MLX_VLM: i64 = 14;
186    /// in-process MLX-Swift text runtime.
187    pub const MLX_SWIFT: i64 = 15;
188    /// Apple Foundation Models.
189    pub const APPLE_FOUNDATION: i64 = 15;
190    /// Ollama daemon.
191    pub const OLLAMA: i64 = 20;
192    /// mflux FLUX image runtime.
193    pub const MFLUX: i64 = 25;
194    /// diffusers image runtime.
195    pub const DIFFUSERS: i64 = 26;
196    /// ComfyUI daemon.
197    pub const COMFY_UI: i64 = 27;
198    /// Automatic1111 daemon.
199    pub const A1111: i64 = 28;
200    /// mlx-audio speech runtime.
201    pub const MLX_AUDIO: i64 = 30;
202    /// embeddings sidecar.
203    pub const EMBEDDINGS: i64 = 32;
204    /// mlx-lm text sidecar.
205    pub const MLX_LM: i64 = 40;
206    /// Manifest-declared runtime (lowest priority).
207    pub const MANIFEST: i64 = 100;
208}