mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-27 15:39:47 +00:00
Enhance plugin loading by making the plugin path optional
This commit is contained in:
parent
85c93cea43
commit
6df07dd56b
@ -101,16 +101,18 @@ public static partial class PluginFactory
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<PluginBase> Load(string pluginPath, string code, CancellationToken cancellationToken = default)
|
||||
public static async Task<PluginBase> Load(string? pluginPath, string code, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if(ForbiddenPlugins.Check(code) is { IsForbidden: true } forbiddenState)
|
||||
return new NoPlugin($"This plugin is forbidden: {forbiddenState.Message}");
|
||||
|
||||
var state = LuaState.Create();
|
||||
|
||||
// Add the module loader so that the plugin can load other Lua modules:
|
||||
state.ModuleLoader = new PluginLoader(pluginPath);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(pluginPath))
|
||||
{
|
||||
// Add the module loader so that the plugin can load other Lua modules:
|
||||
state.ModuleLoader = new PluginLoader(pluginPath);
|
||||
}
|
||||
|
||||
// Add some useful libraries:
|
||||
state.OpenModuleLibrary();
|
||||
state.OpenStringLibrary();
|
||||
@ -141,7 +143,7 @@ public static partial class PluginFactory
|
||||
if(type is PluginType.NONE)
|
||||
return new NoPlugin($"TYPE is not a valid plugin type. Valid types are: {CommonTools.GetAllEnumValues<PluginType>()}");
|
||||
|
||||
var isInternal = pluginPath.StartsWith(INTERNAL_PLUGINS_ROOT, StringComparison.OrdinalIgnoreCase);
|
||||
var isInternal = !string.IsNullOrWhiteSpace(pluginPath) && pluginPath.StartsWith(INTERNAL_PLUGINS_ROOT, StringComparison.OrdinalIgnoreCase);
|
||||
return type switch
|
||||
{
|
||||
PluginType.LANGUAGE => new PluginLanguage(isInternal, state, type),
|
||||
|
Loading…
Reference in New Issue
Block a user