@@ -32,38 +32,16 @@ public function getModel(string $modelName): Model
32
32
throw new InvalidArgumentException ('Model name cannot be empty. ' );
33
33
}
34
34
35
- $ parsed = self :: parseModelName ($ modelName );
35
+ $ parsed = $ this -> parseModelName ($ modelName );
36
36
$ actualModelName = $ parsed ['name ' ];
37
+ $ catalogKey = $ parsed ['catalogKey ' ];
37
38
$ options = $ parsed ['options ' ];
38
39
39
- // Try to find the model directly first
40
- if (!isset ($ this ->models [$ actualModelName ])) {
41
- // If not found and contains a colon (e.g., "model:23b"), try the base model name
42
- if (str_contains ($ actualModelName , ': ' )) {
43
- $ baseModelName = explode (': ' , $ actualModelName , 2 )[0 ];
44
-
45
- if (isset ($ this ->models [$ baseModelName ])) {
46
- // Use the base model's config but keep the full model name
47
- $ modelConfig = $ this ->models [$ baseModelName ];
48
- $ modelClass = $ modelConfig ['class ' ];
49
-
50
- if (!class_exists ($ modelClass )) {
51
- throw new InvalidArgumentException (\sprintf ('Model class "%s" does not exist. ' , $ modelClass ));
52
- }
53
-
54
- $ model = new $ modelClass ($ actualModelName , $ modelConfig ['capabilities ' ], $ options );
55
- if (!$ model instanceof Model) {
56
- throw new InvalidArgumentException (\sprintf ('Model class "%s" must extend "%s". ' , $ modelClass , Model::class));
57
- }
58
-
59
- return $ model ;
60
- }
61
- }
62
-
40
+ if (!isset ($ this ->models [$ catalogKey ])) {
63
41
throw new ModelNotFoundException (\sprintf ('Model "%s" not found. ' , $ actualModelName ));
64
42
}
65
43
66
- $ modelConfig = $ this ->models [$ actualModelName ];
44
+ $ modelConfig = $ this ->models [$ catalogKey ];
67
45
$ modelClass = $ modelConfig ['class ' ];
68
46
69
47
if (!class_exists ($ modelClass )) {
@@ -88,12 +66,13 @@ public function getModels(): array
88
66
89
67
/**
90
68
* 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.
91
70
*
92
71
* @param string $modelName The model name, potentially with query parameters (e.g., "model-name?param=value&other=123")
93
72
*
94
- * @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
95
74
*/
96
- protected static function parseModelName (string $ modelName ): array
75
+ protected function parseModelName (string $ modelName ): array
97
76
{
98
77
$ options = [];
99
78
$ actualModelName = $ modelName ;
@@ -110,8 +89,18 @@ protected static function parseModelName(string $modelName): array
110
89
$ options = self ::convertNumericStrings ($ options );
111
90
}
112
91
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
+
113
101
return [
114
102
'name ' => $ actualModelName ,
103
+ 'catalogKey ' => $ catalogKey ,
115
104
'options ' => $ options ,
116
105
];
117
106
}
0 commit comments