33using Microsoft . Extensions . Logging ;
44using StabilityMatrix . Core . Api ;
55using StabilityMatrix . Core . Database ;
6+ using StabilityMatrix . Core . Extensions ;
67using StabilityMatrix . Core . Models . Api ;
78using StabilityMatrix . Core . Models . Database ;
89
@@ -42,18 +43,18 @@ public async Task<List<string>> GetBaseModelTypes(bool forceRefresh = false, boo
4243 var jsonContent = await baseModelsResponse . Content . ReadAsStringAsync ( ) ;
4344 var baseModels = JsonNode . Parse ( jsonContent ) ;
4445
45- var jArray =
46- baseModels ? [ "error" ] ? [ "issues" ] ? [ 0 ] ? [ "unionErrors" ] ? [ 0 ] ? [ "issues" ] ? [ 0 ] ? [ "options" ]
47- as JsonArray ;
46+ var innerJson = baseModels ? [ "error" ] ? [ "message" ] ? . GetValue < string > ( ) ;
47+ var jArray = JsonNode . Parse ( innerJson ) . AsArray ( ) ;
48+ var baseModelValues = jArray [ 0 ] ? [ "errors" ] ? [ 0 ] ? [ 0 ] ? [ "values" ] ? . AsArray ( ) ;
4849
49- civitBaseModels = jArray ? . GetValues < string > ( ) . ToList ( ) ?? [ ] ;
50+ civitBaseModels = baseModelValues ? . GetValues < string > ( ) . ToList ( ) ?? [ ] ;
5051
5152 // Cache the results
5253 var cacheEntry = new CivitBaseModelTypeCacheEntry
5354 {
5455 Id = CacheId ,
5556 ModelTypes = civitBaseModels ,
56- CreatedAt = DateTimeOffset . UtcNow
57+ CreatedAt = DateTimeOffset . UtcNow ,
5758 } ;
5859
5960 await dbContext . UpsertCivitBaseModelTypeCacheEntry ( cacheEntry ) ;
@@ -78,7 +79,8 @@ public async Task<List<string>> GetBaseModelTypes(bool forceRefresh = false, boo
7879
7980 // Return cached results if available, even if expired
8081 var expiredCache = await dbContext . GetCivitBaseModelTypeCacheEntry ( CacheId ) ;
81- return expiredCache ? . ModelTypes ?? [ ] ;
82+ return expiredCache ? . ModelTypes
83+ ?? Enum . GetValues < CivitBaseModelType > ( ) . Select ( b => b . GetStringValue ( ) ) . ToList ( ) ;
8284 }
8385 }
8486
0 commit comments