Class: SolidAgent::AgentManifest::Picoschema

Inherits:
Object
  • Object
show all
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.

Examples:

Picoschema syntax

# Simple types
query: string, the search query
limit?: integer                    # optional field

# Enums
status: string(draft, published, archived)

# Arrays
tags: [string]

# Nested objects
author: object
  name: string
  email: string

# Array of objects
comments: [object]
  author: string
  text: string

Constant Summary collapse

SCALAR_TYPES =
%w[string integer number boolean any].freeze

Class Method Summary collapse

Class Method Details

.from_json_schema(json_schema) ⇒ Hash

Convert JSON Schema to Picoschema

Parameters:

  • json_schema (Hash)

    JSON Schema object

Returns:

  • (Hash)

    Picoschema definition



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")

Parameters:

  • type_str (String)

    Type definition string

Returns:

  • (Hash)

    JSON Schema for the field



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

Parameters:

  • picoschema (Hash)

    Picoschema definition

Returns:

  • (Hash)

    JSON Schema object



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