Revert "feat(cli): add dbx-cli runtime and agent integration (#229)"

This reverts commit 58c47adef5, reversing
changes made to 3bcec8ef7f.
This commit is contained in:
t8y2
2026-05-12 17:31:54 +08:00
parent 58c47adef5
commit bf58045a28
37 changed files with 56 additions and 6679 deletions
-109
View File
@@ -1,109 +0,0 @@
import { defineStore } from "pinia";
import { computed, ref } from "vue";
import * as api from "@/lib/api";
import {
deriveHandoffDialogState,
mergeLoadedHandoffs,
updateHandoffStatus,
type AgentHandoffItem,
} from "@/lib/agentHandoff";
import { buildAgentRuntimeSnapshot, DEFAULT_RESULT_SAMPLE_LIMIT } from "@/lib/agentRuntimeSnapshot";
import { useConnectionStore } from "@/stores/connectionStore";
import { useQueryStore } from "@/stores/queryStore";
export const useAgentRuntimeStore = defineStore("agentRuntime", () => {
const selection = ref<unknown>({ type: "none" });
const selectedSql = ref("");
const handoffs = ref<AgentHandoffItem[]>([]);
const activeHandoffId = ref<string | null>(null);
const handoffDialogOpen = ref(false);
const locallyClosedHandoffIds = new Set<string>();
let timer: ReturnType<typeof setTimeout> | null = null;
const activeHandoff = computed(() => handoffs.value.find((item) => item.id === activeHandoffId.value) ?? null);
function setSelection(value: unknown) {
selection.value = value;
scheduleSync();
}
function setSelectedSql(value: string) {
selectedSql.value = value;
scheduleSync();
}
function scheduleSync() {
if (timer) clearTimeout(timer);
timer = setTimeout(() => {
timer = null;
void syncNow();
}, 100);
}
async function syncNow() {
if (!globalThis.localStorage) return;
try {
const connectionStore = useConnectionStore();
const queryStore = useQueryStore();
const snapshot = buildAgentRuntimeSnapshot({
tabs: queryStore.tabs,
activeTabId: queryStore.activeTabId,
getConnection: (connectionId) => connectionStore.getConfig(connectionId),
selectedSql: selectedSql.value,
selection: selection.value,
resultSampleLimit: DEFAULT_RESULT_SAMPLE_LIMIT,
});
await api.agentRuntimeUpdateSnapshot(snapshot);
} catch (err) {
console.debug("[DBX] Agent runtime snapshot sync skipped:", err);
}
}
async function loadHandoffs() {
const loaded = mergeLoadedHandoffs(await api.agentRuntimeLoadHandoffs(), locallyClosedHandoffIds);
handoffs.value = loaded;
const state = deriveHandoffDialogState(loaded, activeHandoffId.value);
activeHandoffId.value = state.active?.id ?? null;
handoffDialogOpen.value = state.open;
if (state.active?.status === "queued") {
await markHandoffShown(state.active.id);
}
}
async function markHandoffShown(id: string) {
handoffs.value = updateHandoffStatus(handoffs.value, id, "shown");
await api.agentRuntimeMarkHandoffShown(id);
}
async function rejectHandoff(id: string) {
await api.agentRuntimeRejectHandoff(id);
locallyClosedHandoffIds.add(id);
handoffs.value = updateHandoffStatus(handoffs.value, id, "rejected");
const state = deriveHandoffDialogState(handoffs.value, activeHandoffId.value === id ? null : activeHandoffId.value);
activeHandoffId.value = state.active?.id ?? null;
handoffDialogOpen.value = state.open;
}
function setActiveHandoff(id: string) {
activeHandoffId.value = id;
const item = handoffs.value.find((handoff) => handoff.id === id);
if (item?.status === "queued") void markHandoffShown(id);
}
return {
selection,
selectedSql,
handoffs,
activeHandoff,
handoffDialogOpen,
setSelection,
setSelectedSql,
scheduleSync,
syncNow,
loadHandoffs,
markHandoffShown,
rejectHandoff,
setActiveHandoff,
};
});
+3 -32
View File
@@ -10,31 +10,22 @@ import { analyzeEditableQuery, allPrimaryKeysPresent } from "@/lib/sqlAnalysis";
import { restoreOpenTabsState, serializeOpenTabs } from "@/lib/openTabsPersistence";
import * as api from "@/lib/api";
import { useConnectionStore } from "@/stores/connectionStore";
import { useAgentRuntimeStore } from "@/stores/agentRuntimeStore";
import { isTauriRuntime } from "@/lib/tauriRuntime";
import type { SavedSqlFile } from "@/types/database";
const STORAGE_KEY = "dbx-open-tabs";
const ACTIVE_TAB_KEY = "dbx-active-tab";
function browserStorage(): Storage | undefined {
return globalThis.localStorage;
}
function saveTabs(tabs: QueryTab[], activeTabId: string | null) {
const storage = browserStorage();
if (!storage) return;
try {
storage.setItem(STORAGE_KEY, JSON.stringify(serializeOpenTabs(tabs)));
storage.setItem(ACTIVE_TAB_KEY, activeTabId || "");
localStorage.setItem(STORAGE_KEY, JSON.stringify(serializeOpenTabs(tabs)));
localStorage.setItem(ACTIVE_TAB_KEY, activeTabId || "");
} catch {}
}
function loadSavedTabs(): { tabs: QueryTab[]; activeTabId: string | null } {
const storage = browserStorage();
if (!storage) return { tabs: [], activeTabId: null };
try {
return restoreOpenTabsState(storage.getItem(STORAGE_KEY), storage.getItem(ACTIVE_TAB_KEY), {
return restoreOpenTabsState(localStorage.getItem(STORAGE_KEY), localStorage.getItem(ACTIVE_TAB_KEY), {
queryOnly: isTauriRuntime(),
});
} catch {
@@ -81,18 +72,11 @@ export const useQueryStore = defineStore("query", () => {
return tabs.value.find((t) => t.connectionId === connectionId && t.database === database && t.title === title);
}
function scheduleAgentRuntimeSync() {
useAgentRuntimeStore().scheduleSync();
}
watch(activeTabId, () => scheduleAgentRuntimeSync());
function createTab(connectionId: string, database: string, title?: string, mode: QueryTab["mode"] = "query") {
if (title) {
const existing = findTabByTitle(connectionId, database, title);
if (existing) {
activeTabId.value = existing.id;
scheduleAgentRuntimeSync();
return existing.id;
}
}
@@ -111,7 +95,6 @@ export const useQueryStore = defineStore("query", () => {
};
tabs.value.push(tab);
activeTabId.value = id;
scheduleAgentRuntimeSync();
return id;
}
@@ -162,7 +145,6 @@ export const useQueryStore = defineStore("query", () => {
if (activeTabId.value === id) {
activeTabId.value = tabs.value[Math.min(idx, tabs.value.length - 1)]?.id ?? null;
}
scheduleAgentRuntimeSync();
}
function closeOtherTabs(id: string) {
@@ -171,7 +153,6 @@ export const useQueryStore = defineStore("query", () => {
const next = closeOtherTabsState(tabs.value, activeTabId.value, id);
tabs.value = next.tabs;
activeTabId.value = next.activeTabId;
scheduleAgentRuntimeSync();
}
function closeAllTabs() {
@@ -180,7 +161,6 @@ export const useQueryStore = defineStore("query", () => {
const next = closeAllTabsState(tabs.value, activeTabId.value);
tabs.value = next.tabs;
activeTabId.value = next.activeTabId;
scheduleAgentRuntimeSync();
}
function updateSql(id: string, sql: string) {
@@ -189,7 +169,6 @@ export const useQueryStore = defineStore("query", () => {
tab.sql = sql;
tab.resultSortedSql = undefined;
tab.resultBaseSql = undefined;
scheduleAgentRuntimeSync();
}
}
@@ -204,7 +183,6 @@ export const useQueryStore = defineStore("query", () => {
const existing = tabs.value.find((tab) => tab.savedSqlId === file.id);
if (existing) {
activeTabId.value = existing.id;
scheduleAgentRuntimeSync();
return existing.id;
}
@@ -224,7 +202,6 @@ export const useQueryStore = defineStore("query", () => {
};
tabs.value.push(tab);
activeTabId.value = id;
scheduleAgentRuntimeSync();
return id;
}
@@ -247,7 +224,6 @@ export const useQueryStore = defineStore("query", () => {
tab.resultSortedSql = undefined;
clearExplain(tab);
tab.tableMeta = undefined;
scheduleAgentRuntimeSync();
}
function updateSchema(id: string, schema: string | undefined) {
@@ -255,7 +231,6 @@ export const useQueryStore = defineStore("query", () => {
if (!tab || tab.schema === schema) return;
tab.schema = schema;
if (tab.mode === "objects") tab.objectBrowser = { ...tab.objectBrowser, schema };
scheduleAgentRuntimeSync();
}
function updateConnection(id: string, connectionId: string, database = "") {
@@ -270,7 +245,6 @@ export const useQueryStore = defineStore("query", () => {
tab.resultSortedSql = undefined;
clearExplain(tab);
tab.tableMeta = undefined;
scheduleAgentRuntimeSync();
}
function setTableMeta(id: string, meta: NonNullable<QueryTab["tableMeta"]>) {
@@ -436,7 +410,6 @@ export const useQueryStore = defineStore("query", () => {
console.info("[DBX][executeTabSql:metadata:start]", { traceId, elapsed: elapsed() });
await analyzeQueryMetadata(current, current.resultBaseSql);
console.info("[DBX][executeTabSql:metadata:done]", { traceId, elapsed: elapsed() });
scheduleAgentRuntimeSync();
} else {
console.warn("[DBX][executeTabSql:stale-result]", {
traceId,
@@ -455,7 +428,6 @@ export const useQueryStore = defineStore("query", () => {
if (current.mode !== "data") current.tableMeta = undefined;
current.resultBaseSql = options?.resultBaseSql ?? sql;
current.resultSortedSql = options?.resultSortedSql;
scheduleAgentRuntimeSync();
}
} finally {
const current = tabs.value.find((t) => t.id === id);
@@ -566,7 +538,6 @@ export const useQueryStore = defineStore("query", () => {
if (!tab?.results || index < 0 || index >= tab.results.length) return;
tab.activeResultIndex = index;
tab.result = tab.results[index];
scheduleAgentRuntimeSync();
}
function trimResultCache() {