forked from neurodock/NeuroDock
feat(plugin): scaffold RPCP plugin loading core
- Add JarFile-based plugin.json manifest reading and validation - Implement reflection-based plugin class instantiation (Data or no-arg constructor) - Wrap Tool objects into OllamaFunctionTool with basic parameter/response handling - Implement ToolArguments storage and ToolResponse record - Extract RPCP_SOURCE constant; add plugin name validation - Update Data interface: getLoadedPlugins() returns LoadedPlugin[] - Fix launcher package references (me.zacharias.chat → me.neurodock) TODO: Extract FileSystem from JAR, populate PluginMetadata, complete OllamaFunctionArgument↔ToolArguments wrapping, invoke plugin lifecycle hooks Signed-off-by: zacharias <alienfromdia@proton.me>
This commit is contained in:
@@ -6,6 +6,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public abstract class Tool {
|
||||
/**
|
||||
* Magic constant for RPCP sources.<br>
|
||||
* This is solely here to replace the case of a magic string being used in the code
|
||||
*/
|
||||
public static final String RPCP_SOURCE = "RPCP";
|
||||
|
||||
/**
|
||||
* The parent plugin of this tool, used by {@link Tool#getToolJSON()}.
|
||||
@@ -29,7 +34,7 @@ public abstract class Tool {
|
||||
ret.put("type", "function");
|
||||
|
||||
JSONObject function = new JSONObject();
|
||||
function.put("name", String.format("%s_%s_RPCP", name(), PLUGIN.getMetadata().getName()).replaceAll(" ", "_"));
|
||||
function.put("name", String.format("%s_%s_%s", name(), PLUGIN.getMetadata().getName(), RPCP_SOURCE).replaceAll(" ", "_"));
|
||||
if(description() != null) {
|
||||
function.put("description", description());
|
||||
}
|
||||
|
||||
@@ -1,4 +1,30 @@
|
||||
package me.neurodock.plugin.tool;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
public class ToolArguments {
|
||||
Map<String, Object> arguments = new HashMap<>();
|
||||
|
||||
public void addArguments(Map<String, Object> args)
|
||||
{
|
||||
arguments.putAll(args);
|
||||
}
|
||||
|
||||
public void addArgument(String name, Object value)
|
||||
{
|
||||
arguments.put(name, value);
|
||||
}
|
||||
|
||||
public Object getArgument(String name)
|
||||
{
|
||||
if(!arguments.containsKey(name)) throw new NoSuchElementException("Trying to access missing argument");
|
||||
return arguments.get(name);
|
||||
}
|
||||
|
||||
public boolean hasArgument(String name)
|
||||
{
|
||||
return arguments.containsKey(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package me.neurodock.plugin.tool;
|
||||
|
||||
public class ToolResponse {
|
||||
public record ToolResponse(String name, String response) {
|
||||
public static ToolResponse empty(Tool tool) {
|
||||
return new ToolResponse();
|
||||
return new ToolResponse(tool.name(), "");
|
||||
}
|
||||
|
||||
public static ToolResponse empty(String toolName)
|
||||
{
|
||||
return new ToolResponse();
|
||||
return new ToolResponse(toolName, "");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user