Open History to see the last commit
1/**
2 * `models.capabilities` as stored and served: `true` = the provider states
3 * the model supports the flag, `false` = the provider states it does not,
4 * key absent = unknown. The whole field is null when nothing is known.
5 */
6export type CapabilityMap = Record<string, boolean>
7
8export function isCapabilityMap(value: unknown): value is CapabilityMap {
9 return (
10 typeof value === 'object' &&
11 value !== null &&
12 !Array.isArray(value) &&
13 Object.values(value).every((flag) => typeof flag === 'boolean')
14 )
15}
16
17/** The flags a stored map says yes to. Anything but a map says none. */
18export function supportedFlags(value: unknown): Array<string> {
19 return isCapabilityMap(value)
20 ? Object.keys(value).filter((flag) => value[flag])
21 : []
22}