Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Openclaw Openclaw EnablePluginInConfig

From Leeroopedia


enablePluginInConfig and resolveSkillConfig

enablePluginInConfig mutates the OpenClaw configuration to enable a specific plugin, handling denylist checks, per-entry updates, and allowlist management. resolveSkillConfig looks up the per-skill configuration entry for a given skill key.

Principle:Openclaw_Openclaw_Extension_Configuration

Source Location

Function File Lines
enablePluginInConfig src/plugins/enable.ts 23-47
resolveSkillConfig src/agents/skills/config.ts 48-61

Repository: github.com/openclaw/openclaw

enablePluginInConfig

Signature

export function enablePluginInConfig(
  cfg: OpenClawConfig,
  pluginId: string,
): PluginEnableResult

Parameters

Parameter Type Description
cfg OpenClawConfig The current OpenClaw configuration object.
pluginId string The ID of the plugin to enable.

Return Value

export type PluginEnableResult = {
  config: OpenClawConfig;
  enabled: boolean;
  reason?: string;
};
Field Type Description
config OpenClawConfig The (potentially updated) configuration. May be the original config if enablement failed.
enabled boolean Whether the plugin was successfully enabled.
reason string? Reason for failure when enabled === false.

Behavior

The function performs three checks in order:

  1. Global disable check. If cfg.plugins?.enabled === false, returns immediately with { enabled: false, reason: "plugins disabled" }.
  2. Denylist check. If cfg.plugins?.deny contains the pluginId, returns immediately with { enabled: false, reason: "blocked by denylist" }.
  3. Enable and allowlist. Creates an updated config with:
    • plugins.entries.<pluginId>.enabled = true (preserving any existing entry config).
    • The plugin ID added to plugins.allow (via the internal ensureAllowlisted() helper).

Full Source

export function enablePluginInConfig(cfg: OpenClawConfig, pluginId: string): PluginEnableResult {
  if (cfg.plugins?.enabled === false) {
    return { config: cfg, enabled: false, reason: "plugins disabled" };
  }
  if (cfg.plugins?.deny?.includes(pluginId)) {
    return { config: cfg, enabled: false, reason: "blocked by denylist" };
  }

  const entries = {
    ...cfg.plugins?.entries,
    [pluginId]: {
      ...(cfg.plugins?.entries?.[pluginId] as Record<string, unknown> | undefined),
      enabled: true,
    },
  };
  let next: OpenClawConfig = {
    ...cfg,
    plugins: {
      ...cfg.plugins,
      entries,
    },
  };
  next = ensureAllowlisted(next, pluginId);
  return { config: next, enabled: true };
}

Internal Helper: ensureAllowlisted

function ensureAllowlisted(cfg: OpenClawConfig, pluginId: string): OpenClawConfig {
  const allow = cfg.plugins?.allow;
  if (!Array.isArray(allow) || allow.includes(pluginId)) {
    return cfg;
  }
  return {
    ...cfg,
    plugins: {
      ...cfg.plugins,
      allow: [...allow, pluginId],
    },
  };
}

This helper ensures that when an allow list exists, the plugin ID is present in it. If there is no allow list (i.e., all plugins are eligible by default), the function is a no-op.

resolveSkillConfig

Signature

export function resolveSkillConfig(
  config: OpenClawConfig | undefined,
  skillKey: string,
): SkillConfig | undefined

Parameters

Parameter Type Description
config undefined The full OpenClaw configuration.
skillKey string The skill key to look up (either the skill name or the skillKey override from metadata).

Return Value

Returns SkillConfig | undefined. Returns undefined if the config is missing, has no skills.entries, or lacks an entry for the given key.

export type SkillConfig = {
  enabled?: boolean;
  apiKey?: string;
  env?: Record<string, string>;
  config?: Record<string, unknown>;
};

Behavior

  1. Reads config.skills.entries.
  2. If the entries map does not exist or is not an object, returns undefined.
  3. Looks up the entry for skillKey.
  4. If the entry does not exist or is not an object, returns undefined.
  5. Returns the entry.

Full Source

export function resolveSkillConfig(
  config: OpenClawConfig | undefined,
  skillKey: string,
): SkillConfig | undefined {
  const skills = config?.skills?.entries;
  if (!skills || typeof skills !== "object") {
    return undefined;
  }
  const entry = (skills as Record<string, SkillConfig | undefined>)[skillKey];
  if (!entry || typeof entry !== "object") {
    return undefined;
  }
  return entry;
}

Usage Context

  • enablePluginInConfig() is called by the CLI plugins enable command and the web UI when a user toggles a plugin on.
  • resolveSkillConfig() is called by shouldIncludeSkill() during the skill eligibility evaluation to determine if a skill is explicitly disabled or has environment/apiKey overrides.

Design Notes

Both functions are pure (no side effects):

  • enablePluginInConfig() returns a new config object via spread operators rather than mutating the input.
  • resolveSkillConfig() is a read-only lookup.

This makes them safe for use in both synchronous configuration pipelines and reactive UI state management.

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment