* Parse auto:N syntax from ENABLE_TOOL_SEARCH env var. * Returns the percentage clamped to 0-100, or null if not auto:N format or not a number.
(value: string)
| 53 | * Returns the percentage clamped to 0-100, or null if not auto:N format or not a number. |
| 54 | */ |
| 55 | function parseAutoPercentage(value: string): number | null { |
| 56 | if (!value.startsWith('auto:')) return null |
| 57 | |
| 58 | const percentStr = value.slice(5) |
| 59 | const percent = parseInt(percentStr, 10) |
| 60 | |
| 61 | if (isNaN(percent)) { |
| 62 | logForDebugging( |
| 63 | `Invalid ENABLE_TOOL_SEARCH value "${value}": expected auto:N where N is a number.`, |
| 64 | ) |
| 65 | return null |
| 66 | } |
| 67 | |
| 68 | // Clamp to valid range |
| 69 | return Math.max(0, Math.min(100, percent)) |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Check if ENABLE_TOOL_SEARCH is set to auto mode (auto or auto:N). |
no test coverage detected