Open History to see the last commit
1/**
2 * The ids a call routes to: `model` with any `modelOptions.variant` suffix,
3 * then each `modelOptions.models` fallback.
4 */
5export function openRouterRoutedModels(
6 model: string,
7 modelOptions: unknown,
8): Array<string> {
9 const record = (modelOptions ?? {}) as { variant?: unknown; models?: unknown }
10 const primary =
11 typeof record.variant === 'string' && record.variant
12 ? `${model}:${record.variant}`
13 : model
14 const fallbacks = Array.isArray(record.models)
15 ? record.models.filter((id): id is string => typeof id === 'string')
16 : []
17 return [primary, ...fallbacks]
18}
19
20/**
21 * The catalog lists some `:variant` ids (for example `:free`) as their own
22 * models. Check the full id first, then the id without its `:variant`.
23 */
24export function openRouterModelIn(
25 set: ReadonlySet<string>,
26 id: string,
27): boolean {
28 if (set.has(id)) return true
29 const variantIndex = id.indexOf(':')
30 return variantIndex !== -1 && set.has(id.slice(0, variantIndex))
31}