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