fix types

This commit is contained in:
Martin McKeaveney 2024-09-10 16:41:44 +01:00
parent 1ee8a12e29
commit c6907eb09e
6 changed files with 26 additions and 26 deletions

View File

@ -84,7 +84,9 @@ export const menu = derived([admin, auth], ([$admin, $auth]) => {
menu.push({ menu.push({
title: "Settings", title: "Settings",
href: "/builder/portal/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)
),
}) })
} }

View File

@ -121,7 +121,7 @@ export interface AIInnerConfig {
active: boolean active: boolean
baseUrl?: string baseUrl?: string
apiKey?: string apiKey?: string
defaultModel: string defaultModel?: string
} }
} }

View File

@ -32,6 +32,7 @@ import {
AIConfig, AIConfig,
PASSWORD_REPLACEMENT, PASSWORD_REPLACEMENT,
isAIConfig, isAIConfig,
AIInnerConfig,
} from "@budibase/types" } from "@budibase/types"
import * as pro from "@budibase/pro" import * as pro from "@budibase/pro"
@ -210,13 +211,13 @@ async function verifyOIDCConfig(config: OIDCConfigs) {
} }
export async function verifyAIConfig( export async function verifyAIConfig(
config: AIConfig, configToSave: AIInnerConfig,
existingConfig: AIConfig existingConfig: AIConfig
) { ) {
// 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 uuid in existingConfig.config) { for (let uuid in existingConfig.config) {
if (config[uuid]?.apiKey === PASSWORD_REPLACEMENT) { if (configToSave[uuid]?.apiKey === PASSWORD_REPLACEMENT) {
config[uuid].apiKey = existingConfig.config[uuid].apiKey configToSave[uuid].apiKey = existingConfig.config[uuid].apiKey
} }
} }
} }
@ -351,7 +352,7 @@ async function enrichAIConfig(aiConfig: AIConfig) {
provider: "OpenAI", provider: "OpenAI",
active: true, active: true,
isDefault: !defaultConfigExists, isDefault: !defaultConfigExists,
defaultModel: env.BUDIBASE_AI_DEFAULT_MODEL, defaultModel: env.BUDIBASE_AI_DEFAULT_MODEL || "",
name: "Budibase AI", name: "Budibase AI",
} }
} }

View File

@ -1,6 +1,7 @@
import * as pro from "@budibase/pro" import * as pro from "@budibase/pro"
import { verifyAIConfig } from "../configs" import { verifyAIConfig } from "../configs"
import { TestConfiguration, structures } from "../../../../tests" import { TestConfiguration, structures } from "../../../../tests"
import { AIInnerConfig } from "@budibase/types"
describe("Global configs controller", () => { describe("Global configs controller", () => {
const config = new TestConfiguration() const config = new TestConfiguration()
@ -29,8 +30,8 @@ describe("Global configs controller", () => {
defaultModel: "gpt4", defaultModel: "gpt4",
isDefault: false, isDefault: false,
name: "Test", name: "Test",
provider: "OpenAI" provider: "OpenAI",
} },
}) })
}) })
@ -56,7 +57,7 @@ describe("Global configs controller", () => {
defaultModel: "gpt4", defaultModel: "gpt4",
isDefault: false, isDefault: false,
name: "Test", name: "Test",
provider: "OpenAI" provider: "OpenAI",
}, },
}) })
}) })
@ -77,7 +78,7 @@ describe("Global configs controller", () => {
defaultModel: "gpt4", defaultModel: "gpt4",
isDefault: false, isDefault: false,
name: "Test", name: "Test",
provider: "OpenAI" provider: "OpenAI",
}, },
}) })
}) })
@ -87,22 +88,18 @@ describe("Global configs controller", () => {
await config.api.configs.saveConfig(data) await config.api.configs.saveConfig(data)
const existingConfig = await config.api.configs.getAIConfig() const existingConfig = await config.api.configs.getAIConfig()
const newConfig = { const newConfig: AIInnerConfig = {
type: "ai", aiconfig: {
config: { provider: "OpenAI",
aiconfig: { isDefault: true,
provider: "OpenAI", name: "MyConfig",
isDefault: true, active: true,
name: "MyConfig", defaultModel: "gpt4",
active: true,
defaultModel: "gpt4",
apiKey: "myapikey",
},
}, },
} }
await verifyAIConfig(newConfig, existingConfig) await verifyAIConfig(newConfig, existingConfig.body)
// should be unchanged // should be unchanged
expect(newConfig.config.aiconfig.apiKey).toEqual("myapikey") expect(newConfig.aiconfig.apiKey).toEqual("myapikey")
}) })
}) })

View File

@ -30,7 +30,6 @@ export class ConfigAPI extends TestAPI {
.expect("Content-Type", /json/) .expect("Content-Type", /json/)
} }
saveConfig = (data: any) => { saveConfig = (data: any) => {
return this.request return this.request
.post(`/api/global/configs`) .post(`/api/global/configs`)

View File

@ -4,7 +4,8 @@ import {
ConfigType, ConfigType,
SMTPConfig, SMTPConfig,
GoogleConfig, GoogleConfig,
OIDCConfig, AIConfig, OIDCConfig,
AIConfig,
} from "@budibase/types" } from "@budibase/types"
export function oidc(conf?: any): OIDCConfig { export function oidc(conf?: any): OIDCConfig {
@ -95,6 +96,6 @@ export function ai(): AIConfig {
apiKey: "abc123APIKey", apiKey: "abc123APIKey",
baseUrl: "https://api.example.com", baseUrl: "https://api.example.com",
}, },
} },
} }
} }