feat(plugin): add plugin framework workflow

This commit is contained in:
t8y2 authored and GitHub committed 2026-09-13 10:39:17 +08:00
1 parent 3767f4a83b
commit b5072f1a3e
247 files changed
+33841 -2256

No files matched your search

+101 -2
View File
@@ -4,8 +4,8 @@ import { isRedisMonitorCommand, startRedisMonitor } from "@/lib/redis/redisMonit
import { uuid } from "@/lib/common/utils";
import { computed, markRaw, nextTick, onScopeDispose, reactive, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
import type { BatchSqlExecution, ConnectionConfig, DatabaseType, IndexInfo, NacosConfigEditorViewport, ObjectBrowserFilter, ObjectBrowserViewport, QueryResult, QueryResultSourceColumnRef, QueryTab, TableInfoTab, TableStructureEditorTarget } from "@/types/database";
import { sanitizeTabPageUiState } from "@/lib/tabs/tabUiState";
import type { BatchSqlExecution, ConnectionConfig, DatabaseType, IndexInfo, NacosConfigEditorViewport, ObjectBrowserFilter, ObjectBrowserViewport, QueryResult, QueryResultSourceColumnRef, QueryTab, TableInfoTab, TableStructureEditorTarget } from "@/types/database";
import { orderPinnedFirst } from "@/lib/app/pinnedItems";
import { canCancelQueryExecution } from "@/lib/sql/queryExecutionState";
import { buildExplainSql, parseExplainResult, parseDamengExplainText, parseOracleExplainText, sqlServerExplainResult, type BuildExplainSqlResult, type ExplainPlanDatabaseType } from "@/lib/diagram/explainPlan";
@@ -74,6 +74,8 @@ import { isQueryExecutionErrorResult } from "@/lib/query/queryResultError";
import { batchSqlRecoverySql, batchSqlRecoveryState, mergeBatchQueryResults, offsetBatchQueryResultIndexes, prepareBatchSqlRecovery, type BatchSqlRecoveryAction } from "@/lib/query/batchSqlRecovery";
import { decodeQueryResultArchive, encodeQueryResultArchive, type DecodedQueryResultArchive } from "@/lib/query/queryResultArchive";
import * as api from "@/lib/backend/api";
import { createFrontendPluginRegistry } from "@/lib/plugins/frontendPlugin";
import { snapshotPluginWorkbenchContext } from "@/lib/plugins/pluginData";
import { useConnectionStore } from "@/stores/connectionStore";
import { useSettingsStore } from "@/stores/settingsStore";
import { useSavedSqlStore } from "@/stores/savedSqlStore";
@@ -91,7 +93,7 @@ import { safeLocalStorageGet, safeLocalStorageRemove } from "@/lib/backend/safeS
import { sqlTextFingerprint } from "@/lib/sql/sqlTextFingerprint";
import { disposeAllSqlServerActivityTraces, disposeSqlServerActivityTrace } from "@/lib/sqlserver/sqlServerActivityTraceRuntime";
import type { SavedSqlFile } from "@/types/database";
import i18n from "@/i18n";
import i18n, { currentLocale } from "@/i18n";
import { translateBackendError } from "@/i18n/backend-errors";
import type { SqlExecutionTargetContext } from "@/lib/database/sqlExecutionTargetRegistry";
import type { DriverProfileWorkspaceScope } from "@/lib/database/driverProfileExtensions";
@@ -3145,6 +3147,100 @@ export const useQueryStore = defineStore("query", () => {
tab.nacosTargetKeyword = undefined;
}
function openPluginWorkbench(pluginId: string, contributionId: string, options: { title?: string; connectionId?: string; database?: string; context?: Record<string, unknown>; forceNew?: boolean } = {}) {
if (!options.forceNew) {
const existing = tabs.value.find((tab) => tab.mode === "plugin-workbench" && tab.pluginWorkbench?.pluginId === pluginId && tab.pluginWorkbench?.contributionId === contributionId && tab.connectionId === (options.connectionId || ""));
if (existing) {
if (options.context) existing.pluginWorkbench = { ...existing.pluginWorkbench!, context: snapshotPluginWorkbenchContext(options.context) };
switchTab(existing.id);
return existing.id;
}
}
const id = uuid();
const tab: QueryTab = {
id,
title: options.title || contributionId,
connectionId: options.connectionId || "",
database: options.database || "",
sql: "",
isExecuting: false,
isCancelling: false,
isExplaining: false,
mode: "plugin-workbench",
pluginWorkbench: {
pluginId,
contributionId,
context: options.context ? snapshotPluginWorkbenchContext(options.context) : undefined,
},
};
return registerOpenTab(tab);
}
function openPluginFilesystem(pluginId: string, providerId: string, options: { title?: string; connectionId?: string; rootUri?: string; currentUri?: string; forceNew?: boolean } = {}) {
if (!options.forceNew) {
const existing = tabs.value.find((tab) => tab.mode === "plugin-filesystem" && tab.pluginFilesystem?.pluginId === pluginId && tab.pluginFilesystem?.providerId === providerId && tab.connectionId === (options.connectionId || ""));
if (existing) {
if (options.currentUri) existing.pluginFilesystem = { ...existing.pluginFilesystem!, currentUri: options.currentUri };
switchTab(existing.id);
return existing.id;
}
}
const id = uuid();
const tab: QueryTab = {
id,
title: options.title || providerId,
connectionId: options.connectionId || "",
database: "",
sql: "",
isExecuting: false,
isCancelling: false,
isExplaining: false,
mode: "plugin-filesystem",
pluginFilesystem: {
pluginId,
providerId,
rootUri: options.rootUri,
currentUri: options.currentUri,
},
};
return registerOpenTab(tab);
}
async function openPluginConnection(connectionId: string) {
const connectionStore = useConnectionStore();
const connection = connectionStore.getConfig(connectionId);
if (!connection || connection.db_type !== "plugin") throw new Error("Plugin connection config not found");
const pluginId = connection.plugin_id;
const providerId = connection.plugin_connection_provider;
if (!pluginId || !providerId) throw new Error("Plugin connection binding is incomplete");
const registry = createFrontendPluginRegistry(await api.listPlugins(), currentLocale());
const provider = registry.listConnectionProviders().find((entry) => entry.plugin.manifest.id === pluginId && entry.contribution.id === providerId);
if (!provider) throw new Error(`Plugin connection provider '${pluginId}/${providerId}' is unavailable`);
const workbench = provider.contribution.workbench ? registry.findWorkbench(pluginId, provider.contribution.workbench) : undefined;
await connectionStore.ensureConnected(connectionId);
if (workbench) {
return openPluginWorkbench(pluginId, workbench.contribution.id, {
title: `${connection.name} · ${workbench.contribution.label}`,
connectionId,
context: {
connectionId,
providerId,
connectionType: connection.plugin_connection_type,
},
});
}
const filesystemProviderId = provider.contribution.filesystem_provider;
const filesystem = filesystemProviderId ? registry.listFilesystemProviders().find((entry) => entry.plugin.manifest.id === pluginId && entry.contribution.id === filesystemProviderId) : undefined;
if (!filesystem) throw new Error(`Plugin connection provider '${pluginId}/${providerId}' does not declare a workbench or filesystem provider`);
return openPluginFilesystem(pluginId, filesystem.contribution.id, {
title: `${connection.name} · ${filesystem.contribution.label}`,
connectionId,
rootUri: filesystem.contribution.root_uri,
});
}
function applyTableStructureInitialTab(tab: QueryTab, initialTab?: TableInfoTab, initialTarget?: TableStructureEditorTarget) {
if (!initialTab && !initialTarget?.name) return;
if (initialTab) tab.structureInitialTab = initialTab;
@@ -8088,6 +8184,9 @@ export const useQueryStore = defineStore("query", () => {
openMqttAdmin,
openNacosAdmin,
clearNacosNavigationTarget,
openPluginWorkbench,
openPluginFilesystem,
openPluginConnection,
openTableStructure,
linkSavedSql,
linkExternalSqlPath,