@@ -32,15 +32,16 @@ public function getModel(string $modelName): Model
3232 throw new InvalidArgumentException ('Model name cannot be empty. ' );
3333 }
3434
35- $ parsed = self :: parseModelName ($ modelName );
35+ $ parsed = $ this -> parseModelName ($ modelName );
3636 $ actualModelName = $ parsed ['name ' ];
37+ $ catalogKey = $ parsed ['catalogKey ' ];
3738 $ options = $ parsed ['options ' ];
3839
39- if (!isset ($ this ->models [$ actualModelName ])) {
40+ if (!isset ($ this ->models [$ catalogKey ])) {
4041 throw new ModelNotFoundException (\sprintf ('Model "%s" not found. ' , $ actualModelName ));
4142 }
4243
43- $ modelConfig = $ this ->models [$ actualModelName ];
44+ $ modelConfig = $ this ->models [$ catalogKey ];
4445 $ modelClass = $ modelConfig ['class ' ];
4546
4647 if (!class_exists ($ modelClass )) {
@@ -65,12 +66,13 @@ public function getModels(): array
6566
6667 /**
6768 * Extracts model name and options from a model name string that may contain query parameters.
69+ * Also resolves size variants (e.g., "model:23b") to their base model for catalog lookup.
6870 *
6971 * @param string $modelName The model name, potentially with query parameters (e.g., "model-name?param=value&other=123")
7072 *
71- * @return array{name: string, options: array<string, mixed>} An array containing the model name and parsed options
73+ * @return array{name: string, catalogKey: string, options: array<string, mixed>} An array containing the model name, catalog lookup key, and parsed options
7274 */
73- protected static function parseModelName (string $ modelName ): array
75+ protected function parseModelName (string $ modelName ): array
7476 {
7577 $ options = [];
7678 $ actualModelName = $ modelName ;
@@ -87,8 +89,18 @@ protected static function parseModelName(string $modelName): array
8789 $ options = self ::convertNumericStrings ($ options );
8890 }
8991
92+ // Determine catalog key: try exact match first, then fall back to base model
93+ $ catalogKey = $ actualModelName ;
94+ if (!isset ($ this ->models [$ actualModelName ]) && str_contains ($ actualModelName , ': ' )) {
95+ $ baseModelName = explode (': ' , $ actualModelName , 2 )[0 ];
96+ if (isset ($ this ->models [$ baseModelName ])) {
97+ $ catalogKey = $ baseModelName ;
98+ }
99+ }
100+
90101 return [
91102 'name ' => $ actualModelName ,
103+ 'catalogKey ' => $ catalogKey ,
92104 'options ' => $ options ,
93105 ];
94106 }
0 commit comments