Class: LittleGhost::Content::Reasoning

Inherits:
Data
  • Object
show all
Includes:
Module.new do # :nodoc: def to_h = Content.serialize(self) def to_json(*arguments) = JSON.generate(to_h, *arguments) end
Defined in:
lib/little_ghost/content.rb,
lib/little_ghost/content.rb

Overview

Preserves provider reasoning without forcing every provider into one representation. A value may carry visible text, a provider signature, opaque redacted bytes, or provider-specific detail objects.

Redacted bytes are mutually exclusive with text and signatures so they can round-trip without exposing or changing provider-managed content.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text: "", signature: nil, redacted_content: nil, details: nil) ⇒ Reasoning

Returns a new instance of Reasoning.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/little_ghost/content.rb', line 68

def initialize(text: "", signature: nil, redacted_content: nil, details: nil)
  text = String(text)
  signature = String(signature) if signature
  redacted_content = String(redacted_content).b if redacted_content
  if details
    unless details.is_a?(Array) && details.all? { |detail| detail.is_a?(Hash) }
      raise ArgumentError, "reasoning details must be an array of objects"
    end
  end
  if redacted_content && (!text.empty? || !signature.to_s.empty?)
    raise ArgumentError, "reasoning content cannot contain both text and redacted content"
  end

  super(
    text: text.freeze,
    signature: signature&.freeze,
    redacted_content: redacted_content&.freeze,
    details:
  )
rescue TypeError
  raise ArgumentError, "reasoning content is invalid"
end

Instance Attribute Details

#detailsObject (readonly)

Returns the value of attribute details

Returns:

  • (Object)

    the current value of details



65
66
67
# File 'lib/little_ghost/content.rb', line 65

def details
  @details
end

#redacted_contentObject (readonly)

Returns the value of attribute redacted_content

Returns:

  • (Object)

    the current value of redacted_content



65
66
67
# File 'lib/little_ghost/content.rb', line 65

def redacted_content
  @redacted_content
end

#signatureObject (readonly)

Returns the value of attribute signature

Returns:

  • (Object)

    the current value of signature



65
66
67
# File 'lib/little_ghost/content.rb', line 65

def signature
  @signature
end

#textObject (readonly)

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



65
66
67
# File 'lib/little_ghost/content.rb', line 65

def text
  @text
end