summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-04-01 23:14:45 +0900
committerAdam Malczewski <[email protected]>2026-04-01 23:14:45 +0900
commita57cb89b3546845e9db2fcd45e4a8f16ade09b31 (patch)
treebe3b186e8474f8cf79c464fe0fb35eca40614a64
parentcc97aeb35f8e0f61a13ee28b94355afa7c884281 (diff)
downloaddispatch-tools-interface-a57cb89b3546845e9db2fcd45e4a8f16ade09b31.tar.gz
dispatch-tools-interface-a57cb89b3546845e9db2fcd45e4a8f16ade09b31.zip
minor updatedev
-rw-r--r--.gitignore2
-rw-r--r--dispatch-tools-interface.gemspec16
-rw-r--r--lib/dispatch/tools/definition.rb8
-rw-r--r--lib/dispatch/tools/interface/version.rb2
-rw-r--r--lib/dispatch/tools/registry.rb10
-rw-r--r--spec/dispatch/tools/definition_spec.rb10
-rw-r--r--spec/dispatch/tools/registry_spec.rb28
-rw-r--r--spec/dispatch/tools/result_spec.rb20
8 files changed, 49 insertions, 47 deletions
diff --git a/.gitignore b/.gitignore
index b04a8c8..052ba26 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,5 @@
# rspec failure tracking
.rspec_status
+
+dispatch-tools-interface-*
diff --git a/dispatch-tools-interface.gemspec b/dispatch-tools-interface.gemspec
index a8bde04..570e91f 100644
--- a/dispatch-tools-interface.gemspec
+++ b/dispatch-tools-interface.gemspec
@@ -5,17 +5,17 @@ require_relative "lib/dispatch/tools/interface/version"
Gem::Specification.new do |spec|
spec.name = "dispatch-tools-interface"
spec.version = Dispatch::Tools::Interface::VERSION
- spec.authors = ["Adam Malczewski"]
- spec.email = ["[email protected]"]
+ spec.authors = [ "Adam Malczewski" ]
+ spec.email = [ "[email protected]" ]
-spec.summary = "Structured interface for defining, validating, and executing tool definitions with JSON Schema."
-spec.description = "A Ruby gem that provides a structured interface for defining, validating, and executing tool definitions. Tools are defined with JSON Schema parameter validation and organized in a registry for lookup and execution."
-spec.homepage = "https://github.com/realtradam/dispatch-tools-interface"
+ spec.summary = "Structured interface for defining, validating, and executing tool definitions with JSON Schema."
+ spec.description = "A Ruby gem that provides a structured interface for defining, validating, and executing tool definitions. Tools are defined with JSON Schema parameter validation and organized in a registry for lookup and execution."
+ spec.homepage = "https://github.com/realtradam/dispatch-tools-interface"
spec.license = "MIT"
spec.required_ruby_version = ">= 3.2.0"
-spec.metadata["allowed_push_host"] = "https://rubygems.org"
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
spec.metadata["homepage_uri"] = spec.homepage
-spec.metadata["source_code_uri"] = "https://github.com/realtradam/dispatch-tools-interface"
+ spec.metadata["source_code_uri"] = "https://github.com/realtradam/dispatch-tools-interface"
# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -28,7 +28,7 @@ spec.metadata["source_code_uri"] = "https://github.com/realtradam/dispatch-tools
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
- spec.require_paths = ["lib"]
+ spec.require_paths = [ "lib" ]
spec.add_dependency "json_schemer", "~> 2.0"
diff --git a/lib/dispatch/tools/definition.rb b/lib/dispatch/tools/definition.rb
index 2e386f0..372f0e3 100644
--- a/lib/dispatch/tools/definition.rb
+++ b/lib/dispatch/tools/definition.rb
@@ -19,9 +19,7 @@ module Dispatch
symbolized = symbolize_keys(params)
valid, errors = validate_params(params)
- unless valid
- return Result.failure(error: "Parameter validation failed: #{errors.join('; ')}")
- end
+ return Result.failure(error: "Parameter validation failed: #{errors.join("; ")}") unless valid
begin
@block.call(symbolized, context)
@@ -43,9 +41,9 @@ module Dispatch
errors = @schemer.validate(stringified).map { |err| err["error"] || err.fetch("type", "unknown error") }
if errors.empty?
- [true, []]
+ [ true, [] ]
else
- [false, errors]
+ [ false, errors ]
end
end
diff --git a/lib/dispatch/tools/interface/version.rb b/lib/dispatch/tools/interface/version.rb
index eba50bf..e016c33 100644
--- a/lib/dispatch/tools/interface/version.rb
+++ b/lib/dispatch/tools/interface/version.rb
@@ -3,7 +3,7 @@
module Dispatch
module Tools
module Interface
- VERSION = "0.1.0"
+ VERSION = "0.2.0"
end
end
end
diff --git a/lib/dispatch/tools/registry.rb b/lib/dispatch/tools/registry.rb
index e4a5d3e..571ca1b 100644
--- a/lib/dispatch/tools/registry.rb
+++ b/lib/dispatch/tools/registry.rb
@@ -10,15 +10,17 @@ module Dispatch
def register(tool_definition)
name = tool_definition.name
- if @tools.key?(name)
- raise DuplicateToolError, "Tool '#{name}' is already registered"
- end
+ raise DuplicateToolError, "Tool '#{name}' is already registered" if @tools.key?(name)
@tools[name] = tool_definition
self
end
def get(name)
+ @tools[name]
+ end
+
+ def fetch(name)
@tools.fetch(name) do
raise ToolNotFoundError, "Tool '#{name}' not found"
end
@@ -44,7 +46,7 @@ module Dispatch
new_registry = self.class.new
names.each do |name|
- new_registry.register(get(name))
+ new_registry.register(fetch(name))
end
new_registry
diff --git a/spec/dispatch/tools/definition_spec.rb b/spec/dispatch/tools/definition_spec.rb
index c9640e2..ada2012 100644
--- a/spec/dispatch/tools/definition_spec.rb
+++ b/spec/dispatch/tools/definition_spec.rb
@@ -9,7 +9,7 @@ RSpec.describe Dispatch::Tools::Definition do
start_line: { type: "integer", description: "Start line (0-based)" },
end_line: { type: "integer", description: "End line (0-based, -1 for EOF)" }
},
- required: ["path"]
+ required: [ "path" ]
}
end
@@ -171,10 +171,10 @@ RSpec.describe Dispatch::Tools::Definition do
hash = tool.to_h
expect(hash).to eq({
- name: "read_file",
- description: "Read the contents of a file",
- parameters: parameters_schema
- })
+ name: "read_file",
+ description: "Read the contents of a file",
+ parameters: parameters_schema
+ })
end
it "returns a plain hash, not a struct" do
diff --git a/spec/dispatch/tools/registry_spec.rb b/spec/dispatch/tools/registry_spec.rb
index fc7332c..9574f19 100644
--- a/spec/dispatch/tools/registry_spec.rb
+++ b/spec/dispatch/tools/registry_spec.rb
@@ -10,7 +10,7 @@ RSpec.describe Dispatch::Tools::Registry do
properties: {
path: { type: "string" }
},
- required: ["path"]
+ required: [ "path" ]
}
) { |params, _context| Dispatch::Tools::Result.success(output: "contents of #{params[:path]}") }
end
@@ -39,7 +39,7 @@ RSpec.describe Dispatch::Tools::Registry do
properties: {
path: { type: "string" }
},
- required: ["path"]
+ required: [ "path" ]
}
) { |_params, _context| Dispatch::Tools::Result.success(output: "deleted") }
end
@@ -88,8 +88,8 @@ RSpec.describe Dispatch::Tools::Registry do
expect(tool).to be(read_file_tool)
end
- it "raises ToolNotFoundError for unknown tool name" do
- expect { registry.get("nonexistent") }.to raise_error(Dispatch::Tools::ToolNotFoundError)
+ it "returns nil for unknown tool name" do
+ expect(registry.get("nonexistent")).to be_nil
end
end
@@ -142,16 +142,16 @@ RSpec.describe Dispatch::Tools::Registry do
expect(result).to be_an(Array)
expect(result.size).to eq(1)
expect(result.first).to eq({
- name: "read_file",
- description: "Read the contents of a file",
- parameters: {
- type: "object",
- properties: {
- path: { type: "string" }
- },
- required: ["path"]
- }
- })
+ name: "read_file",
+ description: "Read the contents of a file",
+ parameters: {
+ type: "object",
+ properties: {
+ path: { type: "string" }
+ },
+ required: [ "path" ]
+ }
+ })
end
it "returns plain hashes, not structs" do
diff --git a/spec/dispatch/tools/result_spec.rb b/spec/dispatch/tools/result_spec.rb
index 17c9d7f..cd33368 100644
--- a/spec/dispatch/tools/result_spec.rb
+++ b/spec/dispatch/tools/result_spec.rb
@@ -72,22 +72,22 @@ RSpec.describe Dispatch::Tools::Result do
result = described_class.success(output: "data", metadata: { flag: true })
expect(result.to_h).to eq({
- success: true,
- output: "data",
- error: nil,
- metadata: { flag: true }
- })
+ success: true,
+ output: "data",
+ error: nil,
+ metadata: { flag: true }
+ })
end
it "returns a hash with all fields for a failure result" do
result = described_class.failure(error: "oops")
expect(result.to_h).to eq({
- success: false,
- output: nil,
- error: "oops",
- metadata: {}
- })
+ success: false,
+ output: nil,
+ error: "oops",
+ metadata: {}
+ })
end
end