mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-31 16:24:33 +00:00
feat: Enhance AI Assistant with new actions and context handling
This commit is contained in:
@@ -50,6 +50,23 @@ export const useQueryStore = defineStore("query", () => {
|
||||
if (tab) tab.sql = sql;
|
||||
}
|
||||
|
||||
function updateDatabase(id: string, database: string) {
|
||||
const tab = tabs.value.find((t) => t.id === id);
|
||||
if (!tab || tab.database === database) return;
|
||||
tab.database = database;
|
||||
tab.result = undefined;
|
||||
tab.tableMeta = undefined;
|
||||
}
|
||||
|
||||
function updateConnection(id: string, connectionId: string, database = "") {
|
||||
const tab = tabs.value.find((t) => t.id === id);
|
||||
if (!tab || tab.connectionId === connectionId) return;
|
||||
tab.connectionId = connectionId;
|
||||
tab.database = database;
|
||||
tab.result = undefined;
|
||||
tab.tableMeta = undefined;
|
||||
}
|
||||
|
||||
function setTableMeta(id: string, meta: NonNullable<QueryTab["tableMeta"]>) {
|
||||
const tab = tabs.value.find((t) => t.id === id);
|
||||
if (tab) tab.tableMeta = meta;
|
||||
@@ -89,6 +106,8 @@ export const useQueryStore = defineStore("query", () => {
|
||||
createTab,
|
||||
closeTab,
|
||||
updateSql,
|
||||
updateDatabase,
|
||||
updateConnection,
|
||||
setTableMeta,
|
||||
executeCurrentTab,
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
import * as api from "@/lib/tauri";
|
||||
|
||||
export type AiProvider = "claude" | "openai" | "custom";
|
||||
|
||||
@@ -17,22 +18,35 @@ const defaultConfigs: Record<AiProvider, Omit<AiConfig, "apiKey">> = {
|
||||
};
|
||||
|
||||
export const useSettingsStore = defineStore("settings", () => {
|
||||
const saved = localStorage.getItem("dbx-ai-config");
|
||||
const aiConfig = ref<AiConfig>(saved ? JSON.parse(saved) : { ...defaultConfigs.claude, apiKey: "" });
|
||||
const aiConfig = ref<AiConfig>({ ...defaultConfigs.claude, apiKey: "" });
|
||||
const isAiConfigLoaded = ref(false);
|
||||
|
||||
async function initAiConfig() {
|
||||
if (isAiConfigLoaded.value) return;
|
||||
const legacy = localStorage.getItem("dbx-ai-config");
|
||||
const saved = await api.loadAiConfig().catch(() => null);
|
||||
if (saved) {
|
||||
aiConfig.value = saved;
|
||||
} else if (legacy) {
|
||||
aiConfig.value = JSON.parse(legacy);
|
||||
await api.saveAiConfig(aiConfig.value).catch(() => {});
|
||||
localStorage.removeItem("dbx-ai-config");
|
||||
}
|
||||
isAiConfigLoaded.value = true;
|
||||
}
|
||||
|
||||
function updateAiConfig(config: Partial<AiConfig>) {
|
||||
Object.assign(aiConfig.value, config);
|
||||
if (config.provider && config.provider !== aiConfig.value.provider) {
|
||||
const defaults = defaultConfigs[config.provider];
|
||||
aiConfig.value.endpoint = defaults.endpoint;
|
||||
aiConfig.value.model = defaults.model;
|
||||
const previousProvider = aiConfig.value.provider;
|
||||
if (config.provider && config.provider !== previousProvider) {
|
||||
Object.assign(aiConfig.value, defaultConfigs[config.provider]);
|
||||
}
|
||||
localStorage.setItem("dbx-ai-config", JSON.stringify(aiConfig.value));
|
||||
Object.assign(aiConfig.value, config);
|
||||
api.saveAiConfig(aiConfig.value).catch(() => {});
|
||||
}
|
||||
|
||||
function isConfigured(): boolean {
|
||||
return !!aiConfig.value.apiKey && !!aiConfig.value.endpoint;
|
||||
}
|
||||
|
||||
return { aiConfig, updateAiConfig, isConfigured };
|
||||
return { aiConfig, isAiConfigLoaded, initAiConfig, updateAiConfig, isConfigured };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user