MCPcopy Index your code
hub / github.com/BlockRunAI/ClawRouter / deactivate

Function deactivate

src/index.ts:2185–2270  ·  view source on GitHub ↗

* Cleanup hook called when plugin is uninstalled via `openclaw plugins uninstall`. * Removes blockrun provider config, plugin entries, model allowlist entries, * and auth profiles from openclaw.json so no residual config causes errors.

(api: OpenClawPluginApi)

Source from the content-addressed store, hash-verified

2183 * and auth profiles from openclaw.json so no residual config causes errors.
2184 */
2185 deactivate(api: OpenClawPluginApi) {
2186 // 1. Stop proxy
2187 if (activeProxyHandle) {
2188 activeProxyHandle.close().catch(() => {});
2189 activeProxyHandle = null;
2190 }
2191 resetProxyStartupState();
2192
2193 // 2. Clean openclaw.json — remove provider, plugin entries, model allowlist
2194 try {
2195 const configPath = join(homedir(), ".openclaw", "openclaw.json");
2196 if (existsSync(configPath)) {
2197 const config = JSON.parse(readTextFileSync(configPath));
2198
2199 // Remove blockrun provider
2200 if (config.models?.providers?.blockrun) {
2201 delete config.models.providers.blockrun;
2202 }
2203
2204 // Remove managed BlockRun MCP server config, but preserve any user-managed override.
2205 removeManagedBlockrunMcpServerConfig(config as OpenClawConfig);
2206
2207 // Remove plugin entries (all case variants)
2208 for (const key of ["clawrouter", "ClawRouter", "@blockrun/clawrouter"]) {
2209 if (config.plugins?.entries?.[key]) delete config.plugins.entries[key];
2210 if (config.plugins?.installs?.[key]) delete config.plugins.installs[key];
2211 }
2212
2213 // Remove from plugins.allow
2214 if (Array.isArray(config.plugins?.allow)) {
2215 config.plugins.allow = config.plugins.allow.filter(
2216 (p: string) => p !== "clawrouter" && p !== "ClawRouter" && p !== "@blockrun/clawrouter",
2217 );
2218 }
2219
2220 // Remove blockrun models from allowlist
2221 if (config.agents?.defaults?.models) {
2222 for (const key of Object.keys(config.agents.defaults.models)) {
2223 if (key.startsWith("blockrun/")) delete config.agents.defaults.models[key];
2224 }
2225 }
2226
2227 // Reset default model if it's blockrun
2228 if (config.agents?.defaults?.model?.primary?.startsWith("blockrun/")) {
2229 delete config.agents.defaults.model.primary;
2230 }
2231
2232 if (config.tools?.web?.search?.provider === BLOCKRUN_EXA_PROVIDER_ID) {
2233 delete config.tools.web.search.provider;
2234 }
2235
2236 // Atomic write
2237 const tmpPath = `${configPath}.tmp.${process.pid}`;
2238 writeFileSync(tmpPath, JSON.stringify(config, null, 2));
2239 renameSync(tmpPath, configPath);
2240 api.logger.info("ClawRouter config cleaned up");
2241 }
2242 } catch (err) {

Callers

nothing calls this directly

Calls 4

resetProxyStartupStateFunction · 0.85
readTextFileSyncFunction · 0.85
closeMethod · 0.80

Tested by

no test coverage detected