fix types
This commit is contained in:
parent
1ee8a12e29
commit
c6907eb09e
|
@ -84,7 +84,9 @@ export const menu = derived([admin, auth], ([$admin, $auth]) => {
|
|||
menu.push({
|
||||
title: "Settings",
|
||||
href: "/builder/portal/settings",
|
||||
subPages: [...settingsSubPages].sort((a, b) => a.title.localeCompare(b.title)),
|
||||
subPages: [...settingsSubPages].sort((a, b) =>
|
||||
a.title.localeCompare(b.title)
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ export interface AIInnerConfig {
|
|||
active: boolean
|
||||
baseUrl?: string
|
||||
apiKey?: string
|
||||
defaultModel: string
|
||||
defaultModel?: string
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ import {
|
|||
AIConfig,
|
||||
PASSWORD_REPLACEMENT,
|
||||
isAIConfig,
|
||||
AIInnerConfig,
|
||||
} from "@budibase/types"
|
||||
import * as pro from "@budibase/pro"
|
||||
|
||||
|
@ -210,13 +211,13 @@ async function verifyOIDCConfig(config: OIDCConfigs) {
|
|||
}
|
||||
|
||||
export async function verifyAIConfig(
|
||||
config: AIConfig,
|
||||
configToSave: AIInnerConfig,
|
||||
existingConfig: AIConfig
|
||||
) {
|
||||
// ensure that the redacted API keys are not overwritten in the DB
|
||||
for (let uuid in existingConfig.config) {
|
||||
if (config[uuid]?.apiKey === PASSWORD_REPLACEMENT) {
|
||||
config[uuid].apiKey = existingConfig.config[uuid].apiKey
|
||||
if (configToSave[uuid]?.apiKey === PASSWORD_REPLACEMENT) {
|
||||
configToSave[uuid].apiKey = existingConfig.config[uuid].apiKey
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -351,7 +352,7 @@ async function enrichAIConfig(aiConfig: AIConfig) {
|
|||
provider: "OpenAI",
|
||||
active: true,
|
||||
isDefault: !defaultConfigExists,
|
||||
defaultModel: env.BUDIBASE_AI_DEFAULT_MODEL,
|
||||
defaultModel: env.BUDIBASE_AI_DEFAULT_MODEL || "",
|
||||
name: "Budibase AI",
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import * as pro from "@budibase/pro"
|
||||
import { verifyAIConfig } from "../configs"
|
||||
import { TestConfiguration, structures } from "../../../../tests"
|
||||
import { AIInnerConfig } from "@budibase/types"
|
||||
|
||||
describe("Global configs controller", () => {
|
||||
const config = new TestConfiguration()
|
||||
|
@ -29,8 +30,8 @@ describe("Global configs controller", () => {
|
|||
defaultModel: "gpt4",
|
||||
isDefault: false,
|
||||
name: "Test",
|
||||
provider: "OpenAI"
|
||||
}
|
||||
provider: "OpenAI",
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -56,7 +57,7 @@ describe("Global configs controller", () => {
|
|||
defaultModel: "gpt4",
|
||||
isDefault: false,
|
||||
name: "Test",
|
||||
provider: "OpenAI"
|
||||
provider: "OpenAI",
|
||||
},
|
||||
})
|
||||
})
|
||||
|
@ -77,7 +78,7 @@ describe("Global configs controller", () => {
|
|||
defaultModel: "gpt4",
|
||||
isDefault: false,
|
||||
name: "Test",
|
||||
provider: "OpenAI"
|
||||
provider: "OpenAI",
|
||||
},
|
||||
})
|
||||
})
|
||||
|
@ -87,22 +88,18 @@ describe("Global configs controller", () => {
|
|||
await config.api.configs.saveConfig(data)
|
||||
const existingConfig = await config.api.configs.getAIConfig()
|
||||
|
||||
const newConfig = {
|
||||
type: "ai",
|
||||
config: {
|
||||
aiconfig: {
|
||||
provider: "OpenAI",
|
||||
isDefault: true,
|
||||
name: "MyConfig",
|
||||
active: true,
|
||||
defaultModel: "gpt4",
|
||||
apiKey: "myapikey",
|
||||
},
|
||||
const newConfig: AIInnerConfig = {
|
||||
aiconfig: {
|
||||
provider: "OpenAI",
|
||||
isDefault: true,
|
||||
name: "MyConfig",
|
||||
active: true,
|
||||
defaultModel: "gpt4",
|
||||
},
|
||||
}
|
||||
|
||||
await verifyAIConfig(newConfig, existingConfig)
|
||||
await verifyAIConfig(newConfig, existingConfig.body)
|
||||
// should be unchanged
|
||||
expect(newConfig.config.aiconfig.apiKey).toEqual("myapikey")
|
||||
expect(newConfig.aiconfig.apiKey).toEqual("myapikey")
|
||||
})
|
||||
})
|
||||
|
|
|
@ -30,7 +30,6 @@ export class ConfigAPI extends TestAPI {
|
|||
.expect("Content-Type", /json/)
|
||||
}
|
||||
|
||||
|
||||
saveConfig = (data: any) => {
|
||||
return this.request
|
||||
.post(`/api/global/configs`)
|
||||
|
|
|
@ -4,7 +4,8 @@ import {
|
|||
ConfigType,
|
||||
SMTPConfig,
|
||||
GoogleConfig,
|
||||
OIDCConfig, AIConfig,
|
||||
OIDCConfig,
|
||||
AIConfig,
|
||||
} from "@budibase/types"
|
||||
|
||||
export function oidc(conf?: any): OIDCConfig {
|
||||
|
@ -95,6 +96,6 @@ export function ai(): AIConfig {
|
|||
apiKey: "abc123APIKey",
|
||||
baseUrl: "https://api.example.com",
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue