feat: add explicit plugins config to control plugin auto-detection

Previously, plugins: [] still auto-detected cortex because autoDetect()
always tried importing @soulcraft/cortex regardless of config. Now:
- undefined (default): auto-detect installed plugins
- false: no plugins, skip auto-detection entirely
- []: no plugins, skip auto-detection entirely
- ['@soulcraft/cortex']: load only specified, no auto-detection

Also adds typed plugins field to BrainyConfig interface.
This commit is contained in:
David Snelling 2026-02-02 08:52:18 -08:00
parent 389e9d6258
commit 6625385913
2 changed files with 35 additions and 3 deletions

View file

@ -6438,6 +6438,8 @@ export class Brainy<T = any> implements BrainyInterface<T> {
hnsw: config?.hnsw ?? undefined as any,
// Embedding initialization - false = lazy init on first embed()
eagerEmbeddings: config?.eagerEmbeddings ?? false,
// Plugin configuration - undefined = auto-detect
plugins: config?.plugins ?? undefined as any,
// Integration Hub - undefined/false = disabled
integrations: config?.integrations ?? undefined as any
}
@ -6691,9 +6693,31 @@ export class Brainy<T = any> implements BrainyInterface<T> {
* Called internally during init().
*/
private async loadPlugins(): Promise<void> {
// Auto-detect installed plugins (e.g., @soulcraft/cortex)
const pluginPackages = (this.config as any).plugins as string[] | undefined
await this.pluginRegistry.autoDetect(pluginPackages || [])
// plugins config:
// undefined (default) → auto-detect installed plugins
// false → no plugins, skip auto-detection
// [] → no plugins, skip auto-detection
// ['@soulcraft/cortex'] → load only these, no auto-detection
const pluginConfig = this.config.plugins
if (pluginConfig === false) {
// Explicitly disabled — no plugins
} else if (Array.isArray(pluginConfig)) {
// Explicit list: only register the specified packages, no auto-detection
for (const pkg of pluginConfig) {
try {
const mod = await import(pkg)
const plugin: BrainyPlugin = mod.default || mod
if (plugin && typeof plugin.activate === 'function' && plugin.name) {
this.pluginRegistry.register(plugin)
}
} catch {
// Package not found — skip
}
}
} else {
// Default: auto-detect known plugins
await this.pluginRegistry.autoDetect()
}
// Create plugin context
const context: BrainyPluginContext = {

View file

@ -747,6 +747,14 @@ export interface BrainyConfig {
// WASM compilation to happen during container startup, not on first request
eagerEmbeddings?: boolean
// Plugin configuration
// Controls which plugins are loaded during init()
// - undefined (default): Auto-detect installed plugins (@soulcraft/cortex, etc.)
// - false: No plugins — skip auto-detection entirely
// - []: No plugins — skip auto-detection entirely
// - ['@soulcraft/cortex']: Load only specified plugins, no auto-detection
plugins?: string[] | false
// Logging configuration
verbose?: boolean // Enable verbose logging
silent?: boolean // Suppress all logging output