MCPcopy Create free account
hub / github.com/Noumena-Network/code / setPluginEnabledOp

Function setPluginEnabledOp

src/services/plugins/pluginOperations.ts:575–750  ·  view source on GitHub ↗
(
  plugin: string,
  enabled: boolean,
  scope?: InstallableScope,
)

Source from the content-addressed store, hash-verified

573 * @returns Result indicating success/failure
574 */
575export async function setPluginEnabledOp(
576 plugin: string,
577 enabled: boolean,
578 scope?: InstallableScope,
579): Promise<PluginOperationResult> {
580 const operation = enabled ? 'enable' : 'disable'
581
582 // Built-in plugins: always use user-scope settings, bypass the normal
583 // scope-resolution + installed_plugins lookup (they're not installed).
584 if (isBuiltinPluginId(plugin)) {
585 const { error } = updateSettingsForSource('userSettings', {
586 enabledPlugins: {
587 ...getSettingsForSource('userSettings')?.enabledPlugins,
588 [plugin]: enabled,
589 },
590 })
591 if (error) {
592 return {
593 success: false,
594 message: `Failed to ${operation} built-in plugin: ${error.message}`,
595 }
596 }
597 clearAllCaches()
598 const { name: pluginName } = parsePluginIdentifier(plugin)
599 return {
600 success: true,
601 message: `Successfully ${operation}d built-in plugin: ${pluginName}`,
602 pluginId: plugin,
603 pluginName,
604 scope: 'user',
605 }
606 }
607
608 if (scope) {
609 assertInstallableScope(scope)
610 }
611
612 // ── Resolve pluginId and scope from settings ──
613 // Search across editable scopes for any mention (enabled or disabled) of
614 // this plugin. Does NOT pre-gate on installed_plugins.json.
615 let pluginId: string
616 let resolvedScope: InstallableScope
617
618 const found = findPluginInSettings(plugin)
619
620 if (scope) {
621 // Explicit scope: use it. Resolve pluginId from settings if possible,
622 // otherwise require a full plugin@marketplace identifier.
623 resolvedScope = scope
624 if (found) {
625 pluginId = found.pluginId
626 } else if (plugin.includes('@')) {
627 pluginId = plugin
628 } else {
629 return {
630 success: false,
631 message: `Plugin "${plugin}" not found in settings. Use plugin@marketplace format.`,
632 }

Callers 3

enablePluginOpFunction · 0.85
disablePluginOpFunction · 0.85
disableAllPluginsOpFunction · 0.85

Calls 14

isBuiltinPluginIdFunction · 0.85
getSettingsForSourceFunction · 0.85
clearAllCachesFunction · 0.85
parsePluginIdentifierFunction · 0.85
assertInstallableScopeFunction · 0.85
findPluginInSettingsFunction · 0.85
isPluginBlockedByPolicyFunction · 0.85
scopeToSettingSourceFunction · 0.85
getPluginEditableScopesFunction · 0.85
loadAllPluginsFunction · 0.85
findReverseDependentsFunction · 0.85

Tested by

no test coverage detected