-
Notifications
You must be signed in to change notification settings - Fork 216
Open
Description
Add the ability to extend GenAIScript's core contexts (global, host, workspace, parsers) through a plugin system, enabling users to add custom functionality without modifying core code.
Motivation
Currently, extending GenAIScript requires modifying core files or creating wrapper implementations. Users should be able to:
- Add custom workspace file parsers (e.g.,
.proto,.graphql, custom formats) - Extend the global context with project-specific utilities
- Register custom host capabilities (e.g., database connections, API clients)
- Add domain-specific tools and helpers
Proposed Solution
Allow plugins to be registered via configuration file:
{
"plugins": ["./plugins/my-plugin.js", "genaiscript-plugin-database"]
}Plugin API:
import { plugin } from "genaiscript/plugin"
export default plugin({
name: 'my-plugin',
setup(extend, options) {
extend(({ global, host, workspace, parsers }) => {
// Extend global context
global.defTask = (name, fn) => { /* ... */ }
// Add custom parsers
parsers.readProto = async (file) => { /* ... */ }
// Extend workspace
workspace.queryDatabase = async (sql) => { /* ... */ }
// Add host capabilities
host.customService = () => { /* ... */ }
})
}
})Benefits
- Modularity: Keep custom code separate from core framework
- Reusability: Share plugins across projects or publish to npm
- Type Safety: Plugins can provide TypeScript definitions
- Declarative: Clear plugin API with standardized structure
- Composable: Multiple plugins can coexist
Thoughts
- Should plugins support async initialization?
- How to handle plugin conflicts/priorities when multiple plugins extend the same context?
- Should plugins have access to all framework internals or sandboxed APIs only?
- Should there be lifecycle hooks (beforeRun, afterRun, etc.)?
Metadata
Metadata
Assignees
Labels
No labels