Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: migrate ai setting (#15612)
ecmadao737bf712d0ba
diff --git a/frontend/src/components/GeneralSetting/AIAugmentationSetting.vue b/frontend/src/components/GeneralSetting/AIAugmentationSetting.vueindex 2bb30f3928..68cd56a14b 100644--- a/frontend/src/components/GeneralSetting/AIAugmentationSetting.vue+++ b/frontend/src/components/GeneralSetting/AIAugmentationSetting.vue@@ -125,6 +125,10 @@ import { computed, onMounted, reactive, ref, watchEffect } from "vue";import LearnMoreLink from "@/components/LearnMoreLink.vue";import { hasFeature } from "@/store";import { useSettingV1Store } from "@/store/modules/v1/setting";+import {+ AISetting,+ AISetting_Provider,+} from "@/types/proto/v1/setting_service";import { isDev } from "@/utils";import { FeatureBadge } from "../FeatureGuard";@@ -148,23 +152,17 @@ const state = reactive<LocalState>({openAIModel: "",});-const openAIKeySetting = computed(() =>- settingV1Store.getSettingByName("bb.plugin.openai.key")-);-const openAIEndpointSetting = computed(() =>- settingV1Store.getSettingByName("bb.plugin.openai.endpoint")-);-const openAIModelSetting = computed(() =>- settingV1Store.getSettingByName("bb.plugin.openai.model")+const aiSetting = computed(+ () => settingV1Store.getSettingByName("bb.ai")?.value?.aiSetting);const hasAIFeature = computed(() => hasFeature("bb.feature.ai-assistant"));const getInitialState = (): LocalState => {return {- openAIKey: maskKey(openAIKeySetting.value?.value?.stringValue),- openAIEndpoint: openAIEndpointSetting.value?.value?.stringValue ?? "",- openAIModel: openAIModelSetting.value?.value?.stringValue ?? "",+ openAIKey: maskKey(aiSetting.value?.apiKey),+ openAIEndpoint: aiSetting.value?.endpoint ?? "",+ openAIModel: aiSetting.value?.model ?? "",};};@@ -174,12 +172,11 @@ watchEffect(() => {const allowSave = computed((): boolean => {const openAIKeyUpdated =- state.openAIKey !== maskKey(openAIKeySetting.value?.value?.stringValue) ||+ state.openAIKey !== maskKey(aiSetting.value?.apiKey) ||(state.openAIKey && !state.openAIKey.includes("***"));const openAIEndpointUpdated =- state.openAIEndpoint !== openAIEndpointSetting.value?.value?.stringValue;- const openAIModelUpdated =- state.openAIModel !== openAIModelSetting.value?.value?.stringValue;+ state.openAIEndpoint !== aiSetting.value?.endpoint;+ const openAIModelUpdated = state.openAIModel !== aiSetting.value?.model;return openAIKeyUpdated || openAIEndpointUpdated || openAIModelUpdated;});@@ -188,35 +185,19 @@ function maskKey(key: string | undefined): string {}const updateOpenAIKeyEndpoint = async () => {- if (- state.openAIKey !== maskKey(openAIKeySetting.value?.value?.stringValue) ||- !state.openAIKey.includes("***")- ) {- await settingV1Store.upsertSetting({- name: "bb.plugin.openai.key",- value: {- stringValue: state.openAIKey,- },- });- }- if (- state.openAIEndpoint !== openAIEndpointSetting.value?.value?.stringValue- ) {- await settingV1Store.upsertSetting({- name: "bb.plugin.openai.endpoint",- value: {- stringValue: state.openAIEndpoint,- },- });- }- if (state.openAIEndpoint !== openAIModelSetting.value?.value?.stringValue) {- await settingV1Store.upsertSetting({- name: "bb.plugin.openai.model",- value: {- stringValue: state.openAIModel,- },- });- }+ await settingV1Store.upsertSetting({+ name: "bb.ai",+ value: {+ aiSetting: AISetting.fromPartial({+ ...(aiSetting.value ?? {}),+ apiKey: state.openAIKey,+ endpoint: state.openAIEndpoint,+ model: state.openAIModel,+ // TODO(ed): support change provider.+ provider: AISetting_Provider.OPEN_AI,+ }),+ },+ });Object.assign(state, getInitialState());};diff --git a/frontend/src/plugins/ai/components/ProvideAIContext.vue b/frontend/src/plugins/ai/components/ProvideAIContext.vueindex e976c79260..d143973467 100644--- a/frontend/src/plugins/ai/components/ProvideAIContext.vue+++ b/frontend/src/plugins/ai/components/ProvideAIContext.vue@@ -27,22 +27,12 @@ const state = reactive<LocalState>({});const settingV1Store = useSettingV1Store();-const openAIKeySetting = settingV1Store.getSettingByName(- "bb.plugin.openai.key"-);-const openAIEndpointSetting = settingV1Store.getSettingByName(- "bb.plugin.openai.endpoint"-);-const openAIModelSetting = settingV1Store.getSettingByName(- "bb.plugin.openai.model"-);-const openAIKey = computed(() => openAIKeySetting?.value?.stringValue ?? "");+const aiSetting = settingV1Store.getSettingByName("bb.ai");+const openAIKey = computed(() => aiSetting?.value?.aiSetting?.apiKey ?? "");const openAIEndpoint = computed(- () => openAIEndpointSetting?.value?.stringValue ?? ""-);-const openAIModel = computed(- () => openAIModelSetting?.value?.stringValue ?? ""+ () => aiSetting?.value?.aiSetting?.endpoint ?? "");+const openAIModel = computed(() => aiSetting?.value?.aiSetting?.model ?? "");const { instance, database } = useConnectionOfCurrentSQLEditorTab();const databaseMetadata = useMetadata(diff --git a/frontend/src/types/setting.ts b/frontend/src/types/setting.tsindex 87c4f0ef1d..21e77b8e3c 100644--- a/frontend/src/types/setting.ts+++ b/frontend/src/types/setting.ts@@ -6,9 +6,7 @@ export type SettingName =| "bb.workspace.profile"| "bb.workspace.approval"| "bb.workspace.approval.external"- | "bb.plugin.openai.key"- | "bb.plugin.openai.endpoint"- | "bb.plugin.openai.model"+ | "bb.ai"| "bb.enterprise.trial"| "bb.workspace.schema-template"| "bb.workspace.data-classification"diff --git a/frontend/src/views/sql-editor/EditorCommon/OpenAIButton/OpenAIButton.vue b/frontend/src/views/sql-editor/EditorCommon/OpenAIButton/OpenAIButton.vueindex 9b1722b31a..26036ae06e 100644--- a/frontend/src/views/sql-editor/EditorCommon/OpenAIButton/OpenAIButton.vue+++ b/frontend/src/views/sql-editor/EditorCommon/OpenAIButton/OpenAIButton.vue@@ -85,11 +85,8 @@ const tabStore = useSQLEditorTabStore();const settingV1Store = useSettingV1Store();const databaseChangeMode = useAppFeature("bb.feature.database-change-mode");-const openAIKeySetting = computed(() =>- settingV1Store.getSettingByName("bb.plugin.openai.key")-);const openAIKey = computed(- () => openAIKeySetting.value?.value?.stringValue ?? ""+ () => settingV1Store.getSettingByName("bb.ai")?.value?.aiSetting?.apiKey);const { showAIPanel } = useSQLEditorContext();