fix(coding): remediate ML-07 plugin authority

This commit is contained in:
2026-08-27 20:40:58 +08:00
parent 9407c67df2
commit cf13aa7eba
29 changed files with 1008 additions and 214 deletions

View File

@@ -44,6 +44,7 @@ export function createCodingPluginsStore(overrides: Partial<Dependencies> = {}):
removeProject: removeDataServiceProject, ...overrides,
};
const flights = new Map<string, Promise<void>>();
let loadGeneration = 0;
const operation = (key: string, run: () => Promise<void>): Promise<void> => {
const existing = flights.get(key); if (existing) return existing;
let flight: Promise<void>;
@@ -57,7 +58,11 @@ export function createCodingPluginsStore(overrides: Partial<Dependencies> = {}):
const store = createStore<CodingPluginsState>((set, get) => ({
projectId: null, projection: null, dataService: null, loadState: 'idle', error: null, pending: {},
load(projectId) {
return operation(`load:${projectId}`, async () => {
const key = `load:${projectId}`;
const existing = flights.get(key);
if (existing) return existing;
const generation = ++loadGeneration;
return operation(key, async () => {
set({ loadState: 'loading', error: null });
try {
const projection = await deps.list(projectId);
@@ -67,9 +72,13 @@ export function createCodingPluginsStore(overrides: Partial<Dependencies> = {}):
const result = await deps.inspectDataService();
if (result.success && result.data) dataService = result.data;
}
set({ projectId, projection, dataService, loadState: 'ready' });
if (generation === loadGeneration) {
set({ projectId, projection, dataService, loadState: 'ready', error: null });
}
} catch (error) {
set({ loadState: 'error', error: error instanceof Error ? error.message : String(error) });
if (generation === loadGeneration) {
set({ loadState: 'error', error: error instanceof Error ? error.message : String(error) });
}
throw error;
}
});
@@ -77,9 +86,16 @@ export function createCodingPluginsStore(overrides: Partial<Dependencies> = {}):
setEnabled(projectId, pluginId, enabled) {
return operation(`enabled:${projectId}:${pluginId}`, async () => {
const projection = await deps.setEnabled(projectId, pluginId, enabled);
let dataService = get().projectId === projectId ? get().dataService : null;
const item = projection.items.find(({ id }) => id === pluginId);
if (!enabled) {
dataService = null;
} else if (item?.settingsSurface === 'data-service' && item.backend.status === 'ready') {
const inspected = await deps.inspectDataService();
if (inspected.success && inspected.data) dataService = inspected.data;
}
set({
projectId, projection, error: null,
...(!enabled || get().projectId !== projectId ? { dataService: null } : {}),
projectId, projection, dataService, error: null,
});
});
},