({
uriScheme,
apiConfiguration,
setApiConfigurationField,
fromWelcomeView,
errorMessage,
setErrorMessage,
}: ApiOptionsProps)
| 106 | } |
| 107 | |
| 108 | const ApiOptions = ({ |
| 109 | uriScheme, |
| 110 | apiConfiguration, |
| 111 | setApiConfigurationField, |
| 112 | fromWelcomeView, |
| 113 | errorMessage, |
| 114 | setErrorMessage, |
| 115 | }: ApiOptionsProps) => { |
| 116 | const { t } = useAppTranslation() |
| 117 | const { organizationAllowList, openAiCodexIsAuthenticated } = useExtensionState() |
| 118 | |
| 119 | const [customHeaders, setCustomHeaders] = useState<[string, string][]>(() => { |
| 120 | const headers = apiConfiguration?.openAiHeaders || {} |
| 121 | return Object.entries(headers) |
| 122 | }) |
| 123 | |
| 124 | useEffect(() => { |
| 125 | const propHeaders = apiConfiguration?.openAiHeaders || {} |
| 126 | |
| 127 | if (JSON.stringify(customHeaders) !== JSON.stringify(Object.entries(propHeaders))) { |
| 128 | setCustomHeaders(Object.entries(propHeaders)) |
| 129 | } |
| 130 | }, [apiConfiguration?.openAiHeaders, customHeaders]) |
| 131 | |
| 132 | // Helper to convert array of tuples to object (filtering out empty keys). |
| 133 | |
| 134 | // Debounced effect to update the main configuration when local |
| 135 | // customHeaders state stabilizes. |
| 136 | useDebounce( |
| 137 | () => { |
| 138 | const currentConfigHeaders = apiConfiguration?.openAiHeaders || {} |
| 139 | const newHeadersObject = convertHeadersToObject(customHeaders) |
| 140 | |
| 141 | // Only update if the processed object is different from the current config. |
| 142 | if (JSON.stringify(currentConfigHeaders) !== JSON.stringify(newHeadersObject)) { |
| 143 | setApiConfigurationField("openAiHeaders", newHeadersObject, false) |
| 144 | } |
| 145 | }, |
| 146 | 300, |
| 147 | [customHeaders, apiConfiguration?.openAiHeaders, setApiConfigurationField], |
| 148 | ) |
| 149 | |
| 150 | const [isAdvancedSettingsOpen, setIsAdvancedSettingsOpen] = useState(false) |
| 151 | |
| 152 | const handleInputChange = useCallback( |
| 153 | <K extends keyof ProviderSettings, E>( |
| 154 | field: K, |
| 155 | transform: (event: E) => ProviderSettings[K] = inputEventTransform, |
| 156 | ) => |
| 157 | (event: E | Event) => { |
| 158 | setApiConfigurationField(field, transform(event as E)) |
| 159 | }, |
| 160 | [setApiConfigurationField], |
| 161 | ) |
| 162 | |
| 163 | const { |
| 164 | provider: selectedProvider, |
| 165 | id: selectedModelId, |
nothing calls this directly
no test coverage detected