feat(runtime): 同步前端状态到 agent runtime

- 新增 snapshot 构造 helper 和 agent runtime store

- 同步 active tab、连接、库、schema、SQL、选中 SQL、表格选择和结果采样

- 补充 snapshot payload 组装测试
This commit is contained in:
Illuminated2020
2026-05-12 16:51:34 +08:00
parent feff43c459
commit c144330d79
9 changed files with 271 additions and 3 deletions
+28 -2
View File
@@ -62,9 +62,17 @@ import type { QueryResult, ColumnInfo, DatabaseType } from "@/types/database";
import * as api from "@/lib/api";
import { buildTableSelectSql, quoteTableIdentifier } from "@/lib/tableSelectSql";
import { isHiddenGridColumn, usesSyntheticRowIdKey } from "@/lib/tableEditing";
import { formatGridSqlLiteral } from "@/lib/dataGridSql";
import { matchesRowStatusFilter, type RowStatus, type RowStatusFilter } from "@/lib/gridRowStatus";
import { displayCellValue, type CellValue } from "@/lib/cellValue";
import { buildDataGridSaveStatements, formatGridSqlLiteral } from "@/lib/dataGridSql";
import { formatMarkdownTable } from "@/lib/markdownTable";
import { buildXlsxWorkbook } from "@/lib/xlsxExport";
import {
matchesRowStatusFilter,
rowStatusFilterAfterAddingRow,
type RowStatus,
type RowStatusFilter,
} from "@/lib/gridRowStatus";
import { useAgentRuntimeStore } from "@/stores/agentRuntimeStore";
import { useToast } from "@/composables/useToast";
import { useDataGridExport } from "@/composables/useDataGridExport";
@@ -74,6 +82,7 @@ import { useDataGridEditor } from "@/composables/useDataGridEditor";
const { t } = useI18n();
const { toast } = useToast();
const agentRuntimeStore = useAgentRuntimeStore();
const props = defineProps<{
result: QueryResult;
@@ -1090,6 +1099,22 @@ const activeCellDetail = computed(() => {
const detailEditValue = ref("");
const isEditingDetail = ref(false);
watch(
selectedCells,
(data) => {
agentRuntimeStore.setSelection(
selectedCellCount.value > 0
? {
type: "grid-cells",
range: selectedRange.value,
data,
}
: { type: "none" },
);
},
{ deep: true },
);
function startDetailEdit() {
const detail = activeCellDetail.value;
if (!detail || !detail.isEditable) return;
@@ -1611,6 +1636,7 @@ watch(
onUnmounted(() => {
cleanupFrames();
agentRuntimeStore.setSelection({ type: "none" });
onDdlResizeEnd();
finishCellSelection();
clearTimeout(_searchTimer);