| 1 | import { shouldAutoEnableSystemMessageTools } from "core/config/shouldAutoEnableSystemMessageTools"; |
| 2 | import { selectSelectedChatModel } from "../slices/configSlice"; |
| 3 | import { RootState } from "../store"; |
| 4 | |
| 5 | /** |
| 6 | * Selector that determines if system message tools should be used. |
| 7 | * This prioritizes auto-detection over manual configuration where we have a strong preference. |
| 8 | * |
| 9 | * Priority order: |
| 10 | * 1. Auto-detection (if it returns true/false) |
| 11 | * 2. Manual user configuration (if auto-detection returns undefined) |
| 12 | * 3. Default to false |
| 13 | * |
| 14 | * @param state The Redux root state |
| 15 | * @returns true if system message tools should be used, false otherwise |
| 16 | */ |
| 17 | export function selectUseSystemMessageTools(state: RootState): boolean { |
| 18 | const selectedModel = selectSelectedChatModel(state); |
| 19 | const manualSetting = |
| 20 | state.config.config.experimental?.onlyUseSystemMessageTools; |
| 21 | |
| 22 | // If no model is selected, fall back to manual setting or default |
| 23 | if (!selectedModel) { |
| 24 | return manualSetting ?? false; |
| 25 | } |
| 26 | |
| 27 | // Check auto-detection first |
| 28 | const autoSetting = shouldAutoEnableSystemMessageTools(selectedModel); |
| 29 | |
| 30 | // If auto-detection has a preference, use it (takes priority) |
| 31 | if (autoSetting !== undefined) { |
| 32 | return autoSetting; |
| 33 | } |
| 34 | |
| 35 | // If no auto-preference, use manual setting or default to false |
| 36 | return manualSetting ?? false; |
| 37 | } |