feat(history): add AI analysis action

This commit is contained in:
t8y2
2026-05-15 19:53:32 +08:00
parent 048f629d21
commit f031fe85ae
7 changed files with 188 additions and 9 deletions
+34 -1
View File
@@ -46,6 +46,7 @@ import {
import { isPreviewTab } from "@/lib/tabPresentation";
import { supportsSqlFileExecution } from "@/lib/databaseCapabilities";
import { classifyAiSqlExecution } from "@/lib/aiSqlExecutionPolicy";
import { buildHistoryAiAnalysisPrompt } from "@/lib/historyAiAnalysis";
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
@@ -191,6 +192,34 @@ function fixWithAi(errorMessage: string) {
nextTick(() => aiAssistantRef.value?.triggerAction("fix", errorMessage));
}
function openAiPanel() {
if (!showAiPanel.value) {
showAiPanel.value = true;
localStorage.setItem("dbx-ai-panel-open", "true");
}
}
function analyzeHistoryWithAi(entry: HistoryEntry) {
const connectionId = entry.connection_id || activeTab.value?.connectionId;
if (!connectionId) {
toast(t("history.aiAnalyzeNoConnection"), 5000);
return;
}
const config = connectionStore.getConfig(connectionId);
if (!config) {
toast(t("history.aiAnalyzeNoConnection"), 5000);
return;
}
openAiPanel();
const database = entry.database || activeTab.value?.database || resolveDefaultDatabase(config, []);
const title = t("history.aiAnalysisTab");
const tabId = queryStore.createTab(connectionId, database || "", title, "query");
queryStore.updateSql(tabId, entry.sql);
nextTick(() => aiAssistantRef.value?.triggerAction("explain", buildHistoryAiAnalysisPrompt(entry)));
}
function formatActiveSql() {
const tab = activeTab.value;
if (!tab || tab.mode !== "query" || !tab.sql.trim()) return;
@@ -780,7 +809,11 @@ onUnmounted(() => {
:style="{ width: historyWidth + 'px' }"
>
<div class="panel-resize-handle panel-resize-handle--left" @mousedown="startHistoryResize" />
<QueryHistory @restore="restoreHistorySql" @close="showHistory = false" />
<QueryHistory
@restore="restoreHistorySql"
@analyze-ai="analyzeHistoryWithAi"
@close="showHistory = false"
/>
</div>
</div>