mirror of
https://github.com/t8y2/dbx.git
synced 2026-11-01 08:26:35 +00:00
- 新增 snapshot 构造 helper 和 agent runtime store - 同步 active tab、连接、库、schema、SQL、选中 SQL、表格选择和结果采样 - 补充 snapshot payload 组装测试
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
import { defineStore } from "pinia";
|
|
import { ref } from "vue";
|
|
import * as api from "@/lib/api";
|
|
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("");
|
|
let timer: ReturnType<typeof setTimeout> | null = 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() {
|
|
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,
|
|
});
|
|
|
|
try {
|
|
await api.agentRuntimeUpdateSnapshot(snapshot);
|
|
} catch (err) {
|
|
console.debug("[DBX] Agent runtime snapshot sync skipped:", err);
|
|
}
|
|
}
|
|
|
|
return { selection, selectedSql, setSelection, setSelectedSql, scheduleSync, syncNow };
|
|
});
|