Class: SolidAgent::AgentManifest::Picoschema
- Inherits:
-
Object
- Object
- SolidAgent::AgentManifest::Picoschema
- Defined in:
- lib/solid_agent/agent_manifest/picoschema.rb
Overview
Picoschema provides bidirectional conversion between Picoschema (a compact, YAML-optimized schema format from Dotprompt) and JSON Schema.
Picoschema is designed for human readability while JSON Schema provides full validation capabilities.
Constant Summary collapse
- SCALAR_TYPES =
%w[string integer number boolean any].freeze
Class Method Summary collapse
-
.from_json_schema(json_schema) ⇒ Hash
Convert JSON Schema to Picoschema.
-
.parse_type_string(type_str) ⇒ Hash
Parse a single type string (e.g., "string, description").
-
.to_json_schema(picoschema) ⇒ Hash
Convert Picoschema to JSON Schema.
Class Method Details
.from_json_schema(json_schema) ⇒ Hash
Convert JSON Schema to Picoschema
51 52 53 54 55 56 57 58 59 |
# File 'lib/solid_agent/agent_manifest/picoschema.rb', line 51 def from_json_schema(json_schema) return {} if json_schema.nil? return json_schema unless json_schema?(json_schema) properties = json_schema["properties"] || json_schema[:properties] || {} required = json_schema["required"] || json_schema[:required] || [] convert_properties(properties, required) end |
.parse_type_string(type_str) ⇒ Hash
Parse a single type string (e.g., "string, description")
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/solid_agent/agent_manifest/picoschema.rb', line 65 def parse_type_string(type_str) return { "type" => "any" } if type_str.nil? || type_str.strip == "any" str = type_str.to_s.strip # Handle enum types first: string(a, b, c), description # Need to split after the closing paren for enum types if str =~ /\A(\w+\([^)]+\))(,\s*(.+))?\z/ type_part = ::Regexp.last_match(1).strip description = ::Regexp.last_match(3)&.strip else # Normal split for non-enum types parts = str.split(",", 2) type_part = parts[0].strip description = parts[1]&.strip end result = parse_type_part(type_part) result["description"] = description if description.present? result end |
.to_json_schema(picoschema) ⇒ Hash
Convert Picoschema to JSON Schema
40 41 42 43 44 45 |
# File 'lib/solid_agent/agent_manifest/picoschema.rb', line 40 def to_json_schema(picoschema) return { "type" => "object", "properties" => {} } if picoschema.nil? return picoschema if json_schema?(picoschema) parse_object(picoschema) end |