| 1 | import data from "./providerCatalog.generated.json"; |
| 2 | import type { ProviderCatalog, ProviderPresetView } from "./types"; |
| 3 | |
| 4 | // Old desktop hosts omit catalog metadata. The generated fallback comes from the |
| 5 | // same Go registry, so protocol names never have to be guessed from display text. |
| 6 | export function catalogForPreset(preset: ProviderPresetView): ProviderCatalog { |
| 7 | const known: Record<string, ProviderCatalog> = data.catalogs; |
| 8 | return preset.catalog ?? known[preset.id] ?? { |
| 9 | brandId: preset.id, brandLabel: preset.label, region: "global", product: "api", |
| 10 | format: preset.routeKind || "openai", baseUrl: "", |
| 11 | }; |
| 12 | } |
| 13 | |
| 14 | |
| 15 | // Generated metadata also covers the built-in official provider and older hosts. |
| 16 | export function protocolsForCatalog(catalog: ProviderCatalog) { |
| 17 | const known = Object.values(data.catalogs).find(c => c.brandId === catalog.brandId && c.region === catalog.region && c.product === catalog.product) as ProviderCatalog | undefined; |
| 18 | return catalog.protocols ?? known?.protocols ?? {}; |
| 19 | } |
| 20 |