mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 12:21:13 -05:00
fix: config-manager
This commit is contained in:
@@ -45,7 +45,7 @@ interface ApiOptionsProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) => {
|
const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) => {
|
||||||
const { apiConfiguration, setApiConfiguration, uriScheme, onUpdateApiConfig } = useExtensionState()
|
const { apiConfiguration, setApiConfiguration, uriScheme, handleInputChange } = useExtensionState()
|
||||||
const [ollamaModels, setOllamaModels] = useState<string[]>([])
|
const [ollamaModels, setOllamaModels] = useState<string[]>([])
|
||||||
const [lmStudioModels, setLmStudioModels] = useState<string[]>([])
|
const [lmStudioModels, setLmStudioModels] = useState<string[]>([])
|
||||||
const [vsCodeLmModels, setVsCodeLmModels] = useState<vscodemodels.LanguageModelChatSelector[]>([])
|
const [vsCodeLmModels, setVsCodeLmModels] = useState<vscodemodels.LanguageModelChatSelector[]>([])
|
||||||
@@ -53,12 +53,6 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
|
|||||||
const [azureApiVersionSelected, setAzureApiVersionSelected] = useState(!!apiConfiguration?.azureApiVersion)
|
const [azureApiVersionSelected, setAzureApiVersionSelected] = useState(!!apiConfiguration?.azureApiVersion)
|
||||||
const [isDescriptionExpanded, setIsDescriptionExpanded] = useState(false)
|
const [isDescriptionExpanded, setIsDescriptionExpanded] = useState(false)
|
||||||
|
|
||||||
const handleInputChange = (field: keyof ApiConfiguration) => (event: any) => {
|
|
||||||
const apiConfig = { ...apiConfiguration, [field]: event.target.value }
|
|
||||||
onUpdateApiConfig(apiConfig)
|
|
||||||
// setApiConfiguration(apiConfig)
|
|
||||||
}
|
|
||||||
|
|
||||||
const { selectedProvider, selectedModelId, selectedModelInfo } = useMemo(() => {
|
const { selectedProvider, selectedModelId, selectedModelInfo } = useMemo(() => {
|
||||||
return normalizeApiConfiguration(apiConfiguration)
|
return normalizeApiConfiguration(apiConfiguration)
|
||||||
}, [apiConfiguration])
|
}, [apiConfiguration])
|
||||||
@@ -162,7 +156,7 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
|
|||||||
value={apiConfiguration?.apiKey || ""}
|
value={apiConfiguration?.apiKey || ""}
|
||||||
style={{ width: "100%" }}
|
style={{ width: "100%" }}
|
||||||
type="password"
|
type="password"
|
||||||
onInput={handleInputChange("apiKey")}
|
onChange={handleInputChange("apiKey")}
|
||||||
placeholder="Enter API Key...">
|
placeholder="Enter API Key...">
|
||||||
<span style={{ fontWeight: 500 }}>Anthropic API Key</span>
|
<span style={{ fontWeight: 500 }}>Anthropic API Key</span>
|
||||||
</VSCodeTextField>
|
</VSCodeTextField>
|
||||||
@@ -183,7 +177,7 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
|
|||||||
value={apiConfiguration?.anthropicBaseUrl || ""}
|
value={apiConfiguration?.anthropicBaseUrl || ""}
|
||||||
style={{ width: "100%", marginTop: 3 }}
|
style={{ width: "100%", marginTop: 3 }}
|
||||||
type="url"
|
type="url"
|
||||||
onInput={handleInputChange("anthropicBaseUrl")}
|
onChange={handleInputChange("anthropicBaseUrl")}
|
||||||
placeholder="Default: https://api.anthropic.com"
|
placeholder="Default: https://api.anthropic.com"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -212,7 +206,7 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
|
|||||||
value={apiConfiguration?.glamaApiKey || ""}
|
value={apiConfiguration?.glamaApiKey || ""}
|
||||||
style={{ width: "100%" }}
|
style={{ width: "100%" }}
|
||||||
type="password"
|
type="password"
|
||||||
onInput={handleInputChange("glamaApiKey")}
|
onChange={handleInputChange("glamaApiKey")}
|
||||||
placeholder="Enter API Key...">
|
placeholder="Enter API Key...">
|
||||||
<span style={{ fontWeight: 500 }}>Glama API Key</span>
|
<span style={{ fontWeight: 500 }}>Glama API Key</span>
|
||||||
</VSCodeTextField>
|
</VSCodeTextField>
|
||||||
@@ -241,7 +235,7 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
|
|||||||
value={apiConfiguration?.openAiNativeApiKey || ""}
|
value={apiConfiguration?.openAiNativeApiKey || ""}
|
||||||
style={{ width: "100%" }}
|
style={{ width: "100%" }}
|
||||||
type="password"
|
type="password"
|
||||||
onInput={handleInputChange("openAiNativeApiKey")}
|
onChange={handleInputChange("openAiNativeApiKey")}
|
||||||
placeholder="Enter API Key...">
|
placeholder="Enter API Key...">
|
||||||
<span style={{ fontWeight: 500 }}>OpenAI API Key</span>
|
<span style={{ fontWeight: 500 }}>OpenAI API Key</span>
|
||||||
</VSCodeTextField>
|
</VSCodeTextField>
|
||||||
@@ -269,7 +263,7 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
|
|||||||
value={apiConfiguration?.mistralApiKey || ""}
|
value={apiConfiguration?.mistralApiKey || ""}
|
||||||
style={{ width: "100%" }}
|
style={{ width: "100%" }}
|
||||||
type="password"
|
type="password"
|
||||||
onInput={handleInputChange("mistralApiKey")}
|
onChange={handleInputChange("mistralApiKey")}
|
||||||
placeholder="Enter API Key...">
|
placeholder="Enter API Key...">
|
||||||
<span style={{ fontWeight: 500 }}>Mistral API Key</span>
|
<span style={{ fontWeight: 500 }}>Mistral API Key</span>
|
||||||
</VSCodeTextField>
|
</VSCodeTextField>
|
||||||
@@ -300,7 +294,7 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
|
|||||||
value={apiConfiguration?.openRouterApiKey || ""}
|
value={apiConfiguration?.openRouterApiKey || ""}
|
||||||
style={{ width: "100%" }}
|
style={{ width: "100%" }}
|
||||||
type="password"
|
type="password"
|
||||||
onInput={handleInputChange("openRouterApiKey")}
|
onChange={handleInputChange("openRouterApiKey")}
|
||||||
placeholder="Enter API Key...">
|
placeholder="Enter API Key...">
|
||||||
<span style={{ fontWeight: 500 }}>OpenRouter API Key</span>
|
<span style={{ fontWeight: 500 }}>OpenRouter API Key</span>
|
||||||
</VSCodeTextField>
|
</VSCodeTextField>
|
||||||
@@ -346,7 +340,7 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
|
|||||||
value={apiConfiguration?.awsAccessKey || ""}
|
value={apiConfiguration?.awsAccessKey || ""}
|
||||||
style={{ width: "100%" }}
|
style={{ width: "100%" }}
|
||||||
type="password"
|
type="password"
|
||||||
onInput={handleInputChange("awsAccessKey")}
|
onChange={handleInputChange("awsAccessKey")}
|
||||||
placeholder="Enter Access Key...">
|
placeholder="Enter Access Key...">
|
||||||
<span style={{ fontWeight: 500 }}>AWS Access Key</span>
|
<span style={{ fontWeight: 500 }}>AWS Access Key</span>
|
||||||
</VSCodeTextField>
|
</VSCodeTextField>
|
||||||
@@ -354,7 +348,7 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
|
|||||||
value={apiConfiguration?.awsSecretKey || ""}
|
value={apiConfiguration?.awsSecretKey || ""}
|
||||||
style={{ width: "100%" }}
|
style={{ width: "100%" }}
|
||||||
type="password"
|
type="password"
|
||||||
onInput={handleInputChange("awsSecretKey")}
|
onChange={handleInputChange("awsSecretKey")}
|
||||||
placeholder="Enter Secret Key...">
|
placeholder="Enter Secret Key...">
|
||||||
<span style={{ fontWeight: 500 }}>AWS Secret Key</span>
|
<span style={{ fontWeight: 500 }}>AWS Secret Key</span>
|
||||||
</VSCodeTextField>
|
</VSCodeTextField>
|
||||||
@@ -362,7 +356,7 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
|
|||||||
value={apiConfiguration?.awsSessionToken || ""}
|
value={apiConfiguration?.awsSessionToken || ""}
|
||||||
style={{ width: "100%" }}
|
style={{ width: "100%" }}
|
||||||
type="password"
|
type="password"
|
||||||
onInput={handleInputChange("awsSessionToken")}
|
onChange={handleInputChange("awsSessionToken")}
|
||||||
placeholder="Enter Session Token...">
|
placeholder="Enter Session Token...">
|
||||||
<span style={{ fontWeight: 500 }}>AWS Session Token</span>
|
<span style={{ fontWeight: 500 }}>AWS Session Token</span>
|
||||||
</VSCodeTextField>
|
</VSCodeTextField>
|
||||||
@@ -428,7 +422,7 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
|
|||||||
<VSCodeTextField
|
<VSCodeTextField
|
||||||
value={apiConfiguration?.vertexProjectId || ""}
|
value={apiConfiguration?.vertexProjectId || ""}
|
||||||
style={{ width: "100%" }}
|
style={{ width: "100%" }}
|
||||||
onInput={handleInputChange("vertexProjectId")}
|
onChange={handleInputChange("vertexProjectId")}
|
||||||
placeholder="Enter Project ID...">
|
placeholder="Enter Project ID...">
|
||||||
<span style={{ fontWeight: 500 }}>Google Cloud Project ID</span>
|
<span style={{ fontWeight: 500 }}>Google Cloud Project ID</span>
|
||||||
</VSCodeTextField>
|
</VSCodeTextField>
|
||||||
@@ -486,7 +480,7 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
|
|||||||
value={apiConfiguration?.geminiApiKey || ""}
|
value={apiConfiguration?.geminiApiKey || ""}
|
||||||
style={{ width: "100%" }}
|
style={{ width: "100%" }}
|
||||||
type="password"
|
type="password"
|
||||||
onInput={handleInputChange("geminiApiKey")}
|
onChange={handleInputChange("geminiApiKey")}
|
||||||
placeholder="Enter API Key...">
|
placeholder="Enter API Key...">
|
||||||
<span style={{ fontWeight: 500 }}>Gemini API Key</span>
|
<span style={{ fontWeight: 500 }}>Gemini API Key</span>
|
||||||
</VSCodeTextField>
|
</VSCodeTextField>
|
||||||
@@ -514,7 +508,7 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
|
|||||||
value={apiConfiguration?.openAiBaseUrl || ""}
|
value={apiConfiguration?.openAiBaseUrl || ""}
|
||||||
style={{ width: "100%" }}
|
style={{ width: "100%" }}
|
||||||
type="url"
|
type="url"
|
||||||
onInput={handleInputChange("openAiBaseUrl")}
|
onChange={handleInputChange("openAiBaseUrl")}
|
||||||
placeholder={"Enter base URL..."}>
|
placeholder={"Enter base URL..."}>
|
||||||
<span style={{ fontWeight: 500 }}>Base URL</span>
|
<span style={{ fontWeight: 500 }}>Base URL</span>
|
||||||
</VSCodeTextField>
|
</VSCodeTextField>
|
||||||
@@ -522,7 +516,7 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
|
|||||||
value={apiConfiguration?.openAiApiKey || ""}
|
value={apiConfiguration?.openAiApiKey || ""}
|
||||||
style={{ width: "100%" }}
|
style={{ width: "100%" }}
|
||||||
type="password"
|
type="password"
|
||||||
onInput={handleInputChange("openAiApiKey")}
|
onChange={handleInputChange("openAiApiKey")}
|
||||||
placeholder="Enter API Key...">
|
placeholder="Enter API Key...">
|
||||||
<span style={{ fontWeight: 500 }}>API Key</span>
|
<span style={{ fontWeight: 500 }}>API Key</span>
|
||||||
</VSCodeTextField>
|
</VSCodeTextField>
|
||||||
@@ -552,7 +546,7 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
|
|||||||
<VSCodeTextField
|
<VSCodeTextField
|
||||||
value={apiConfiguration?.azureApiVersion || ""}
|
value={apiConfiguration?.azureApiVersion || ""}
|
||||||
style={{ width: "100%", marginTop: 3 }}
|
style={{ width: "100%", marginTop: 3 }}
|
||||||
onInput={handleInputChange("azureApiVersion")}
|
onChange={handleInputChange("azureApiVersion")}
|
||||||
placeholder={`Default: ${azureOpenAiDefaultApiVersion}`}
|
placeholder={`Default: ${azureOpenAiDefaultApiVersion}`}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -576,14 +570,14 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
|
|||||||
value={apiConfiguration?.lmStudioBaseUrl || ""}
|
value={apiConfiguration?.lmStudioBaseUrl || ""}
|
||||||
style={{ width: "100%" }}
|
style={{ width: "100%" }}
|
||||||
type="url"
|
type="url"
|
||||||
onInput={handleInputChange("lmStudioBaseUrl")}
|
onChange={handleInputChange("lmStudioBaseUrl")}
|
||||||
placeholder={"Default: http://localhost:1234"}>
|
placeholder={"Default: http://localhost:1234"}>
|
||||||
<span style={{ fontWeight: 500 }}>Base URL (optional)</span>
|
<span style={{ fontWeight: 500 }}>Base URL (optional)</span>
|
||||||
</VSCodeTextField>
|
</VSCodeTextField>
|
||||||
<VSCodeTextField
|
<VSCodeTextField
|
||||||
value={apiConfiguration?.lmStudioModelId || ""}
|
value={apiConfiguration?.lmStudioModelId || ""}
|
||||||
style={{ width: "100%" }}
|
style={{ width: "100%" }}
|
||||||
onInput={handleInputChange("lmStudioModelId")}
|
onChange={handleInputChange("lmStudioModelId")}
|
||||||
placeholder={"e.g. meta-llama-3.1-8b-instruct"}>
|
placeholder={"e.g. meta-llama-3.1-8b-instruct"}>
|
||||||
<span style={{ fontWeight: 500 }}>Model ID</span>
|
<span style={{ fontWeight: 500 }}>Model ID</span>
|
||||||
</VSCodeTextField>
|
</VSCodeTextField>
|
||||||
@@ -645,7 +639,7 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
|
|||||||
value={apiConfiguration?.deepSeekApiKey || ""}
|
value={apiConfiguration?.deepSeekApiKey || ""}
|
||||||
style={{ width: "100%" }}
|
style={{ width: "100%" }}
|
||||||
type="password"
|
type="password"
|
||||||
onInput={handleInputChange("deepSeekApiKey")}
|
onChange={handleInputChange("deepSeekApiKey")}
|
||||||
placeholder="Enter API Key...">
|
placeholder="Enter API Key...">
|
||||||
<span style={{ fontWeight: 500 }}>DeepSeek API Key</span>
|
<span style={{ fontWeight: 500 }}>DeepSeek API Key</span>
|
||||||
</VSCodeTextField>
|
</VSCodeTextField>
|
||||||
@@ -735,14 +729,14 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
|
|||||||
value={apiConfiguration?.ollamaBaseUrl || ""}
|
value={apiConfiguration?.ollamaBaseUrl || ""}
|
||||||
style={{ width: "100%" }}
|
style={{ width: "100%" }}
|
||||||
type="url"
|
type="url"
|
||||||
onInput={handleInputChange("ollamaBaseUrl")}
|
onChange={handleInputChange("ollamaBaseUrl")}
|
||||||
placeholder={"Default: http://localhost:11434"}>
|
placeholder={"Default: http://localhost:11434"}>
|
||||||
<span style={{ fontWeight: 500 }}>Base URL (optional)</span>
|
<span style={{ fontWeight: 500 }}>Base URL (optional)</span>
|
||||||
</VSCodeTextField>
|
</VSCodeTextField>
|
||||||
<VSCodeTextField
|
<VSCodeTextField
|
||||||
value={apiConfiguration?.ollamaModelId || ""}
|
value={apiConfiguration?.ollamaModelId || ""}
|
||||||
style={{ width: "100%" }}
|
style={{ width: "100%" }}
|
||||||
onInput={handleInputChange("ollamaModelId")}
|
onChange={handleInputChange("ollamaModelId")}
|
||||||
placeholder={"e.g. llama3.1"}>
|
placeholder={"e.g. llama3.1"}>
|
||||||
<span style={{ fontWeight: 500 }}>Model ID</span>
|
<span style={{ fontWeight: 500 }}>Model ID</span>
|
||||||
</VSCodeTextField>
|
</VSCodeTextField>
|
||||||
|
|||||||
@@ -167,9 +167,18 @@ const GlamaModelPicker: React.FC = () => {
|
|||||||
placeholder="Search and select a model..."
|
placeholder="Search and select a model..."
|
||||||
value={searchTerm}
|
value={searchTerm}
|
||||||
onInput={(e) => {
|
onInput={(e) => {
|
||||||
handleModelChange((e.target as HTMLInputElement)?.value?.toLowerCase())
|
const newModelId = (e.target as HTMLInputElement)?.value?.toLowerCase()
|
||||||
|
const apiConfig = {
|
||||||
|
...apiConfiguration,
|
||||||
|
openAiModelId: newModelId,
|
||||||
|
}
|
||||||
|
setApiConfiguration(apiConfig)
|
||||||
|
setSearchTerm(newModelId)
|
||||||
setIsDropdownVisible(true)
|
setIsDropdownVisible(true)
|
||||||
}}
|
}}
|
||||||
|
onChange={(e) => {
|
||||||
|
handleModelChange((e.target as HTMLInputElement)?.value?.toLowerCase())
|
||||||
|
}}
|
||||||
onFocus={() => setIsDropdownVisible(true)}
|
onFocus={() => setIsDropdownVisible(true)}
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
style={{ width: "100%", zIndex: GLAMA_MODEL_PICKER_Z_INDEX, position: "relative" }}>
|
style={{ width: "100%", zIndex: GLAMA_MODEL_PICKER_Z_INDEX, position: "relative" }}>
|
||||||
|
|||||||
@@ -25,8 +25,6 @@ const OpenAiModelPicker: React.FC = () => {
|
|||||||
}
|
}
|
||||||
setApiConfiguration(apiConfig)
|
setApiConfiguration(apiConfig)
|
||||||
onUpdateApiConfig(apiConfig)
|
onUpdateApiConfig(apiConfig)
|
||||||
|
|
||||||
setSearchTerm(newModelId)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -161,9 +159,18 @@ const OpenAiModelPicker: React.FC = () => {
|
|||||||
placeholder="Search and select a model..."
|
placeholder="Search and select a model..."
|
||||||
value={searchTerm}
|
value={searchTerm}
|
||||||
onInput={(e) => {
|
onInput={(e) => {
|
||||||
handleModelChange((e.target as HTMLInputElement)?.value?.toLowerCase())
|
const newModelId = (e.target as HTMLInputElement)?.value?.toLowerCase()
|
||||||
|
const apiConfig = {
|
||||||
|
...apiConfiguration,
|
||||||
|
openAiModelId: newModelId,
|
||||||
|
}
|
||||||
|
setApiConfiguration(apiConfig)
|
||||||
|
setSearchTerm(newModelId)
|
||||||
setIsDropdownVisible(true)
|
setIsDropdownVisible(true)
|
||||||
}}
|
}}
|
||||||
|
onChange={(e) => {
|
||||||
|
handleModelChange((e.target as HTMLInputElement)?.value?.toLowerCase())
|
||||||
|
}}
|
||||||
onFocus={() => setIsDropdownVisible(true)}
|
onFocus={() => setIsDropdownVisible(true)}
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
style={{ width: "100%", zIndex: OPENAI_MODEL_PICKER_Z_INDEX, position: "relative" }}>
|
style={{ width: "100%", zIndex: OPENAI_MODEL_PICKER_Z_INDEX, position: "relative" }}>
|
||||||
|
|||||||
@@ -167,9 +167,18 @@ const OpenRouterModelPicker: React.FC = () => {
|
|||||||
placeholder="Search and select a model..."
|
placeholder="Search and select a model..."
|
||||||
value={searchTerm}
|
value={searchTerm}
|
||||||
onInput={(e) => {
|
onInput={(e) => {
|
||||||
handleModelChange((e.target as HTMLInputElement)?.value?.toLowerCase())
|
const newModelId = (e.target as HTMLInputElement)?.value?.toLowerCase()
|
||||||
|
const apiConfig = {
|
||||||
|
...apiConfiguration,
|
||||||
|
openAiModelId: newModelId,
|
||||||
|
}
|
||||||
|
setApiConfiguration(apiConfig)
|
||||||
|
setSearchTerm(newModelId)
|
||||||
setIsDropdownVisible(true)
|
setIsDropdownVisible(true)
|
||||||
}}
|
}}
|
||||||
|
onChange={(e) => {
|
||||||
|
handleModelChange((e.target as HTMLInputElement)?.value?.toLowerCase())
|
||||||
|
}}
|
||||||
onFocus={() => setIsDropdownVisible(true)}
|
onFocus={() => setIsDropdownVisible(true)}
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
style={{ width: "100%", zIndex: OPENROUTER_MODEL_PICKER_Z_INDEX, position: "relative" }}>
|
style={{ width: "100%", zIndex: OPENROUTER_MODEL_PICKER_Z_INDEX, position: "relative" }}>
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ export interface ExtensionStateContextType extends ExtensionState {
|
|||||||
setExperimentalDiffStrategy: (value: boolean) => void
|
setExperimentalDiffStrategy: (value: boolean) => void
|
||||||
autoApprovalEnabled?: boolean
|
autoApprovalEnabled?: boolean
|
||||||
setAutoApprovalEnabled: (value: boolean) => void
|
setAutoApprovalEnabled: (value: boolean) => void
|
||||||
|
handleInputChange: (field: keyof ApiConfiguration) => (event: any) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ExtensionStateContext = createContext<ExtensionStateContextType | undefined>(undefined)
|
export const ExtensionStateContext = createContext<ExtensionStateContextType | undefined>(undefined)
|
||||||
@@ -117,15 +118,33 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
|
|||||||
|
|
||||||
const onUpdateApiConfig = useCallback((apiConfig: ApiConfiguration) => {
|
const onUpdateApiConfig = useCallback((apiConfig: ApiConfiguration) => {
|
||||||
setState((currentState) => {
|
setState((currentState) => {
|
||||||
|
console.log("onUpdateApiConfig", currentState, apiConfig)
|
||||||
|
|
||||||
vscode.postMessage({
|
vscode.postMessage({
|
||||||
type: "upsertApiConfiguration",
|
type: "upsertApiConfiguration",
|
||||||
text: currentState.currentApiConfigName, // Access latest state
|
text: currentState.currentApiConfigName,
|
||||||
apiConfiguration: apiConfig,
|
apiConfiguration: apiConfig,
|
||||||
})
|
})
|
||||||
return currentState // No state update needed
|
return currentState // No state update needed
|
||||||
})
|
})
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
const handleInputChange = useCallback(
|
||||||
|
(field: keyof ApiConfiguration) => (event: any) => {
|
||||||
|
setState((currentState) => {
|
||||||
|
console.log("handleInputChange", currentState, event)
|
||||||
|
|
||||||
|
vscode.postMessage({
|
||||||
|
type: "upsertApiConfiguration",
|
||||||
|
text: currentState.currentApiConfigName,
|
||||||
|
apiConfiguration: { ...currentState.apiConfiguration, [field]: event.target.value },
|
||||||
|
})
|
||||||
|
return currentState // No state update needed
|
||||||
|
})
|
||||||
|
},
|
||||||
|
[],
|
||||||
|
)
|
||||||
|
|
||||||
const handleMessage = useCallback(
|
const handleMessage = useCallback(
|
||||||
(event: MessageEvent) => {
|
(event: MessageEvent) => {
|
||||||
const message: ExtensionMessage = event.data
|
const message: ExtensionMessage = event.data
|
||||||
@@ -258,6 +277,7 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
|
|||||||
setExperimentalDiffStrategy: (value) =>
|
setExperimentalDiffStrategy: (value) =>
|
||||||
setState((prevState) => ({ ...prevState, experimentalDiffStrategy: value })),
|
setState((prevState) => ({ ...prevState, experimentalDiffStrategy: value })),
|
||||||
setAutoApprovalEnabled: (value) => setState((prevState) => ({ ...prevState, autoApprovalEnabled: value })),
|
setAutoApprovalEnabled: (value) => setState((prevState) => ({ ...prevState, autoApprovalEnabled: value })),
|
||||||
|
handleInputChange,
|
||||||
}
|
}
|
||||||
|
|
||||||
return <ExtensionStateContext.Provider value={contextValue}>{children}</ExtensionStateContext.Provider>
|
return <ExtensionStateContext.Provider value={contextValue}>{children}</ExtensionStateContext.Provider>
|
||||||
|
|||||||
Reference in New Issue
Block a user