preserve apikeys on save

This commit is contained in:
Martin McKeaveney 2024-09-03 19:12:13 +01:00
parent 378ccb6e70
commit 0d5e776424
4 changed files with 25 additions and 21 deletions

View File

@ -22,6 +22,7 @@
const {provider, defaultModel, name, apiKey} = config const {provider, defaultModel, name, apiKey} = config
validation = provider && defaultModel && name && apiKey validation = provider && defaultModel && name && apiKey
} }
$: canEditBaseUrl = config.provider && ConfigMap[config.provider].baseUrl === ""
function prefillConfig(evt) { function prefillConfig(evt) {
const provider = evt.detail const provider = evt.detail
@ -70,7 +71,7 @@
</div> </div>
<div class="form-row"> <div class="form-row">
<Label size="M">Base URL</Label> <Label size="M">Base URL</Label>
<Input placeholder={"www.google.com"} bind:value={config.baseUrl}/> <Input disabled={!canEditBaseUrl} placeholder={"https://budibase.ai"} bind:value={config.baseUrl}/>
</div> </div>
<div class="form-row"> <div class="form-row">
<Label size="M">API Key</Label> <Label size="M">API Key</Label>

View File

@ -60,10 +60,9 @@
} }
try { try {
const savedConfig = await API.saveConfig(fullAIConfig) await API.saveConfig(fullAIConfig)
fullAIConfig._rev = savedConfig._rev
fullAIConfig._id = savedConfig._id
notifications.success(`Successfully saved and activated AI Configuration`) notifications.success(`Successfully saved and activated AI Configuration`)
await fetchAIConfig()
} catch (error) { } catch (error) {
notifications.error( notifications.error(
`Failed to save AI Configuration, reason: ${error?.message || "Unknown"}` `Failed to save AI Configuration, reason: ${error?.message || "Unknown"}`
@ -76,10 +75,9 @@
delete fullAIConfig.config[key] delete fullAIConfig.config[key]
try { try {
const savedConfig = await API.saveConfig(fullAIConfig) await API.saveConfig(fullAIConfig)
fullAIConfig._rev = savedConfig._rev
fullAIConfig._id = savedConfig._id
notifications.success(`Deleted config`) notifications.success(`Deleted config`)
await fetchAIConfig()
} catch (error) { } catch (error) {
notifications.error( notifications.error(
`Failed to delete config, reason: ${error?.message || "Unknown"}` `Failed to delete config, reason: ${error?.message || "Unknown"}`

View File

@ -112,6 +112,7 @@ export interface SCIMInnerConfig {
export interface SCIMConfig extends Config<SCIMInnerConfig> {} export interface SCIMConfig extends Config<SCIMInnerConfig> {}
export interface AIInnerConfig { export interface AIInnerConfig {
[key: string]: {
// TODO: should be enum // TODO: should be enum
provider: string provider: string
isDefault: boolean isDefault: boolean
@ -122,8 +123,9 @@ export interface AIInnerConfig {
// TODO: should be enum // TODO: should be enum
defaultModel: string defaultModel: string
} }
}
export interface AIConfig extends Config<AIInnerConfig[]> {} export interface AIConfig extends Config<AIInnerConfig> {}
export const isSettingsConfig = (config: Config): config is SettingsConfig => export const isSettingsConfig = (config: Config): config is SettingsConfig =>
config.type === ConfigType.SETTINGS config.type === ConfigType.SETTINGS

View File

@ -200,11 +200,14 @@ async function verifyOIDCConfig(config: OIDCConfigs) {
} }
async function verifyAIConfig(config: AIConfig, existingConfig?: AIConfig) { async function verifyAIConfig(config: AIConfig, existingConfig?: AIConfig) {
if (!existingConfig) return
// ensure that the redacted API keys are not overwritten in the DB // ensure that the redacted API keys are not overwritten in the DB
// for (let aiConfig of existingConfig) { for (let uuid in existingConfig.config) {
// if (config[uuid]?.apiKey === PASSWORD_REPLACEMENT) {
// } config[uuid].apiKey = existingConfig.config[uuid].apiKey
return true }
}
} }
export async function save(ctx: UserCtx<Config>) { export async function save(ctx: UserCtx<Config>) {