README Source History Refs Reviews Compare Notes Search Review guide ai(SMH-PLAN-AIAG0001): ship the reviewed offline catalog with deterministic resolution 212c561fb5e9fff91776d25ac881f13604ea194d
Oliver Jan Krylow <oliver@bugabinga.net > · 11 Sep 2026
unsigned
Browse files Compare with HEAD
Model capabilities gate requests before dispatch: unadvertised
tools, thinking, and output limits are rejected with the offending
field path. Alias chains and groups resolve offline into ordered
failover plans; cycles and dangling references fail at load with
sorted, deterministic diagnostics.
Changed files (5) Diff layout Auto Unified Split
+1 / −0 text lines
513 513 name = "smith-ai" name = "smith-ai" 514 514 version = "0.1.0" version = "0.1.0" 515 515 dependencies = [dependencies = [516 517 "serde_json" , "serde_json" ,smith-ai/Cargo.toml Modified +1 / −0 text lines
10 10 [dependencies ][dependencies ]11 11 smith = { path = "../smith" }smith = { path = "../smith" }
12 + serde = { workspace = true }12 13 serde_json = { workspace = true }serde_json = { workspace = true }smith-ai/src/catalog.json Added new file mode 100644+63 / −0 text lines
5 + "provider" : "OpenAiCompatible" ,7 + "context_window" : 8192 ,8 + "max_output_tokens" : 1024 ,9 + "input_images" : false ,12 + "strict_tool_input" : false ,13 + "cache_control" : false 16 + "claude-sonnet-4-5" : {17 + "id" : "claude-sonnet-4-5" ,18 + "provider" : "Anthropic" ,20 + "context_window" : 200000 ,21 + "max_output_tokens" : 16384 ,22 + "input_images" : true ,25 + "strict_tool_input" : true ,26 + "cache_control" : true 31 + "provider" : "OpenAiCompatible" ,33 + "context_window" : 400000 ,34 + "max_output_tokens" : 128000 ,35 + "input_images" : true ,38 + "strict_tool_input" : true ,39 + "cache_control" : false 43 + "id" : "gemini-3-pro" ,44 + "provider" : "Google" ,46 + "context_window" : 1000000 ,47 + "max_output_tokens" : 65536 ,48 + "input_images" : true ,51 + "strict_tool_input" : false ,52 + "cache_control" : false 57 + "sonnet" : "claude-sonnet-4-5" ,58 + "smart" : "claude-sonnet-4-5" 61 + "default" : ["claude-sonnet-4-5" , "gpt-5.1" , "gemini-3-pro" ]smith-ai/src/lib.rs Modified +3 / −0 text lines
13 13 pub mod conformance ;pub mod conformance ;15 15 pub mod gemini ;pub mod gemini ;17 19 pub mod openai ;pub mod openai ;19 21 pub use anthropic::AnthropicDecoder;pub use anthropic::AnthropicDecoder;20 22 pub use conformance::{Expected, Fixture, StreamDecoder};pub use conformance::{Expected, Fixture, StreamDecoder};21 23 pub use gemini::GeminiDecoder;pub use gemini::GeminiDecoder;
24 + pub use models::{Catalog, ModelCapabilities, ModelEntry, ProviderKind};22 25 pub use openai::OpenAiDecoder;pub use openai::OpenAiDecoder;smith-ai/src/models.rs Added new file mode 100644+374 / −0 text lines
8 + use serde::{Deserialize, Serialize};9 + use smith::error::{ProviderFault, Result , SmithError};10 + use smith::provider::{ProviderParams, ProviderRequest};11 + use std::collections::HashMap;14 + #[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)]15 + pub enum ProviderKind {28 + clippy::struct_excessive_bools,29 + reason = "capabilities are independent advertised switches" 31 + #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]32 + pub struct ModelCapabilities {34 + pub context_window: u64 ,36 + pub max_output_tokens: u64 ,38 + pub input_images: bool ,44 + pub strict_tool_input: bool ,46 + pub cache_control: bool ,50 + #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]51 + pub struct ModelEntry {55 + pub provider: ProviderKind,57 + pub capabilities: ModelCapabilities,61 + #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]64 + pub models: HashMap<String , ModelEntry>,66 + pub aliases: HashMap<String , String >,68 + pub groups: HashMap<String , Vec <String >>,72 + const BUILTIN : &str = include_str! ("catalog.json" );82 + pub fn builtin () -> Result <Self > {83 + Self ::from_json(BUILTIN )91 + pub fn from_json (json: &str ) -> Result <Self > {93 + serde_json::from_str(json).map_err (|e| invalid ("catalog" , & e.to_string ()))? ;95 + let mut alias_names: Vec <& String > = catalog.aliases.keys ().collect ();97 + for alias in alias_names {98 + let target = & catalog.aliases[alias];99 + if ! catalog.models.contains_key (target)100 + && ! catalog.groups.contains_key (target)101 + && ! catalog.aliases.contains_key (target)104 + & format! ("catalog.aliases.{alias}" ),105 + & format! ("target '{target}' is neither a model nor a group" ),109 + for (group, members) in & catalog.groups {110 + for (position, member) in members.iter ().enumerate () {111 + if ! catalog.models.contains_key (member) {113 + & format! ("catalog.groups.{group}[{position}]" ),114 + & format! ("member '{member}' is not a model" ),119 + for alias in & alias_names {120 + catalog.resolve_alias (alias)? ;125 + fn resolve_alias (& self, alias: &str ) -> Result <String > {126 + let mut chain = vec! [alias.to_string ()];127 + let mut current = alias;128 + while let Some (next) = self.aliases.get (current) {129 + if chain.iter ().any (|step| step == next) {130 + chain.push (next.clone ());132 + & format! ("catalog.aliases.{alias}" ),133 + & format! ("alias cycle: {}" , chain.join (" -> " )),136 + chain.push (next.clone ());139 + Ok (current.to_string ())152 + pub fn resolve_plan (& self, requested: &str ) -> Result <Vec <& ModelEntry>> {153 + let resolved = self.resolve_alias (requested)? ;154 + let ids: Vec <& String > = self157 + .map_or_else (|| vec! [& resolved], |members| members.iter ().collect ());160 + self.models.get (id).ok_or_else (|| {162 + & format! ("catalog.resolve.{requested}" ),163 + & format! ("'{id}' is not a model" ),177 + pub fn validate_request (& self, model: &str , request: & ProviderRequest) -> Result <()> {179 + self.resolve_plan (model)? .first ().copied ().ok_or_else (|| {180 + invalid (& format! ("catalog.resolve.{model}" ), "empty resolution plan" )182 + let caps = & entry.capabilities;183 + if ! request.tools.is_empty () && ! caps.tool_use {184 + return Err (invalid_request (186 + & format! ("{} does not advertise tool use" , entry.id),189 + let ProviderParams {194 + if let Some (requested) = max_output_tokens195 + && requested > caps.max_output_tokens197 + return Err (invalid_request (198 + "params.max_output_tokens" ,200 + "{requested} exceeds the advertised limit of {}" ,201 + caps.max_output_tokens205 + if let Some (requested) = temperature208 + return Err (invalid_request (209 + "params.temperature" ,210 + "temperature above 2 is not a valid sampling value" ,213 + if thinking && ! caps.thinking {214 + return Err (invalid_request (216 + & format! ("{} does not advertise thinking" , entry.id),223 + fn invalid (field: &str , message: &str ) -> SmithError {224 + SmithError::Config {225 + field: field.to_string (),226 + message: message.to_string (),230 + fn invalid_request (field: &str , message: &str ) -> SmithError {231 + SmithError::Provider {232 + fault: ProviderFault::Invalid {233 + field: Some (field.to_string ()),234 + message: message.to_string (),240 + #[expect(clippy::unwrap_used, reason = "catalog tests assert on checked data" )]243 + use smith::message::{Message, Role};244 + use smith::provider::ProviderParams;245 + use smith::tool::ToolMetadata;247 + const TEST_CATALOG : &str = r #"{ 251 + "provider": "OpenAiCompatible", 253 + "context_window": 8192, 254 + "max_output_tokens": 1024, 255 + "input_images": false, 258 + "strict_tool_input": false, 259 + "cache_control": false 264 + "provider": "Anthropic", 266 + "context_window": 200000, 267 + "max_output_tokens": 8192, 268 + "input_images": true, 271 + "strict_tool_input": false, 272 + "cache_control": true 276 + "aliases": { "smart": "thinker" }, 277 + "groups": { "default": ["thinker", "mock-smith"] } 281 + clippy::unwrap_used,282 + reason = "catalog fixtures are valid by construction" 284 + fn catalog () -> Catalog {285 + Catalog::from_json(TEST_CATALOG ).unwrap ()289 + fn builtin_catalog_loads_and_resolves () {290 + let catalog = Catalog::builtin().unwrap ();291 + let _plan = catalog.resolve_plan ("default" );293 + for id in catalog.models.keys () {294 + assert! (catalog.resolve_plan (id).is_ok (), "id {id}" );299 + fn alias_resolves_to_model_and_group_expands_in_order () {300 + let catalog = catalog ();301 + let plan = catalog.resolve_plan ("smart" ).unwrap ();302 + assert_eq! (plan.len (), 1 );303 + assert_eq! (plan[0 ].id, "thinker" );304 + let plan = catalog.resolve_plan ("default" ).unwrap ();307 + .map (|entry| entry.id.as_str ())308 + .collect::<Vec <_ >>(),309 + vec! ["thinker" , "mock-smith" ]314 + fn unknown_targets_and_cycles_fail_with_field_paths () {315 + let catalog = catalog ();316 + let err = catalog.resolve_plan ("nope" ).unwrap_err ();317 + assert_eq! (err.code (), "CONFIG" );320 + "aliases": { "a": "b", "b": "a" }, 323 + let err = Catalog::from_json(cyclic).unwrap_err ();326 + "config [catalog.aliases.a]: alias cycle: a -> b -> a" 330 + "aliases": { "smart": "ghost" }, 333 + let err = Catalog::from_json(dangling).unwrap_err ();334 + assert! (err.to_string ().contains ("catalog.aliases.smart" ));338 + fn requests_cannot_use_unadvertised_capabilities () {339 + let catalog = catalog ();340 + let tools = vec! [ToolMetadata::new("read" , "Read a file" )];342 + ProviderRequest::new("mock-smith" , vec! [Message::with_text(Role::User, "hi" )])345 + assert! (catalog.validate_request ("mock-smith" , & request).is_ok ());346 + let tools = vec! [ToolMetadata::new("read" , "Read a file" )];349 + request.params = ProviderParams {351 + .. ProviderParams::default()354 + .validate_request ("mock-smith" , & request)356 + assert_eq! (err.code (), "PROVIDER_INVALID" );357 + assert! (err.to_string ().contains ("params.thinking" ));359 + request.params = ProviderParams {360 + max_output_tokens: Some (999_999 ),362 + .. ProviderParams::default()364 + assert! (catalog.validate_request ("mock-smith" , & request).is_err ());366 + assert! (catalog.validate_request ("thinker" , & request).is_err ());367 + request.params = ProviderParams {368 + max_output_tokens: Some (4096 ),370 + .. ProviderParams::default()372 + assert! (catalog.validate_request ("thinker" , & request).is_ok ());