Open History to see the last commit
1import type { ModelOption } from "../../lib/modelOptions";
2
3/** Match the terms a user can actually see or recognize in the model picker. */
4export function modelMatchesCatalogQuery(input: {
5 readonly model: ModelOption;
6 readonly providerLabel: string;
7 readonly query: string;
8}): boolean {
9 const query = input.query.trim().toLocaleLowerCase();
10 if (query.length === 0) {
11 return true;
12 }
13
14 return [
15 input.model.label,
16 input.model.subtitle,
17 input.model.selection.model,
18 input.providerLabel,
19 ].some((value) => value.toLocaleLowerCase().includes(query));
20}
21
22/** Preserve staged provider options when the highlighted model is tapped again. */
23export function pendingModelAfterPress(input: {
24 readonly current: ModelOption | null;
25 readonly pressed: ModelOption;
26 readonly pressedIsApplied: boolean;
27}): ModelOption | null {
28 if (input.pressedIsApplied) {
29 return null;
30 }
31 return input.current?.key === input.pressed.key ? input.current : input.pressed;
32}
33
34/**
35 * Primary and selected providers start open; all other catalogs start closed.
36 * A user's disclosure tap inverts that default until the picker is dismissed.
37 */
38export function providerSectionIsCollapsed(input: {
39 readonly defaultExpanded: boolean;
40 readonly hasExpansionOverride: boolean;
41 readonly isNarrowed: boolean;
42}): boolean {
43 if (input.isNarrowed) {
44 return false;
45 }
46 return input.defaultExpanded ? input.hasExpansionOverride : !input.hasExpansionOverride;
47}