25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(redis): route AI commands to Redis console
t8y2330d27d7180c
diff --git a/apps/desktop/src/App.vue b/apps/desktop/src/App.vueindex 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.vueindex 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<AiActionButton[]>(() => (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) {<span>{{ seg.lang }}</span><span class="flex-1" /><div class="flex items-center gap-1.5">- <button v-if="seg.isSql" class="rounded p-0.5 text-zinc-500 hover:bg-zinc-200 hover:text-zinc-900 dark:text-zinc-400 dark:hover:bg-zinc-700 dark:hover:text-zinc-200" :title="t('ai.tempRunSql')" @click="tempRunSql(seg.content)">+ <button v-if="seg.isSql && !isRedisConnection" class="rounded p-0.5 text-zinc-500 hover:bg-zinc-200 hover:text-zinc-900 dark:text-zinc-400 dark:hover:bg-zinc-700 dark:hover:text-zinc-200" :title="t('ai.tempRunSql')" @click="tempRunSql(seg.content)"><FlaskConical class="h-3.5 w-3.5" /></button>- <button v-if="seg.isSql" class="rounded p-0.5 text-zinc-500 hover:bg-zinc-200 hover:text-zinc-900 dark:text-zinc-400 dark:hover:bg-zinc-700 dark:hover:text-zinc-200" :title="t('ai.executeSql')" @click="executeSql(seg.content)">+ <button v-if="seg.isSql || isRedisConnection" class="rounded p-0.5 text-zinc-500 hover:bg-zinc-200 hover:text-zinc-900 dark:text-zinc-400 dark:hover:bg-zinc-700 dark:hover:text-zinc-200" :title="t('ai.executeSql')" @click="executeSql(seg.content)"><Play class="h-3.5 w-3.5" /></button>- <button v-if="seg.isSql" class="rounded p-0.5 text-zinc-500 hover:bg-zinc-200 hover:text-zinc-900 dark:text-zinc-400 dark:hover:bg-zinc-700 dark:hover:text-zinc-200" :title="t('ai.apply')" @click="applySql(seg.content)">+ <button v-if="seg.isSql || isRedisConnection" class="rounded p-0.5 text-zinc-500 hover:bg-zinc-200 hover:text-zinc-900 dark:text-zinc-400 dark:hover:bg-zinc-700 dark:hover:text-zinc-200" :title="t('ai.apply')" @click="applySql(seg.content)"><Replace class="h-3.5 w-3.5" /></button><buttondiff --git a/apps/desktop/src/components/layout/ContentArea.vue b/apps/desktop/src/components/layout/ContentArea.vueindex 0b784a09ee..c44bb75f67 100644--- a/apps/desktop/src/components/layout/ContentArea.vue+++ b/apps/desktop/src/components/layout/ContentArea.vue@@ -119,6 +119,8 @@ type DataGridHandle = {type SearchableBrowserHandle = {focusSearch: () => boolean;refresh?: () => boolean;+ insertCommand?: (command: string) => Promise<boolean>;+ executeCommand?: (command: string) => Promise<boolean>;};const props = defineProps<{@@ -788,7 +790,17 @@ function applyTableStructureChanges() {return tableStructureEditorRef.value?.applyChanges() ?? Promise.resolve(false);}-defineExpose({ focusSearch, refreshData, refreshQueryEditorCompletionCache, handleModRTarget, requestQueryEditorExecute, pasteClipboardAsSqlInCondition, applyTableStructureChanges });+async function insertRedisCommand(command: string): Promise<boolean> {+ if (props.activeTab.mode !== "redis") return false;+ return (await redisKeyBrowserRef.value?.insertCommand?.(command)) ?? false;+}++async function executeRedisCommand(command: string): Promise<boolean> {+ if (props.activeTab.mode !== "redis") return false;+ return (await redisKeyBrowserRef.value?.executeCommand?.(command)) ?? false;+}++defineExpose({ focusSearch, refreshData, refreshQueryEditorCompletionCache, handleModRTarget, requestQueryEditorExecute, pasteClipboardAsSqlInCondition, applyTableStructureChanges, insertRedisCommand, executeRedisCommand });</script><template>diff --git a/apps/desktop/src/components/redis/RedisKeyBrowser.vue b/apps/desktop/src/components/redis/RedisKeyBrowser.vueindex 30ede5daa9..bb0794c2e1 100644--- a/apps/desktop/src/components/redis/RedisKeyBrowser.vue+++ b/apps/desktop/src/components/redis/RedisKeyBrowser.vue@@ -1111,7 +1111,25 @@ watch(},);-defineExpose({ focusSearch });+async function insertCommand(command: string): Promise<boolean> {+ const normalizedCommand = command.trim();+ if (!normalizedCommand || commandRunning.value) return false;+ await openCommandPanel();+ commandText.value = normalizedCommand;+ await nextTick();+ getCommandInput()?.focus();+ return true;+}++async function executeAiCommand(command: string): Promise<boolean> {+ if (!(await insertCommand(command))) return false;+ // Reuse the interactive console path so blocked commands, confirmations, and+ // the disabled-safety preference behave exactly like manually entered commands.+ await executeCommand();+ return true;+}++defineExpose({ focusSearch, insertCommand, executeCommand: executeAiCommand });</script><template>diff --git a/apps/desktop/src/lib/ai/__tests__/aiRedisConsoleRouting.spec.ts b/apps/desktop/src/lib/ai/__tests__/aiRedisConsoleRouting.spec.tsnew file mode 100644index 0000000000..c14601dcd1--- /dev/null+++ b/apps/desktop/src/lib/ai/__tests__/aiRedisConsoleRouting.spec.ts@@ -0,0 +1,41 @@+import { readFileSync } from "node:fs";+import { describe, expect, it } from "vitest";+import { classifyRedisCommandSafety } from "@/lib/redis/redisCommandSafety";++const aiAssistantSource = readFileSync(new URL("../../../components/editor/AiAssistant.vue", import.meta.url), "utf8");+const appSource = readFileSync(new URL("../../../App.vue", import.meta.url), "utf8");+const contentAreaSource = readFileSync(new URL("../../../components/layout/ContentArea.vue", import.meta.url), "utf8");+const redisBrowserSource = readFileSync(new URL("../../../components/redis/RedisKeyBrowser.vue", import.meta.url), "utf8");++describe("AI Redis console routing", () => {+ it("routes Redis insert and execute actions to the active Redis console", () => {+ expect(aiAssistantSource).toContain('emit("insertRedisCommand", code)');+ expect(aiAssistantSource).toContain('emit("executeRedisCommand", code)');+ expect(aiAssistantSource).toContain("seg.isSql || isRedisConnection");+ expect(appSource).toContain("if (routeAiRedisCommand(sql, false)) return;");+ expect(appSource).toContain("if (routeAiRedisCommand(sql, true)) return;");+ expect(contentAreaSource).toContain('props.activeTab.mode !== "redis"');+ expect(contentAreaSource).toContain("redisKeyBrowserRef.value?.executeCommand?.(command)");+ });++ it("keeps the existing SQL editor and execution behavior for non-Redis connections", () => {+ expect(aiAssistantSource).toContain('emit("replaceSql", code)');+ expect(aiAssistantSource).toContain('emit("executeSql", code)');+ expect(aiAssistantSource).toContain('emit("tempRunSql", code)');+ expect(appSource).toContain("const tabId = ensureQueryTab();");+ expect(appSource).toContain('buildAppendedEditorSql(activeTab.value?.sql || "", sql)');+ expect(appSource).toContain("const decision = classifyAiSqlExecution(sql, activeConnection.value);");+ });++ it("uses the console safety path and rejects unavailable command input", () => {+ expect(classifyRedisCommandSafety("CONFIG SET requirepass secret")).toBe("blocked");+ expect(classifyRedisCommandSafety("FLUSHDB")).toBe("confirm");+ expect(classifyRedisCommandSafety("SET issue:846 fixed")).toBe("write");+ expect(classifyRedisCommandSafety("INFO server")).toBe("allowed");++ expect(redisBrowserSource).toContain("if (!normalizedCommand || commandRunning.value) return false;");+ expect(redisBrowserSource).toContain("await executeCommand();");+ expect(redisBrowserSource).not.toMatch(/async function executeAiCommand[\s\S]*?await runRedisCommand\(command\)/);+ expect(contentAreaSource).toContain("?? false");+ });+});