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(ai): restore progressive composer controls
t8y262bf47a0e919
diff --git a/apps/desktop/src/components/editor/AiAssistant.vue b/apps/desktop/src/components/editor/AiAssistant.vueindex ddfffa182d..358d8e9065 100644--- a/apps/desktop/src/components/editor/AiAssistant.vue+++ b/apps/desktop/src/components/editor/AiAssistant.vue@@ -3,7 +3,7 @@ import { computed, defineAsyncComponent, h, nextTick, onMounted, onUnmounted, reimport { uuid } from "@/lib/common/utils";import { useI18n } from "vue-i18n";import { translateBackendError } from "@/i18n/backend-errors";-import { deferUntilPanelResizeEnd } from "@/lib/app/panelResizeState";+import { deferUntilPanelResizeEnd, isPanelResizing } from "@/lib/app/panelResizeState";import {ArrowDown,ArrowUp,@@ -1228,19 +1228,27 @@ const pendingCompaction = ref<{ summary: string; compactedMessages: number } | nconst AI_TEXTAREA_MIN_HEIGHT_PX = 64;const AI_TEXTAREA_MAX_PANEL_RATIO = 0.5;const AI_TEXTAREA_HEIGHT_STORAGE_KEY = "dbx-ai-textarea-height";+const AI_RESPONSIVE_DRAG_MEASURE_STEP_PX = 16;const textareaHeight = ref<number>(AI_TEXTAREA_MIN_HEIGHT_PX);const assistantRootRef = ref<HTMLElement | null>(null);const promptPanelRef = ref<HTMLElement | null>(null);const compactContextControls = ref(false);-const compactActionControls = ref(false);+const compactModelControl = ref(false);+const compactModeActionControl = ref(false);const isResizing = ref<boolean>(false);let resizeStartY = 0;let resizeStartHeight = 0;let promptPanelResizeObserver: ResizeObserver | undefined;let responsiveControlMeasureFrame: number | null = null;let responsiveControlMeasureForce = false;+let responsiveControlObservedWidth: number | null = null;let lastResponsiveControlWidth: number | null = null;+let latestResponsiveControlDragWidth: number | null = null;+let lastResponsiveControlDragMeasureWidth: number | null = null;+let responsiveControlDragMeasureRunning = false;+let responsiveControlDragMeasureQueued = false;+let responsiveControlDragEpoch = 0;interface AiTableMentionCandidate {kind: "table";@@ -5130,11 +5138,11 @@ onMounted(async () => {appearance: () => aiCodeAppearance.value,}).catch(() => undefined);- window.addEventListener("resize", handlePanelResize);+ window.addEventListener("resize", handleWindowResize);document.addEventListener("dbx:tauri-file-drop", onTauriFileDrop as EventListener);window.addEventListener(DBX_TABLE_REFERENCE_DROP_EVENT, onTableReferenceDropEvent);if (typeof ResizeObserver !== "undefined" && assistantRootRef.value) {- promptPanelResizeObserver = new ResizeObserver(handlePanelResize);+ promptPanelResizeObserver = new ResizeObserver(handleObservedPanelResize);promptPanelResizeObserver.observe(assistantRootRef.value);if (promptPanelRef.value) promptPanelResizeObserver.observe(promptPanelRef.value);}@@ -5153,9 +5161,24 @@ function clampTextareaHeight(height: number) {return Math.max(AI_TEXTAREA_MIN_HEIGHT_PX, Math.min(maxTextareaHeight(), Math.round(height)));}-function handlePanelResize() {+function handleWindowResize() {+ handlePanelResize();+}++function handleObservedPanelResize(entries: ResizeObserverEntry[]) {+ const promptPanel = promptPanelRef.value;+ const promptPanelEntry = promptPanel ? entries.find((entry) => entry.target === promptPanel) : undefined;+ handlePanelResize(promptPanelEntry?.contentRect.width);+}++function handlePanelResize(observedPanelWidth?: number) {+ if (isPanelResizing.value) {+ deferUntilPanelResizeEnd(resyncPromptPanelAfterPanelResize);+ if (typeof observedPanelWidth === "number") scheduleResponsiveControlDragMeasurement(observedPanelWidth);+ return;+ }textareaHeight.value = clampTextareaHeight(textareaHeight.value);- scheduleResponsiveControlMeasurement();+ scheduleResponsiveControlMeasurement(false, observedPanelWidth);}function hasHorizontalOverflow(element: HTMLElement | null): boolean {@@ -5167,48 +5190,99 @@ function hasOverflowingLabel(element: HTMLElement | null, selector: string): booreturn Array.from(element.querySelectorAll<HTMLElement>(selector)).some((label) => label.scrollWidth > label.clientWidth + 1);}-async function measureResponsiveControls(force = false) {- const panel = promptPanelRef.value;- if (!panel) return;- // Reading clientWidth/scrollWidth here forces a document-wide synchronous- // relayout, and the AI panel divider drag fires resize events every frame.- // Skip measurements while the drag is in flight and re-measure once at the end.- if (- deferUntilPanelResizeEnd(() => {- void measureResponsiveControls(force);- })- )- return;- const panelWidth = panel.clientWidth;+function actionControlsOverflow(actionRow: HTMLElement | null): boolean {+ return hasHorizontalOverflow(actionRow) || hasOverflowingLabel(actionRow, ".ai-mode-action-label, .ai-model-selector-label, .ai-prompt-queue-label");+}++function resyncPromptPanelAfterPanelResize() {+ responsiveControlDragEpoch += 1;+ latestResponsiveControlDragWidth = null;+ lastResponsiveControlDragMeasureWidth = null;+ responsiveControlDragMeasureQueued = false;+ if (!assistantViewMounted) return;+ textareaHeight.value = clampTextareaHeight(textareaHeight.value);+ scheduleResponsiveControlMeasurement(true);+}++async function applyResponsiveControlMeasurement(panel: HTMLElement, panelWidth: number, force: boolean, panelResizeEpoch?: number) {if (!force && lastResponsiveControlWidth === panelWidth) return;- // Measure the full labels before deciding to compact. This lets a wide- // composer recover from icon mode after it grows, while the actual- // overflow checks decide independently for the context and action rows.- if (compactContextControls.value || compactActionControls.value) {+ if (compactContextControls.value || compactModelControl.value || compactModeActionControl.value) {compactContextControls.value = false;- compactActionControls.value = false;+ compactModelControl.value = false;+ compactModeActionControl.value = false;await nextTick();+ if (panelResizeEpoch !== undefined && (!isPanelResizing.value || panelResizeEpoch !== responsiveControlDragEpoch)) return;}const contextRow = panel.querySelector<HTMLElement>("[data-ai-composer-context-row]");const actionRow = panel.querySelector<HTMLElement>("[data-ai-composer-actions]");const contextOverflow = hasHorizontalOverflow(contextRow) || hasOverflowingLabel(contextRow, ".ai-template-selector-label, .ai-skills-selector-label");- const actionOverflow = hasHorizontalOverflow(actionRow) || hasOverflowingLabel(actionRow, ".ai-mode-action-label, .ai-model-selector-label, .ai-prompt-queue-label");compactContextControls.value = contextOverflow;- compactActionControls.value = actionOverflow;- lastResponsiveControlWidth = panelWidth;+ if (actionControlsOverflow(actionRow)) {+ compactModelControl.value = true;+ await nextTick();+ if (panelResizeEpoch !== undefined && (!isPanelResizing.value || panelResizeEpoch !== responsiveControlDragEpoch)) return;+ compactModeActionControl.value = actionControlsOverflow(actionRow);+ }+ lastResponsiveControlWidth = panelResizeEpoch === undefined ? panelWidth : (latestResponsiveControlDragWidth ?? panelWidth);}-function scheduleResponsiveControlMeasurement(force = false) {+async function flushResponsiveControlDragMeasurements() {+ if (responsiveControlDragMeasureRunning) return;+ responsiveControlDragMeasureRunning = true;+ const panelResizeEpoch = responsiveControlDragEpoch;+ try {+ while (responsiveControlDragMeasureQueued && isPanelResizing.value && panelResizeEpoch === responsiveControlDragEpoch) {+ responsiveControlDragMeasureQueued = false;+ const panelWidth = latestResponsiveControlDragWidth;+ const panel = promptPanelRef.value;+ if (panelWidth === null || !panel) continue;+ if (lastResponsiveControlDragMeasureWidth !== null && Math.abs(panelWidth - lastResponsiveControlDragMeasureWidth) < AI_RESPONSIVE_DRAG_MEASURE_STEP_PX) continue;+ lastResponsiveControlDragMeasureWidth = panelWidth;+ await applyResponsiveControlMeasurement(panel, panelWidth, true, panelResizeEpoch);+ const latestWidth = latestResponsiveControlDragWidth;+ if (latestWidth !== null && Math.abs(latestWidth - panelWidth) >= AI_RESPONSIVE_DRAG_MEASURE_STEP_PX) responsiveControlDragMeasureQueued = true;+ }+ } finally {+ responsiveControlDragMeasureRunning = false;+ if (responsiveControlDragMeasureQueued && isPanelResizing.value) void flushResponsiveControlDragMeasurements();+ }+}++function scheduleResponsiveControlDragMeasurement(observedPanelWidth: number) {+ latestResponsiveControlDragWidth = Math.round(observedPanelWidth);+ responsiveControlDragMeasureQueued = true;+ void flushResponsiveControlDragMeasurements();+}++async function measureResponsiveControls(force = false, observedPanelWidth?: number) {+ const panel = promptPanelRef.value;+ if (!panel) return;++ if (isPanelResizing.value) {+ deferUntilPanelResizeEnd(resyncPromptPanelAfterPanelResize);+ if (typeof observedPanelWidth === "number") scheduleResponsiveControlDragMeasurement(observedPanelWidth);+ return;+ }++ lastResponsiveControlDragMeasureWidth = null;+ const panelWidth = typeof observedPanelWidth === "number" ? Math.round(observedPanelWidth) : panel.clientWidth;+ await applyResponsiveControlMeasurement(panel, panelWidth, force);+}++function scheduleResponsiveControlMeasurement(force = false, observedPanelWidth?: number) {responsiveControlMeasureForce ||= force;+ if (typeof observedPanelWidth === "number") responsiveControlObservedWidth = observedPanelWidth;if (responsiveControlMeasureFrame !== null) return;const measure = () => {responsiveControlMeasureFrame = null;const forceMeasure = responsiveControlMeasureForce;+ const measuredPanelWidth = responsiveControlObservedWidth;responsiveControlMeasureForce = false;- void measureResponsiveControls(forceMeasure);+ responsiveControlObservedWidth = null;+ void measureResponsiveControls(forceMeasure, measuredPanelWidth ?? undefined);};if (typeof window !== "undefined" && typeof window.requestAnimationFrame === "function") {responsiveControlMeasureFrame = window.requestAnimationFrame(measure);@@ -5296,7 +5370,7 @@ onUnmounted(() => {// 若卸载时仍在拖拽,复位 body 样式,避免全局残留document.body.style.userSelect = "";document.body.style.cursor = "";- window.removeEventListener("resize", handlePanelResize);+ window.removeEventListener("resize", handleWindowResize);document.removeEventListener("dbx:tauri-file-drop", onTauriFileDrop as EventListener);window.removeEventListener(DBX_TABLE_REFERENCE_DROP_EVENT, onTableReferenceDropEvent);promptPanelResizeObserver?.disconnect();@@ -5305,6 +5379,11 @@ onUnmounted(() => {responsiveControlMeasureFrame = null;}responsiveControlMeasureForce = false;+ responsiveControlObservedWidth = null;+ latestResponsiveControlDragWidth = null;+ lastResponsiveControlDragMeasureWidth = null;+ responsiveControlDragMeasureQueued = false;+ responsiveControlDragEpoch += 1;});function triggerAction(action: AiAction, instruction?: string) {@@ -6354,7 +6433,7 @@ async function openExternalUrl(url: string) {<Clock class="h-3.5 w-3.5 shrink-0" /><span>{{ t("ai.status.longRunningHint") }}</span></div>- <div data-ai-composer-actions :class="['ai-prompt-action-row flex min-w-0 flex-nowrap items-center gap-1.5 overflow-hidden', compactActionControls && 'ai-prompt-action-row--compact']">+ <div data-ai-composer-actions :class="['ai-prompt-action-row flex min-w-0 flex-nowrap items-center gap-1.5 overflow-hidden', compactModelControl && 'ai-prompt-action-row--model-compact', compactModeActionControl && 'ai-prompt-action-row--mode-compact']"><Tooltip><TooltipTrigger as-child><Button variant="ghost" size="icon" class="h-7 w-7 shrink-0" :disabled="isGenerating" @click="selectCsvFile">@@ -6706,13 +6785,13 @@ async function openExternalUrl(url: string) {display: none;}-.ai-prompt-action-row--compact {+.ai-prompt-action-row--mode-compact {gap: 0.25rem;}-.ai-prompt-action-row--compact .ai-mode-action-trigger,-.ai-prompt-action-row--compact .ai-mode-static-trigger,-.ai-prompt-action-row--compact .ai-model-selector-trigger {+.ai-prompt-action-row--model-compact .ai-model-selector-trigger,+.ai-prompt-action-row--mode-compact .ai-mode-action-trigger,+.ai-prompt-action-row--mode-compact .ai-mode-static-trigger {flex: 0 0 1.75rem;width: 1.75rem;max-width: 1.75rem;@@ -6721,29 +6800,29 @@ async function openExternalUrl(url: string) {padding: 0;}-.ai-prompt-action-row--compact .ai-mode-action-label,-.ai-prompt-action-row--compact .ai-mode-action-chevron,-.ai-prompt-action-row--compact .ai-model-selector-label,-.ai-prompt-action-row--compact .ai-model-selector-chevron {+.ai-prompt-action-row--model-compact .ai-model-selector-label,+.ai-prompt-action-row--model-compact .ai-model-selector-chevron,+.ai-prompt-action-row--mode-compact .ai-mode-action-label,+.ai-prompt-action-row--mode-compact .ai-mode-action-chevron {display: none;}-.ai-prompt-action-row--compact .ai-model-selector-trigger {+.ai-prompt-action-row--model-compact .ai-model-selector-trigger {min-width: 1.75rem;}-.ai-prompt-action-row--compact .ai-prompt-send-control {+.ai-prompt-action-row--mode-compact .ai-prompt-send-control {flex: 0 0 auto;}-.ai-prompt-action-row--compact .ai-prompt-queue-control {+.ai-prompt-action-row--mode-compact .ai-prompt-queue-control {width: 1.75rem;height: 1.75rem;justify-content: center;padding: 0;}-.ai-prompt-action-row--compact .ai-prompt-queue-label {+.ai-prompt-action-row--mode-compact .ai-prompt-queue-label {display: none;}@@ -6905,19 +6984,4 @@ html.dbx-legacy-webview.dark .ai-markdown :deep(.ai-markdown-table-wrap:hover::-height: 9px;cursor: ns-resize;}--.resize-handle::before {- content: "";- position: absolute;- top: 3px;- left: 0;- right: 0;- height: 1px;- background-color: var(--border);- transition: background-color 0.15s ease;-}--.resize-handle:hover::before {- background-color: color-mix(in srgb, var(--foreground) 20%, transparent);-}</style>diff --git a/apps/desktop/src/components/editor/__tests__/AiAssistant.mount.spec.ts b/apps/desktop/src/components/editor/__tests__/AiAssistant.mount.spec.tsindex 9773468b28..258cc59450 100644--- a/apps/desktop/src/components/editor/__tests__/AiAssistant.mount.spec.ts+++ b/apps/desktop/src/components/editor/__tests__/AiAssistant.mount.spec.ts@@ -11,6 +11,7 @@ import { createPinia } from "pinia";import i18n from "@/i18n";import { TooltipProvider } from "@/components/ui/tooltip";import AiAssistant from "@/components/editor/AiAssistant.vue";+import { beginPanelResize, endPanelResize } from "@/lib/app/panelResizeState";import { useSettingsStore } from "@/stores/settingsStore";import { useConnectionStore } from "@/stores/connectionStore";import type { ConnectionConfig } from "@/types/database";@@ -53,6 +54,8 @@ vi.mock("@/lib/backend/api", async (importOriginal) => {const cleanups: Array<() => void> = [];afterEach(() => {+ endPanelResize();+ vi.unstubAllGlobals();aiAssistantMountApi.conversations = [];aiAssistantMountApi.runAgentStream = undefined;while (cleanups.length) cleanups.pop()?.();@@ -256,6 +259,102 @@ describe("AiAssistant mount", () => {expect(modelTrigger?.getAttribute("title")).toBe("deepseek-chat");});+ it("progressively compacts and expands composer controls while the AI panel is dragged", async () => {+ let resizeObserverCallback: ResizeObserverCallback | undefined;+ let resizeObserver: ResizeObserver | undefined;+ vi.stubGlobal(+ "ResizeObserver",+ class {+ constructor(callback: ResizeObserverCallback) {+ resizeObserverCallback = callback;+ resizeObserver = this as unknown as ResizeObserver;+ }++ observe() {}+ unobserve() {}+ disconnect() {}+ },+ );++ const { errors, container } = await mountPanel(true, undefined, (settings) => {+ settings.aiConfigs = [+ {+ id: "deepseek-default",+ name: "DeepSeek",+ provider: "deepseek",+ apiKey: "test-key",+ authMethod: "api-key",+ endpoint: "https://api.deepseek.com",+ model: "deepseek-chat",+ apiStyle: "completions",+ isDefault: true,+ },+ ];+ settings.activeModel = { configId: "deepseek-default", modelId: "deepseek-chat" };+ });++ const panel = container.querySelector<HTMLElement>(".ai-prompt-context-container")!;+ const contextRow = container.querySelector<HTMLElement>("[data-ai-composer-context-row]")!;+ const actionRow = container.querySelector<HTMLElement>("[data-ai-composer-actions]")!;+ let panelWidth = 300;+ let contextClientWidth = 280;+ let contextScrollWidth = 320;+ let actionClientWidth = 280;+ let actionFullScrollWidth = 320;+ let actionModelCompactScrollWidth = 280;+ Object.defineProperty(panel, "clientWidth", { configurable: true, get: () => panelWidth });+ Object.defineProperty(contextRow, "clientWidth", { configurable: true, get: () => contextClientWidth });+ Object.defineProperty(contextRow, "scrollWidth", { configurable: true, get: () => contextScrollWidth });+ Object.defineProperty(actionRow, "clientWidth", { configurable: true, get: () => actionClientWidth });+ Object.defineProperty(actionRow, "scrollWidth", {+ configurable: true,+ get: () => (actionRow.classList.contains("ai-prompt-action-row--model-compact") ? actionModelCompactScrollWidth : actionFullScrollWidth),+ });++ beginPanelResize();+ resizeObserverCallback?.([{ target: panel, contentRect: { width: panelWidth } } as ResizeObserverEntry], resizeObserver!);+ await new Promise((resolve) => setTimeout(resolve, 20));++ expect(contextRow.classList.contains("ai-prompt-context-row--compact")).toBe(true);+ expect(actionRow.classList.contains("ai-prompt-action-row--model-compact")).toBe(true);+ expect(actionRow.classList.contains("ai-prompt-action-row--mode-compact")).toBe(false);++ panelWidth = 240;+ actionClientWidth = 220;+ actionModelCompactScrollWidth = 250;+ resizeObserverCallback?.([{ target: panel, contentRect: { width: panelWidth } } as ResizeObserverEntry], resizeObserver!);+ await new Promise((resolve) => setTimeout(resolve, 20));+ expect(actionRow.classList.contains("ai-prompt-action-row--model-compact")).toBe(true);+ expect(actionRow.classList.contains("ai-prompt-action-row--mode-compact")).toBe(true);++ panelWidth = 300;+ actionClientWidth = 280;+ actionModelCompactScrollWidth = 280;+ resizeObserverCallback?.([{ target: panel, contentRect: { width: panelWidth } } as ResizeObserverEntry], resizeObserver!);+ await new Promise((resolve) => setTimeout(resolve, 20));+ expect(actionRow.classList.contains("ai-prompt-action-row--model-compact")).toBe(true);+ expect(actionRow.classList.contains("ai-prompt-action-row--mode-compact")).toBe(false);++ panelWidth = 420;+ contextClientWidth = 400;+ contextScrollWidth = 400;+ actionClientWidth = 400;+ actionFullScrollWidth = 400;+ actionModelCompactScrollWidth = 400;+ resizeObserverCallback?.([{ target: panel, contentRect: { width: panelWidth } } as ResizeObserverEntry], resizeObserver!);+ await new Promise((resolve) => setTimeout(resolve, 20));+ expect(contextRow.classList.contains("ai-prompt-context-row--compact")).toBe(false);+ expect(actionRow.classList.contains("ai-prompt-action-row--model-compact")).toBe(false);+ expect(actionRow.classList.contains("ai-prompt-action-row--mode-compact")).toBe(false);++ endPanelResize();+ await new Promise((resolve) => setTimeout(resolve, 20));+ expect(contextRow.classList.contains("ai-prompt-context-row--compact")).toBe(false);+ expect(actionRow.classList.contains("ai-prompt-action-row--model-compact")).toBe(false);+ expect(actionRow.classList.contains("ai-prompt-action-row--mode-compact")).toBe(false);+ expect(errors.map(String)).toEqual([]);+ });+it.each(["plugin", "etcd"] as const)("hides database and schema selectors for %s connections", async (dbType) => {const { errors, container } = await mountPanel(true, { id: "connection", name: "Connection", db_type: dbType, plugin_id: dbType === "plugin" ? "sample.plugin" : undefined, host: "localhost", port: 22, username: "", password: "" });expect(errors.map(String)).toEqual([]);