first commit
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
plugins { id("java-library-conventions") }
|
||||
dependencies {
|
||||
api(project(":gateway-module-tool-registry:tool-registry-contract-subjects"))
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package net.bquarkz.ai.gateway.tools.api;
|
||||
|
||||
import net.bquarkz.ai.gateway.tools.contracts.ToolDefinition;
|
||||
import net.bquarkz.ai.gateway.tools.contracts.ToolProvider;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface ToolRegistry {
|
||||
Optional<ToolProvider> findTool(String name);
|
||||
List<ToolDefinition> listTools();
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
plugins { id("java-library-conventions") }
|
||||
dependencies { implementation(project(":main-infrastructure")) }
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package net.bquarkz.ai.gateway.tools.contracts;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Value;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Value
|
||||
@Builder
|
||||
public class ToolDefinition {
|
||||
String name;
|
||||
String description;
|
||||
List<String> actions;
|
||||
Map<String, Object> inputSchema;
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package net.bquarkz.ai.gateway.tools.contracts;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ToolProvider {
|
||||
String getName();
|
||||
String getDescription();
|
||||
List<String> getActions();
|
||||
Map<String, Object> getInputSchema();
|
||||
Map<String, Object> execute(String action, Map<String, Object> arguments);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
plugins { id("java-library-conventions") }
|
||||
dependencies {
|
||||
implementation(project(":gateway-module-tool-registry:tool-registry-api"))
|
||||
implementation("org.springframework.boot:spring-boot-starter")
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package net.bquarkz.ai.gateway.tools.domain;
|
||||
|
||||
import net.bquarkz.ai.gateway.tools.api.ToolRegistry;
|
||||
import net.bquarkz.ai.gateway.tools.contracts.ToolDefinition;
|
||||
import net.bquarkz.ai.gateway.tools.contracts.ToolProvider;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class ToolRegistryImpl implements ToolRegistry {
|
||||
private final Map<String, ToolProvider> tools;
|
||||
|
||||
public ToolRegistryImpl(List<ToolProvider> providers) {
|
||||
this.tools = providers.stream()
|
||||
.collect(Collectors.toMap(ToolProvider::getName, Function.identity()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ToolProvider> findTool(String name) {
|
||||
return Optional.ofNullable(tools.get(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ToolDefinition> listTools() {
|
||||
return tools.values().stream()
|
||||
.map(p -> ToolDefinition.builder()
|
||||
.name(p.getName())
|
||||
.description(p.getDescription())
|
||||
.actions(p.getActions())
|
||||
.inputSchema(p.getInputSchema())
|
||||
.build())
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user