Module: OllamaAgent::Topology::SignatureNormalizer
- Defined in:
- lib/ollama_agent/topology/signature_normalizer.rb
Overview
Canonical method/class shapes for deterministic symbol_id hashing.
Constant Summary collapse
- PARAM_KIND_ORDER =
{ "positional" => 0, "optional_positional" => 1, "keyword_required" => 2, "keyword_optional" => 3, "rest" => 4, "kwrest" => 5, "block" => 6 }.freeze
Class Method Summary collapse
- .normalize(method_signature_hash) ⇒ Object
- .normalize_class(class_fqcn:, methods:) ⇒ Object
- .normalize_one_param(param) ⇒ Object
- .normalize_parameters(params) ⇒ Object
- .normalize_types(types) ⇒ Object
- .sort_top_level(canonical) ⇒ Object
- .stringify_keys(obj) ⇒ Object
Class Method Details
.normalize(method_signature_hash) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ollama_agent/topology/signature_normalizer.rb', line 19 def normalize(method_signature_hash) h = stringify_keys(method_signature_hash || {}) params = normalize_parameters(Array(h["parameters"])) out = { "name" => h["name"].to_s, "kind" => h["kind"].to_s, "parameters" => params } out["types"] = normalize_types(h["types"]) if h.key?("types") sort_top_level(out) end |
.normalize_class(class_fqcn:, methods:) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/ollama_agent/topology/signature_normalizer.rb', line 31 def normalize_class(class_fqcn:, methods:) normalized_methods = Array(methods).map { |m| normalize(m) }.sort_by { |m| m["name"] } sort_top_level( { "fqcn" => class_fqcn.to_s, "methods" => normalized_methods } ) end |
.normalize_one_param(param) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/ollama_agent/topology/signature_normalizer.rb', line 47 def normalize_one_param(param) p = stringify_keys(param) kind = p["kind"].to_s out = { "kind" => kind, "name" => p["name"].to_s } out["type"] = p["type"].to_s if p["type"] && !p["type"].to_s.empty? out end |
.normalize_parameters(params) ⇒ Object
41 42 43 44 45 |
# File 'lib/ollama_agent/topology/signature_normalizer.rb', line 41 def normalize_parameters(params) params.map { |p| normalize_one_param(p) }.sort_by do |p| [PARAM_KIND_ORDER.fetch(p["kind"], 99), p["name"].to_s] end end |
.normalize_types(types) ⇒ Object
55 56 57 58 |
# File 'lib/ollama_agent/topology/signature_normalizer.rb', line 55 def normalize_types(types) t = stringify_keys(types) t.keys.sort.to_h { |key| [key, t[key].to_s] } end |
.sort_top_level(canonical) ⇒ Object
69 70 71 |
# File 'lib/ollama_agent/topology/signature_normalizer.rb', line 69 def sort_top_level(canonical) canonical.keys.sort.to_h { |key| [key, canonical[key]] } end |
.stringify_keys(obj) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/ollama_agent/topology/signature_normalizer.rb', line 60 def stringify_keys(obj) case obj when Hash obj.transform_keys(&:to_s) else {} end end |