-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: dynamic plugin imports #1383
base: develop
Are you sure you want to change the base?
chore: dynamic plugin imports #1383
Conversation
P.S. - seems like passed all tests, omg, nice... just noticed could do same for all client packages: if we like this change, ill do another PR for dynamic client imports too, massive optz. |
hmmm avaer told me that "alot of wrappings" I can make better abstraction for loading dynamic imports... I'll work on. Like a function for it instead. Bit complex because of all the diff conditionals / import styles / 1 is a default import. I'll see if can do nicely. |
done, now have |
Why do it like this? Why not pass a callback to loadPlugin that is |
The probably is the public api is purely string base its not type safe where as if you do callback import and you don't have the dependency installed, typescript will not compile it. |
Probably need to update Line 45 in 4c658d7
for future plugin devs |
OK yeah callback param is better, I'll update. |
changed to callback params: 2efee64 |
This doesn't work your IMO the correct approach would be something as follows.
export type DynamicPlugin = {
readonly factory: () => Promise<Plugin>;
readonly shouldInit: (character: Character) => boolean;
};
|
I see, more complex with types then I originally thought, will think about / work on, thanks for feedback. |
Actually I stand mistaken since there is a |
Few more comments.
|
(found issues in Plugin types)
OK strictly type loadPlugins with Plugin + mod style, this works and is type compliant however we now have 3 plugins not correctly typed to Plugin that were hidden found: @elizaos/plugin-solana This is bigger PR to fix all plugins now, was never type safe to begin with tbh. |
Have you run |
ah, fixed, OK everything compiling / working great. Gonna work on: 1.) export the loadPlugin function to cleanup and ready for review / testing. thanks for help! TS god |
+ new dev.sh instructions
I went big boy AAA on this one: I think this proper now. ready for review kind citizen. |
Nice PR. On the topic of plugins, I am thinking about what would be good solution in long term for plugins, as there will be hundreds of them. It makes no sense to import them all or even have them in code. I like the approach of just adding them in .json file for each character. So maybe we can have some core plugins and just contrib plugins where it can be whatever. |
If I fix the conflicts is this ready to merge? |
I fixed conflicts and added more new plugins back. Should be good for testing in dev, I didn't get chance to try every plugin, this high risk. I think it's ready for merge myself. |
true some theory crafting there, but issue is types need to be correct in build, I originally made some string solution but does not validate |
I found it perfectly suitable that char is build with .json and then we just add something like
|
got clarification, forgot Eliza is multi-agent support, understood, will handle the plugin in .json and active for all loaded characters in dynamic import style, not too bad update, coming soon. |
ready for review, let's stick to just the top of file imports being removed, not overcomplicate this, 1 for 1 these changes are an improvment, nothing different logically, plugins in character configs still do their thing. |
Relates to:
None, just looking for improvements.
Risks
HIGH - could break plugins
Background
Plugins even if unused are being always imported into the agent/index.ts at top of file.
This adds much memory usage to the JS runtime and not most efficient way to load optional plugins.
What does this PR do?
Dynamically imports plugins when needed based on ENV / secrets loaded.
What kind of change is this?
Improvements (misc. changes to existing features)
Why are we doing this? Any context or related work?
Makes Eliza faster / slimmer / less bloated / scales infinite plugins with minimal runtime overhead.
Documentation changes needed?
My changes do not require a change to the project documentation.
Testing
Try out different combinations of plugins off and on, see if loads or breaks.
Discord username
cjft