()
| 29 | * Hook for saving model and mode changes. |
| 30 | */ |
| 31 | export const useModelChange = () => { |
| 32 | const [userConfig, setUserConfig] = useAtom(userConfigAtom); |
| 33 | const { saveUserConfig } = useRequestClient(); |
| 34 | |
| 35 | const saveConfig = async (newConfig: Partial<UserConfig>) => { |
| 36 | await saveUserConfig({ config: newConfig }).then(() => { |
| 37 | setUserConfig((prev) => ({ ...prev, ...newConfig })); |
| 38 | }); |
| 39 | }; |
| 40 | |
| 41 | const saveModelChange = async ( |
| 42 | model: QualifiedModelId, |
| 43 | forRole: SupportedRole, |
| 44 | ) => { |
| 45 | const modelKey = getModelKeyForRole(forRole); |
| 46 | |
| 47 | if (!modelKey) { |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | const newConfig: Partial<UserConfig> = { |
| 52 | ai: { |
| 53 | ...userConfig.ai, |
| 54 | models: { |
| 55 | custom_models: userConfig.ai?.models?.custom_models ?? [], |
| 56 | displayed_models: userConfig.ai?.models?.displayed_models ?? [], |
| 57 | ...userConfig.ai?.models, |
| 58 | [modelKey]: model, |
| 59 | }, |
| 60 | }, |
| 61 | }; |
| 62 | |
| 63 | saveConfig(newConfig); |
| 64 | }; |
| 65 | |
| 66 | const saveModeChange = async (newMode: CopilotMode) => { |
| 67 | const newConfig: Partial<UserConfig> = { |
| 68 | ai: { |
| 69 | ...userConfig.ai, |
| 70 | mode: newMode, |
| 71 | }, |
| 72 | }; |
| 73 | |
| 74 | saveConfig(newConfig); |
| 75 | }; |
| 76 | |
| 77 | return { saveModelChange, saveModeChange }; |
| 78 | }; |
no test coverage detected
searching dependent graphs…