Skip to content

Commit 97b8277

Browse files
committed
Fix saving of OpenAI compatible headers
1 parent ce4ce17 commit 97b8277

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

webview-ui/src/components/settings/providers/OpenAICompatible.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useCallback } from "react"
1+
import { useState, useCallback, useEffect } from "react"
22
import { useEvent } from "react-use"
33
import { Checkbox } from "vscrui"
44
import { VSCodeButton, VSCodeTextField } from "@vscode/webview-ui-toolkit/react"
@@ -67,6 +67,31 @@ export const OpenAICompatible = ({ apiConfiguration, setApiConfigurationField }:
6767
setCustomHeaders((prev) => prev.filter((_, i) => i !== index))
6868
}, [])
6969

70+
// Helper to convert array of tuples to object
71+
const convertHeadersToObject = (headers: [string, string][]): Record<string, string> => {
72+
const result: Record<string, string> = {}
73+
74+
for (const [key, value] of headers) {
75+
const trimmedKey = key.trim()
76+
if (!trimmedKey) {
77+
continue
78+
}
79+
result[trimmedKey] = value.trim()
80+
}
81+
82+
return result
83+
}
84+
85+
// Add effect to update the parent component's state when local headers change
86+
useEffect(() => {
87+
const timer = setTimeout(() => {
88+
const headerObject = convertHeadersToObject(customHeaders)
89+
setApiConfigurationField("openAiHeaders", headerObject)
90+
}, 300)
91+
92+
return () => clearTimeout(timer)
93+
}, [customHeaders, setApiConfigurationField])
94+
7095
const handleInputChange = useCallback(
7196
<K extends keyof ProviderSettings, E>(
7297
field: K,

0 commit comments

Comments
 (0)