50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
/**
|
|
* Macro System
|
|
* Generic plugin-based macro processor
|
|
*/
|
|
|
|
class MacroPlugin {
|
|
/**
|
|
* Base class for macro plugins
|
|
* Subclass and implement these methods:
|
|
* - canHandle(actor, method): boolean
|
|
* - process(macro, context): Promise<{ success, content, error }>
|
|
*/
|
|
|
|
canHandle(actor, method) {
|
|
throw new Error('Must implement canHandle()');
|
|
}
|
|
|
|
async process(macro, context) {
|
|
throw new Error('Must implement process()');
|
|
}
|
|
}
|
|
|
|
class MacroRegistry {
|
|
constructor() {
|
|
this.plugins = new Map();
|
|
console.log('[MacroRegistry] Initializing macro registry');
|
|
}
|
|
|
|
register(actor, method, plugin) {
|
|
const key = `${actor}.${method}`;
|
|
this.plugins.set(key, plugin);
|
|
console.log(`[MacroRegistry] Registered plugin: ${key}`);
|
|
}
|
|
|
|
resolve(actor, method) {
|
|
// Try exact match
|
|
let key = `${actor}.${method}`;
|
|
if (this.plugins.has(key)) {
|
|
console.log(`[MacroRegistry] Found plugin: ${key}`);
|
|
return this.plugins.get(key);
|
|
}
|
|
|
|
// No plugin found
|
|
console.warn(`[MacroRegistry] No plugin found for: ${key}`);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
window.MacroRegistry = MacroRegistry;
|
|
window.MacroPlugin = MacroPlugin; |