fix(redis): route AI commands to Redis console

This commit is contained in:
t8y2 committed 2026-07-22 11:41:43 +08:00
1 parent 1b399a58d0
commit 330d27d718
5 files changed
+113 -5

No files matched your search

@@ -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>
<button
@@ -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>
@@ -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>