Files
worldwideview/src/core/plugins/layerActivation.ts
T
Antigravity AI ad5e7c7576 fix(globe): load plugin data when an agent toggles a layer via MCP
The toggle_layer MCP command only flipped the Zustand UI switch via the
command bridge and never started the plugin data lifecycle, so an
agent-enabled layer showed as toggled but rendered no data.

Extract the shared setLayerActive() helper (src/core/plugins/layerActivation.ts)
that drives pluginManager.enablePlugin/disablePlugin plus store state, and
route both the UI click (LayerPanel) and the agent command bridge
(useGlobeCommandBridge) through it so agent toggles trigger the identical
data fetch/stream path. Verified live: an MCP toggle_layer(camera) loads
2,376 camera entities with no browser interaction.

Patch: behavior fix, no API change.
2026-06-03 12:15:39 +12:00

30 lines
1.1 KiB
TypeScript

import { pluginManager } from "@/core/plugins/PluginManager";
import { useStore } from "@/core/state/store";
/**
* Single source of truth for activating or deactivating a plugin layer's data lifecycle.
* Shared by the UI (LayerPanel) and the agent command bridge (useGlobeCommandBridge)
* so both paths trigger identical data loading and entity cleanup behaviour.
*
* UI-panel-only concerns (highlight layer, open config panel, active config tab,
* analytics) are NOT handled here -- they stay in LayerPanel.
*/
export function setLayerActive(pluginId: string, enabled: boolean): void {
const store = useStore.getState();
if (enabled) {
void pluginManager.enablePlugin(pluginId);
store.setLayerEnabled(pluginId, true);
} else {
pluginManager.disablePlugin(pluginId);
store.setLayerEnabled(pluginId, false);
store.clearEntities(pluginId);
store.setEntityCount(pluginId, 0);
if (store.hoveredEntity?.pluginId === pluginId) {
store.setHoveredEntity(null, null);
}
if (store.selectedEntity?.pluginId === pluginId) {
store.setSelectedEntity(null);
}
}
}