11import React , { useState , useEffect } from "react"
22import { VSCodeCheckbox , VSCodeTextField , VSCodeDropdown , VSCodeOption } from "@vscode/webview-ui-toolkit/react"
33import { useAppTranslation } from "@/i18n/TranslationContext"
4- import type { ProviderSettings } from "@roo-code/types"
54
65interface ImageGenerationSettingsProps {
76 enabled : boolean
87 onChange : ( enabled : boolean ) => void
9- apiConfiguration : ProviderSettings
10- setApiConfigurationField : < K extends keyof ProviderSettings > (
11- field : K ,
12- value : ProviderSettings [ K ] ,
13- isUserAction ?: boolean ,
14- ) => void
8+ openRouterImageApiKey ?: string
9+ openRouterImageGenerationSelectedModel ?: string
10+ setOpenRouterImageApiKey : ( apiKey : string ) => void
11+ setImageGenerationSelectedModel : ( model : string ) => void
1512}
1613
1714// Hardcoded list of image generation models
@@ -24,43 +21,34 @@ const IMAGE_GENERATION_MODELS = [
2421export const ImageGenerationSettings = ( {
2522 enabled,
2623 onChange,
27- apiConfiguration,
28- setApiConfigurationField,
24+ openRouterImageApiKey,
25+ openRouterImageGenerationSelectedModel,
26+ setOpenRouterImageApiKey,
27+ setImageGenerationSelectedModel,
2928} : ImageGenerationSettingsProps ) => {
3029 const { t } = useAppTranslation ( )
3130
32- // Get image generation settings from apiConfiguration
33- const imageGenerationSettings = apiConfiguration ?. openRouterImageGenerationSettings || { }
34- const [ openRouterApiKey , setOpenRouterApiKey ] = useState ( imageGenerationSettings . openRouterApiKey || "" )
31+ const [ apiKey , setApiKey ] = useState ( openRouterImageApiKey || "" )
3532 const [ selectedModel , setSelectedModel ] = useState (
36- imageGenerationSettings . selectedModel || IMAGE_GENERATION_MODELS [ 0 ] . value ,
33+ openRouterImageGenerationSelectedModel || IMAGE_GENERATION_MODELS [ 0 ] . value ,
3734 )
3835
39- // Update local state when apiConfiguration changes (e.g., when switching profiles)
36+ // Update local state when props change (e.g., when switching profiles)
4037 useEffect ( ( ) => {
41- setOpenRouterApiKey ( imageGenerationSettings . openRouterApiKey || "" )
42- setSelectedModel ( imageGenerationSettings . selectedModel || IMAGE_GENERATION_MODELS [ 0 ] . value )
43- } , [ imageGenerationSettings . openRouterApiKey , imageGenerationSettings . selectedModel ] )
44-
45- // Helper function to update settings
46- const updateSettings = ( newApiKey : string , newModel : string ) => {
47- const newSettings = {
48- openRouterApiKey : newApiKey ,
49- selectedModel : newModel ,
50- }
51- setApiConfigurationField ( "openRouterImageGenerationSettings" , newSettings , true )
52- }
38+ setApiKey ( openRouterImageApiKey || "" )
39+ setSelectedModel ( openRouterImageGenerationSelectedModel || IMAGE_GENERATION_MODELS [ 0 ] . value )
40+ } , [ openRouterImageApiKey , openRouterImageGenerationSelectedModel ] )
5341
5442 // Handle API key changes
5543 const handleApiKeyChange = ( value : string ) => {
56- setOpenRouterApiKey ( value )
57- updateSettings ( value , selectedModel )
44+ setApiKey ( value )
45+ setOpenRouterImageApiKey ( value )
5846 }
5947
6048 // Handle model selection changes
6149 const handleModelChange = ( value : string ) => {
6250 setSelectedModel ( value )
63- updateSettings ( openRouterApiKey , value )
51+ setImageGenerationSelectedModel ( value )
6452 }
6553
6654 return (
@@ -84,7 +72,7 @@ export const ImageGenerationSettings = ({
8472 { t ( "settings:experimental.IMAGE_GENERATION.openRouterApiKeyLabel" ) }
8573 </ label >
8674 < VSCodeTextField
87- value = { openRouterApiKey }
75+ value = { apiKey }
8876 onInput = { ( e : any ) => handleApiKeyChange ( e . target . value ) }
8977 placeholder = { t ( "settings:experimental.IMAGE_GENERATION.openRouterApiKeyPlaceholder" ) }
9078 className = "w-full"
@@ -123,13 +111,13 @@ export const ImageGenerationSettings = ({
123111 </ div >
124112
125113 { /* Status Message */ }
126- { enabled && ! openRouterApiKey && (
114+ { enabled && ! apiKey && (
127115 < div className = "p-2 bg-vscode-editorWarning-background text-vscode-editorWarning-foreground rounded text-sm" >
128116 { t ( "settings:experimental.IMAGE_GENERATION.warningMissingKey" ) }
129117 </ div >
130118 ) }
131119
132- { enabled && openRouterApiKey && (
120+ { enabled && apiKey && (
133121 < div className = "p-2 bg-vscode-editorInfo-background text-vscode-editorInfo-foreground rounded text-sm" >
134122 { t ( "settings:experimental.IMAGE_GENERATION.successConfigured" ) }
135123 </ div >
0 commit comments