mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-06-16 03:29:55 +08:00
102 lines
4.1 KiB
TypeScript
102 lines
4.1 KiB
TypeScript
import { DBGetAllColumns, DBGetDatabases, DBGetTables } from '../../../wailsjs/go/app/App';
|
|
|
|
import type { AISnapshotInspectionRuntime } from './aiSnapshotInspectionToolExecutor';
|
|
|
|
export interface AIToolContextEntry {
|
|
connectionId: string;
|
|
dbName: string;
|
|
tables: string[];
|
|
}
|
|
|
|
export interface AILocalToolRuntime extends AISnapshotInspectionRuntime {
|
|
getDatabases: (config: any) => Promise<any>;
|
|
getTables: (config: any, dbName: string) => Promise<any>;
|
|
getAllColumns: (config: any, dbName: string) => Promise<any>;
|
|
getColumns: (config: any, dbName: string, tableName: string) => Promise<any>;
|
|
getIndexes: (config: any, dbName: string, tableName: string) => Promise<any>;
|
|
getForeignKeys: (config: any, dbName: string, tableName: string) => Promise<any>;
|
|
getTriggers: (config: any, dbName: string, tableName: string) => Promise<any>;
|
|
showCreateTable: (config: any, dbName: string, tableName: string) => Promise<any>;
|
|
query: (config: any, dbName: string, sql: string) => Promise<any>;
|
|
checkSQL?: (sql: string) => Promise<{ allowed?: boolean; operationType?: string } | undefined>;
|
|
callMCPTool?: (name: string, args: string) => Promise<{ content?: string; isError?: boolean } | undefined>;
|
|
}
|
|
|
|
const getAIService = () => (window as any).go?.aiservice?.Service;
|
|
|
|
export const buildDefaultLocalToolRuntime = (): AILocalToolRuntime => ({
|
|
getDatabases: DBGetDatabases,
|
|
getTables: DBGetTables,
|
|
getAllColumns: DBGetAllColumns,
|
|
getColumns: async (config, dbName, tableName) => {
|
|
const mod = await import('../../../wailsjs/go/app/App');
|
|
return mod.DBGetColumns(config, dbName, tableName);
|
|
},
|
|
getIndexes: async (config, dbName, tableName) => {
|
|
const mod = await import('../../../wailsjs/go/app/App');
|
|
return mod.DBGetIndexes(config, dbName, tableName);
|
|
},
|
|
getForeignKeys: async (config, dbName, tableName) => {
|
|
const mod = await import('../../../wailsjs/go/app/App');
|
|
return mod.DBGetForeignKeys(config, dbName, tableName);
|
|
},
|
|
getTriggers: async (config, dbName, tableName) => {
|
|
const mod = await import('../../../wailsjs/go/app/App');
|
|
return mod.DBGetTriggers(config, dbName, tableName);
|
|
},
|
|
showCreateTable: async (config, dbName, tableName) => {
|
|
const mod = await import('../../../wailsjs/go/app/App');
|
|
return mod.DBShowCreateTable(config, dbName, tableName);
|
|
},
|
|
query: async (config, dbName, sql) => {
|
|
const mod = await import('../../../wailsjs/go/app/App');
|
|
return mod.DBQuery(config, dbName, sql);
|
|
},
|
|
checkSQL: async (sql) => {
|
|
const service = getAIService();
|
|
if (typeof service?.AICheckSQL !== 'function') {
|
|
return undefined;
|
|
}
|
|
return service.AICheckSQL(sql);
|
|
},
|
|
callMCPTool: async (name, args) => {
|
|
const service = getAIService();
|
|
if (typeof service?.AICallMCPTool !== 'function') {
|
|
return undefined;
|
|
}
|
|
return service.AICallMCPTool(name, args);
|
|
},
|
|
getAIRuntimeState: async () => {
|
|
const service = getAIService();
|
|
if (!service) {
|
|
return undefined;
|
|
}
|
|
const [providers, activeProviderId, safetyLevel, contextLevel] = await Promise.all([
|
|
typeof service.AIGetProviders === 'function' ? service.AIGetProviders() : Promise.resolve([]),
|
|
typeof service.AIGetActiveProvider === 'function' ? service.AIGetActiveProvider() : Promise.resolve(''),
|
|
typeof service.AIGetSafetyLevel === 'function' ? service.AIGetSafetyLevel() : Promise.resolve(''),
|
|
typeof service.AIGetContextLevel === 'function' ? service.AIGetContextLevel() : Promise.resolve(''),
|
|
]);
|
|
return {
|
|
providers: Array.isArray(providers) ? providers : [],
|
|
activeProviderId: String(activeProviderId || '').trim(),
|
|
safetyLevel: String(safetyLevel || '').trim(),
|
|
contextLevel: String(contextLevel || '').trim(),
|
|
};
|
|
},
|
|
getMCPServers: async () => {
|
|
const service = getAIService();
|
|
if (typeof service?.AIGetMCPServers !== 'function') {
|
|
return undefined;
|
|
}
|
|
return service.AIGetMCPServers();
|
|
},
|
|
getMCPClientInstallStatuses: async () => {
|
|
const service = getAIService();
|
|
if (typeof service?.AIGetMCPClientInstallStatuses !== 'function') {
|
|
return undefined;
|
|
}
|
|
return service.AIGetMCPClientInstallStatuses();
|
|
},
|
|
});
|