preserve apikeys on save
This commit is contained in:
parent
378ccb6e70
commit
0d5e776424
|
@ -22,6 +22,7 @@
|
|||
const {provider, defaultModel, name, apiKey} = config
|
||||
validation = provider && defaultModel && name && apiKey
|
||||
}
|
||||
$: canEditBaseUrl = config.provider && ConfigMap[config.provider].baseUrl === ""
|
||||
|
||||
function prefillConfig(evt) {
|
||||
const provider = evt.detail
|
||||
|
@ -70,7 +71,7 @@
|
|||
</div>
|
||||
<div class="form-row">
|
||||
<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 class="form-row">
|
||||
<Label size="M">API Key</Label>
|
||||
|
|
|
@ -60,10 +60,9 @@
|
|||
}
|
||||
|
||||
try {
|
||||
const savedConfig = await API.saveConfig(fullAIConfig)
|
||||
fullAIConfig._rev = savedConfig._rev
|
||||
fullAIConfig._id = savedConfig._id
|
||||
await API.saveConfig(fullAIConfig)
|
||||
notifications.success(`Successfully saved and activated AI Configuration`)
|
||||
await fetchAIConfig()
|
||||
} catch (error) {
|
||||
notifications.error(
|
||||
`Failed to save AI Configuration, reason: ${error?.message || "Unknown"}`
|
||||
|
@ -76,10 +75,9 @@
|
|||
delete fullAIConfig.config[key]
|
||||
|
||||
try {
|
||||
const savedConfig = await API.saveConfig(fullAIConfig)
|
||||
fullAIConfig._rev = savedConfig._rev
|
||||
fullAIConfig._id = savedConfig._id
|
||||
await API.saveConfig(fullAIConfig)
|
||||
notifications.success(`Deleted config`)
|
||||
await fetchAIConfig()
|
||||
} catch (error) {
|
||||
notifications.error(
|
||||
`Failed to delete config, reason: ${error?.message || "Unknown"}`
|
||||
|
|
|
@ -112,18 +112,20 @@ export interface SCIMInnerConfig {
|
|||
export interface SCIMConfig extends Config<SCIMInnerConfig> {}
|
||||
|
||||
export interface AIInnerConfig {
|
||||
// TODO: should be enum
|
||||
provider: string
|
||||
isDefault: boolean
|
||||
name: string
|
||||
active: boolean
|
||||
baseUrl: string
|
||||
apiKey: string
|
||||
// TODO: should be enum
|
||||
defaultModel: string
|
||||
[key: string]: {
|
||||
// TODO: should be enum
|
||||
provider: string
|
||||
isDefault: boolean
|
||||
name: string
|
||||
active: boolean
|
||||
baseUrl: string
|
||||
apiKey: string
|
||||
// TODO: should be enum
|
||||
defaultModel: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface AIConfig extends Config<AIInnerConfig[]> {}
|
||||
export interface AIConfig extends Config<AIInnerConfig> {}
|
||||
|
||||
export const isSettingsConfig = (config: Config): config is SettingsConfig =>
|
||||
config.type === ConfigType.SETTINGS
|
||||
|
|
|
@ -200,11 +200,14 @@ async function verifyOIDCConfig(config: OIDCConfigs) {
|
|||
}
|
||||
|
||||
async function verifyAIConfig(config: AIConfig, existingConfig?: AIConfig) {
|
||||
if (!existingConfig) return
|
||||
|
||||
// ensure that the redacted API keys are not overwritten in the DB
|
||||
// for (let aiConfig of existingConfig) {
|
||||
//
|
||||
// }
|
||||
return true
|
||||
for (let uuid in existingConfig.config) {
|
||||
if (config[uuid]?.apiKey === PASSWORD_REPLACEMENT) {
|
||||
config[uuid].apiKey = existingConfig.config[uuid].apiKey
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function save(ctx: UserCtx<Config>) {
|
||||
|
|
Loading…
Reference in New Issue