|
1 | | -import { useState, useCallback } from "react" |
| 1 | +import { useState, useCallback, useEffect } from "react" |
2 | 2 | import { useEvent } from "react-use" |
3 | 3 | import { Checkbox } from "vscrui" |
4 | 4 | import { VSCodeButton, VSCodeTextField } from "@vscode/webview-ui-toolkit/react" |
@@ -67,6 +67,31 @@ export const OpenAICompatible = ({ apiConfiguration, setApiConfigurationField }: |
67 | 67 | setCustomHeaders((prev) => prev.filter((_, i) => i !== index)) |
68 | 68 | }, []) |
69 | 69 |
|
| 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 | + |
70 | 95 | const handleInputChange = useCallback( |
71 | 96 | <K extends keyof ProviderSettings, E>( |
72 | 97 | field: K, |
|
0 commit comments