(
baseUrl: string,
apiKey: string | null | undefined,
signal?: AbortSignal,
)
| 127 | } |
| 128 | |
| 129 | async function fetchCatalogModels( |
| 130 | baseUrl: string, |
| 131 | apiKey: string | null | undefined, |
| 132 | signal?: AbortSignal, |
| 133 | ): Promise<ModelCatalogItem[]> { |
| 134 | const rawModels = await fetchJson(baseUrl, "/models", apiKey, signal); |
| 135 | // A 2xx response with a non-array body means the endpoint returned |
| 136 | // something unexpected (e.g. an error envelope). Surface it instead of |
| 137 | // silently treating it as an empty catalog. |
| 138 | if (!Array.isArray(rawModels)) { |
| 139 | throw new PollinationsError( |
| 140 | "Model catalog endpoint /models returned a non-array response", |
| 141 | "MODEL_CATALOG", |
| 142 | 502, |
| 143 | ); |
| 144 | } |
| 145 | |
| 146 | return sortModels( |
| 147 | (rawModels as ModelInfo[]) |
| 148 | .map(normalizeModel) |
| 149 | .filter((model): model is ModelCatalogItem => model !== null), |
| 150 | ); |
| 151 | } |
| 152 | |
| 153 | function trimTrailingSlashes(value: string): string { |
| 154 | let end = value.length; |
no test coverage detected