diff --git a/apps/desktop/src/App.vue b/apps/desktop/src/App.vue index e50fbb53bc..8918dd8470 100644 --- a/apps/desktop/src/App.vue +++ b/apps/desktop/src/App.vue @@ -1514,7 +1514,24 @@ function ensureQueryTab(): string { return queryStore.createTab(connId, db, undefined, "query"); } +function routeAiRedisCommand(command: string, execute: boolean): boolean { + if (activeConnection.value?.db_type !== "redis") return false; + + // Redis has a dedicated console. Falling through to ensureQueryTab() would + // recreate the original bug by opening a SQL tab for a Redis command. + const routed = execute ? contentAreaRef.value?.executeRedisCommand(command) : contentAreaRef.value?.insertRedisCommand(command); + if (!routed) { + console.warn("[DBX] Redis AI command could not reach the active Redis console"); + return true; + } + void routed.then((handled) => { + if (!handled) console.warn("[DBX] Redis AI command could not reach the active Redis console"); + }); + return true; +} + function onAiReplaceSql(sql: string) { + if (routeAiRedisCommand(sql, false)) return; const tabId = ensureQueryTab(); queryStore.updateSql(tabId, sql); } @@ -1525,17 +1542,20 @@ function runAiGeneratedSql(sql: string) { } function onAiExecuteSql(sql: string) { + if (routeAiRedisCommand(sql, true)) return; const tabId = ensureQueryTab(); queryStore.updateSql(tabId, buildAppendedEditorSql(activeTab.value?.sql || "", sql)); runAiGeneratedSql(sql); } function onAiTempRunSql(sql: string) { + if (routeAiRedisCommand(sql, true)) return; ensureQueryTab(); runAiGeneratedSql(sql); } function onAiRequestAutoExecuteSql(sql: string) { + if (routeAiRedisCommand(sql, true)) return; const tabId = ensureQueryTab(); queryStore.updateSql(tabId, buildAppendedEditorSql(activeTab.value?.sql || "", sql)); selectedSql.value = ""; @@ -2264,6 +2284,8 @@ onUnmounted(() => { @execute-sql="onAiExecuteSql" @temp-run-sql="onAiTempRunSql" @request-auto-execute-sql="onAiRequestAutoExecuteSql" + @insert-redis-command="(command: string) => routeAiRedisCommand(command, false)" + @execute-redis-command="(command: string) => routeAiRedisCommand(command, true)" @open-explain-plan="onAiOpenExplainPlan" @close="closeRightSidebarPanel('ai')" /> diff --git a/apps/desktop/src/components/editor/AiAssistant.vue b/apps/desktop/src/components/editor/AiAssistant.vue index 397f5e07f5..272f866abf 100644 --- a/apps/desktop/src/components/editor/AiAssistant.vue +++ b/apps/desktop/src/components/editor/AiAssistant.vue @@ -132,6 +132,8 @@ const emit = defineEmits<{ executeSql: [sql: string]; tempRunSql: [sql: string]; requestAutoExecuteSql: [sql: string]; + insertRedisCommand: [command: string]; + executeRedisCommand: [command: string]; openExplainPlan: [sql: string]; close: []; }>(); @@ -390,6 +392,7 @@ const agentActionButtons: AiActionButton[] = [ ]; const actionButtons = computed(() => (assistantMode.value === "agent" ? agentActionButtons : askActionButtons)); +const isRedisConnection = computed(() => props.connection?.db_type === "redis"); // Vector DBs hide the action menu and only expose collection tools. // Keep their action at `generate` so the task contract doesn't tell the LLM to call execute_query. @@ -1531,14 +1534,26 @@ async function cancelStream() { } function applySql(code: string) { + if (isRedisConnection.value) { + emit("insertRedisCommand", code); + return; + } emit("replaceSql", code); } function executeSql(code: string) { + if (isRedisConnection.value) { + emit("executeRedisCommand", code); + return; + } emit("executeSql", code); } function tempRunSql(code: string) { + if (isRedisConnection.value) { + emit("executeRedisCommand", code); + return; + } emit("tempRunSql", code); } @@ -1918,13 +1933,13 @@ async function openExternalUrl(url: string) { {{ seg.lang }}
- - -