diff --git a/app/components/settings.tsx b/app/components/settings.tsx index 1388b196d48..e95722f1d28 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -658,6 +658,389 @@ export function Settings() { const clientConfig = useMemo(() => getClientConfig(), []); const showAccessCode = enabledAccessControl && !clientConfig?.isApp; + const accessCodeComponent = showAccessCode && ( + + { + accessStore.update( + (access) => (access.accessCode = e.currentTarget.value), + ); + }} + /> + + ); + + const useCustomConfigComponent = // Conditionally render the following ListItem based on clientConfig.isApp + !clientConfig?.isApp && ( // only show if isApp is false + + + accessStore.update( + (access) => (access.useCustomConfig = e.currentTarget.checked), + ) + } + > + + ); + + const openAIConfigComponent = accessStore.provider === + ServiceProvider.OpenAI && ( + <> + + + accessStore.update( + (access) => (access.openaiUrl = e.currentTarget.value), + ) + } + > + + + { + accessStore.update( + (access) => (access.openaiApiKey = e.currentTarget.value), + ); + }} + /> + + + ); + + const azureConfigComponent = accessStore.provider === + ServiceProvider.Azure && ( + <> + + + accessStore.update( + (access) => (access.azureUrl = e.currentTarget.value), + ) + } + > + + + { + accessStore.update( + (access) => (access.azureApiKey = e.currentTarget.value), + ); + }} + /> + + + + accessStore.update( + (access) => (access.azureApiVersion = e.currentTarget.value), + ) + } + > + + + ); + + const googleConfigComponent = accessStore.provider === + ServiceProvider.Google && ( + <> + + + accessStore.update( + (access) => (access.googleUrl = e.currentTarget.value), + ) + } + > + + + { + accessStore.update( + (access) => (access.googleApiKey = e.currentTarget.value), + ); + }} + /> + + + + accessStore.update( + (access) => (access.googleApiVersion = e.currentTarget.value), + ) + } + > + + + + + + ); + + const anthropicConfigComponent = accessStore.provider === + ServiceProvider.Anthropic && ( + <> + + + accessStore.update( + (access) => (access.anthropicUrl = e.currentTarget.value), + ) + } + > + + + { + accessStore.update( + (access) => (access.anthropicApiKey = e.currentTarget.value), + ); + }} + /> + + + + accessStore.update( + (access) => (access.anthropicApiVersion = e.currentTarget.value), + ) + } + > + + + ); + + const baiduConfigComponent = accessStore.provider === + ServiceProvider.Baidu && ( + <> + + + accessStore.update( + (access) => (access.baiduUrl = e.currentTarget.value), + ) + } + > + + + { + accessStore.update( + (access) => (access.baiduApiKey = e.currentTarget.value), + ); + }} + /> + + + { + accessStore.update( + (access) => (access.baiduSecretKey = e.currentTarget.value), + ); + }} + /> + + + ); + + const byteDanceConfigComponent = accessStore.provider === + ServiceProvider.ByteDance && ( + <> + + + accessStore.update( + (access) => (access.bytedanceUrl = e.currentTarget.value), + ) + } + > + + + { + accessStore.update( + (access) => (access.bytedanceApiKey = e.currentTarget.value), + ); + }} + /> + + + ); + + const alibabaConfigComponent = accessStore.provider === + ServiceProvider.Alibaba && ( + <> + + + accessStore.update( + (access) => (access.alibabaUrl = e.currentTarget.value), + ) + } + > + + + { + accessStore.update( + (access) => (access.alibabaApiKey = e.currentTarget.value), + ); + }} + /> + + + ); + return (
@@ -904,46 +1287,12 @@ export function Settings() { - {showAccessCode && ( - - { - accessStore.update( - (access) => (access.accessCode = e.currentTarget.value), - ); - }} - /> - - )} + {accessCodeComponent} {!accessStore.hideUserApiKey && ( <> - { - // Conditionally render the following ListItem based on clientConfig.isApp - !clientConfig?.isApp && ( // only show if isApp is false - - - accessStore.update( - (access) => - (access.useCustomConfig = e.currentTarget.checked), - ) - } - > - - ) - } + {useCustomConfigComponent} + {accessStore.useCustomConfig && ( <> - {accessStore.provider === ServiceProvider.OpenAI && ( - <> - - - accessStore.update( - (access) => - (access.openaiUrl = e.currentTarget.value), - ) - } - > - - - { - accessStore.update( - (access) => - (access.openaiApiKey = e.currentTarget.value), - ); - }} - /> - - - )} - {accessStore.provider === ServiceProvider.Azure && ( - <> - - - accessStore.update( - (access) => - (access.azureUrl = e.currentTarget.value), - ) - } - > - - - { - accessStore.update( - (access) => - (access.azureApiKey = e.currentTarget.value), - ); - }} - /> - - - - accessStore.update( - (access) => - (access.azureApiVersion = - e.currentTarget.value), - ) - } - > - - - )} - {accessStore.provider === ServiceProvider.Google && ( - <> - - - accessStore.update( - (access) => - (access.googleUrl = e.currentTarget.value), - ) - } - > - - - { - accessStore.update( - (access) => - (access.googleApiKey = e.currentTarget.value), - ); - }} - /> - - - - accessStore.update( - (access) => - (access.googleApiVersion = - e.currentTarget.value), - ) - } - > - - - - - - )} - {accessStore.provider === ServiceProvider.Anthropic && ( - <> - - - accessStore.update( - (access) => - (access.anthropicUrl = e.currentTarget.value), - ) - } - > - - - { - accessStore.update( - (access) => - (access.anthropicApiKey = - e.currentTarget.value), - ); - }} - /> - - - - accessStore.update( - (access) => - (access.anthropicApiVersion = - e.currentTarget.value), - ) - } - > - - - )} - {accessStore.provider === ServiceProvider.Baidu && ( - <> - - - accessStore.update( - (access) => - (access.baiduUrl = e.currentTarget.value), - ) - } - > - - - { - accessStore.update( - (access) => - (access.baiduApiKey = e.currentTarget.value), - ); - }} - /> - - - { - accessStore.update( - (access) => - (access.baiduSecretKey = e.currentTarget.value), - ); - }} - /> - - - )} - - {accessStore.provider === ServiceProvider.ByteDance && ( - <> - - - accessStore.update( - (access) => - (access.bytedanceUrl = e.currentTarget.value), - ) - } - > - - - { - accessStore.update( - (access) => - (access.bytedanceApiKey = - e.currentTarget.value), - ); - }} - /> - - - )} - - {accessStore.provider === ServiceProvider.Alibaba && ( - <> - - - accessStore.update( - (access) => - (access.alibabaUrl = e.currentTarget.value), - ) - } - > - - - { - accessStore.update( - (access) => - (access.alibabaApiKey = e.currentTarget.value), - ); - }} - /> - - - )} + {openAIConfigComponent} + {azureConfigComponent} + {googleConfigComponent} + {anthropicConfigComponent} + {baiduConfigComponent} + {byteDanceConfigComponent} + {alibabaConfigComponent} )}