({
models,
search,
favoriteIds,
}: {
models: ModelOption[];
search: string;
favoriteIds: Set<string>;
})
| 6 | export type ModelPickerRow = |
| 7 | | { key: string; title: string; type: 'header' } |
| 8 | | { |
| 9 | key: string; |
| 10 | model: SessionModelOption; |
| 11 | isFavorite: boolean; |
| 12 | /** |
| 13 | * Whether the row still shows the provider line. A provider group's header |
| 14 | * already names the provider, so its rows drop the line; the FAVORITES, |
| 15 | * recommended and all-models sections do not name one, and a favorite list |
| 16 | * spans providers, so their rows keep it. |
| 17 | */ |
| 18 | showsProvider: boolean; |
| 19 | type: 'model'; |
| 20 | }; |
| 21 | |
| 22 | type ModelGroup = { |
| 23 | key: string; |
| 24 | title: string; |
| 25 | namesProvider: boolean; |
| 26 | models: SessionModelOption[]; |
| 27 | }; |
| 28 | |
| 29 | export type FavoriteToggleAction = |
| 30 | | { type: 'add'; model: string } |
| 31 | | { type: 'remove'; models: string[] }; |
| 32 | |
| 33 | // A CLI-catalog option is one with a CLI `modelRef` that is not a legacy |
| 34 | // Gateway projection. A Gateway or legacy-gateway option is everything else, |
| 35 | // including an option with no `modelRef`. |
| 36 | function isCliCatalogOption(model: SessionModelOption): boolean { |
| 37 | return Boolean(model.modelRef) && model.overrideSource !== 'legacy-gateway'; |
| 38 | } |
| 39 | |
| 40 | // The stable write id. Favorites are persisted server-side by this key, so it |
| 41 | // must be stable across sessions and catalog refreshes. CLI catalog options get |
| 42 | // opaque order-based `id`s (`remote-model-N`), so favorite them by their CLI |
| 43 | // model identity instead. Kilo CLI options share the Gateway model id; other |
| 44 | // providers get a `remote:<provider>:<model>` key. Gateway and legacy-gateway |
| 45 | // options keep `id` — the Gateway model id shared with regular Gateway |
| 46 | // favorites. |
| 47 | export function canonicalFavoriteId(model: SessionModelOption): string { |
| 48 | const modelRef = isCliCatalogOption(model) ? model.modelRef : undefined; |
| 49 | if (modelRef) { |
| 50 | return modelRef.providerID === 'kilo' |
| 51 | ? modelRef.modelID |
| 52 | : `remote:${modelRef.providerID}:${modelRef.modelID}`; |
| 53 | } |
| 54 | return model.id; |
| 55 | } |
| 56 | |
| 57 | // Every stored string that marks this option starred. Gateway options accept |
| 58 | // their Gateway id and the historical `remote:kilo:<id>` alias; kilo CLI options |
| 59 | // accept the same pair; other-provider CLI options accept only their |
| 60 | // `remote:<provider>:<model>` key. |
| 61 | export function favoriteKeysForOption(model: SessionModelOption): string[] { |
| 62 | const modelRef = isCliCatalogOption(model) ? model.modelRef : undefined; |
| 63 | if (modelRef) { |
| 64 | if (modelRef.providerID === 'kilo') { |
| 65 | return [modelRef.modelID, `remote:kilo:${modelRef.modelID}`]; |
no test coverage detected