(value: unknown)
| 142 | } |
| 143 | |
| 144 | function toProviderEntry(value: unknown): CustomRegistryProviderEntry | undefined { |
| 145 | if (!isRecord(value)) return undefined; |
| 146 | const id = value['id']; |
| 147 | const name = value['name']; |
| 148 | const api = value['api']; |
| 149 | const type = value['type']; |
| 150 | const models = value['models']; |
| 151 | |
| 152 | if (typeof id !== 'string' || id.length === 0) return undefined; |
| 153 | if (typeof name !== 'string' || name.length === 0) return undefined; |
| 154 | if (typeof api !== 'string' || api.length === 0) return undefined; |
| 155 | if (!isAllowedProviderType(type)) return undefined; |
| 156 | if (!isRecord(models)) return undefined; |
| 157 | |
| 158 | const parsedModels: Record<string, CustomRegistryModelEntry> = {}; |
| 159 | for (const [key, raw] of Object.entries(models)) { |
| 160 | const modelEntry = toModelEntry(raw); |
| 161 | if (modelEntry === undefined) continue; |
| 162 | parsedModels[key] = modelEntry; |
| 163 | } |
| 164 | |
| 165 | const env = toStringArrayOrUndefined(value['env']); |
| 166 | |
| 167 | return { |
| 168 | id, |
| 169 | name, |
| 170 | api, |
| 171 | type, |
| 172 | ...(env !== undefined ? { env } : {}), |
| 173 | models: parsedModels, |
| 174 | }; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Fetches and validates an api.json document. The returned record is keyed by |
no test coverage detected