( deps: ProviderDeps, opts: ListOptions, )
| 163 | } |
| 164 | |
| 165 | export async function handleProviderList( |
| 166 | deps: ProviderDeps, |
| 167 | opts: ListOptions, |
| 168 | ): Promise<void> { |
| 169 | const harness = deps.getHarness(); |
| 170 | await harness.ensureConfigFile(); |
| 171 | const config = await harness.getConfig(); |
| 172 | |
| 173 | if (opts.json) { |
| 174 | deps.stdout.write( |
| 175 | `${JSON.stringify({ providers: config.providers, models: config.models ?? {} }, null, 2)}\n`, |
| 176 | ); |
| 177 | return; |
| 178 | } |
| 179 | |
| 180 | const modelsByProvider = new Map<string, string[]>(); |
| 181 | for (const [alias, model] of Object.entries(config.models ?? {})) { |
| 182 | const list = modelsByProvider.get(model.provider) ?? []; |
| 183 | list.push(alias); |
| 184 | modelsByProvider.set(model.provider, list); |
| 185 | } |
| 186 | |
| 187 | const providerIds = Object.keys(config.providers).toSorted(); |
| 188 | if (providerIds.length === 0) { |
| 189 | deps.stdout.write('No providers configured.\n'); |
| 190 | return; |
| 191 | } |
| 192 | |
| 193 | for (const id of providerIds) { |
| 194 | const provider = config.providers[id]!; |
| 195 | const aliases = modelsByProvider.get(id) ?? []; |
| 196 | const sourceLabel = providerSourceLabel(provider); |
| 197 | deps.stdout.write( |
| 198 | `${id} type=${provider.type} models=${String(aliases.length)} source=${sourceLabel}\n`, |
| 199 | ); |
| 200 | } |
| 201 | if (config.defaultModel !== undefined) { |
| 202 | deps.stdout.write(`\nDefault model: ${config.defaultModel}\n`); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * Fetches the models.dev-style public catalog and lists providers, or — when |
no test coverage detected