()
| 118 | } |
| 119 | |
| 120 | function ModelSelect() { |
| 121 | const dispatch = useAppDispatch(); |
| 122 | const navigate = useNavigate(); |
| 123 | |
| 124 | const isInEdit = useAppSelector((store) => store.session.isInEdit); |
| 125 | const config = useAppSelector((state) => state.config.config); |
| 126 | const isConfigLoading = useAppSelector((state) => state.config.loading); |
| 127 | const buttonRef = useRef<HTMLButtonElement>(null); |
| 128 | const [options, setOptions] = useState<Option[]>([]); |
| 129 | const [sortedOptions, setSortedOptions] = useState<Option[]>([]); |
| 130 | const { selectedProfile } = useAuth(); |
| 131 | const tinyFont = useFontSize(-4); |
| 132 | |
| 133 | let selectedModel = null; |
| 134 | let allModels = null; |
| 135 | if (isInEdit) { |
| 136 | allModels = config.modelsByRole.edit; |
| 137 | selectedModel = config.selectedModelByRole.edit; |
| 138 | } |
| 139 | if (!selectedModel) { |
| 140 | selectedModel = config.selectedModelByRole.chat; |
| 141 | } |
| 142 | if (!allModels || allModels.length === 0) { |
| 143 | allModels = config.modelsByRole.chat; |
| 144 | } |
| 145 | |
| 146 | // Sort so that options without an API key are at the end |
| 147 | useEffect(() => { |
| 148 | const alphaSort = options.sort((a, b) => a.title.localeCompare(b.title)); |
| 149 | const enabledOptions = alphaSort.filter((option) => option.apiKey !== ""); |
| 150 | const disabledOptions = alphaSort.filter((option) => option.apiKey === ""); |
| 151 | |
| 152 | const sorted = [...enabledOptions, ...disabledOptions]; |
| 153 | |
| 154 | setSortedOptions(sorted); |
| 155 | }, [options]); |
| 156 | |
| 157 | useEffect(() => { |
| 158 | setOptions( |
| 159 | allModels.map((model) => { |
| 160 | return { |
| 161 | value: model.title, |
| 162 | title: modelSelectTitle(model), |
| 163 | apiKey: model.apiKey, |
| 164 | sourceFile: model.sourceFile, |
| 165 | isAutoDetected: model.isFromAutoDetect, |
| 166 | }; |
| 167 | }), |
| 168 | ); |
| 169 | }, [allModels]); |
| 170 | |
| 171 | useEffect(() => { |
| 172 | const handleKeyDown = (event: KeyboardEvent) => { |
| 173 | if ( |
| 174 | event.key === "'" && |
| 175 | isMetaEquivalentKeyPressed(event as any) && |
| 176 | !event.shiftKey // To prevent collisions w/ assistant toggle logic |
| 177 | ) { |
nothing calls this directly
no test coverage detected