Class: Legion::Extensions::Llm::Canonical::Thinking
- Inherits:
-
Data
- Object
- Data
- Legion::Extensions::Llm::Canonical::Thinking
- Defined in:
- lib/legion/extensions/llm/canonical/thinking.rb
Overview
Canonical thinking/reasoning block. Ports field vocabulary from Legion::LLM::Types and lex-llm Thinking. Empty-string values normalize to nil (absence, not data — 04 §8).
Defined Under Namespace
Classes: Config
Constant Summary collapse
- BUILD_SITE =
'Canonical::Thinking.build'- FROM_HASH_SITE =
'Canonical::Thinking.from_hash'- NEW_SITE =
'Canonical::Thinking.new'
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#signature ⇒ Object
readonly
Returns the value of attribute signature.
Class Method Summary collapse
-
.absence!(value, site, member) ⇒ Object
Empty-string is absence, not data (04 §8).
-
.build(content: nil, signature: nil, metadata: {}) ⇒ Object
Build from keyword args (primary constructor).
-
.from_hash(source) ⇒ Object
Build from a Hash (raw provider response or deserialized wire payload).
Instance Method Summary collapse
-
#as_json ⇒ Object
MultiJson/Oj/::JSON callback — prevents Data.define #inspect leak into JSON.
-
#empty? ⇒ Boolean
Whether this thinking block has any content.
-
#to_h ⇒ Object
Serialize to a Hash for AMQP/fleet/wire transport.
- #to_json ⇒ Object
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content
13 14 15 |
# File 'lib/legion/extensions/llm/canonical/thinking.rb', line 13 def content @content end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata
13 14 15 |
# File 'lib/legion/extensions/llm/canonical/thinking.rb', line 13 def @metadata end |
#signature ⇒ Object (readonly)
Returns the value of attribute signature
13 14 15 |
# File 'lib/legion/extensions/llm/canonical/thinking.rb', line 13 def signature @signature end |
Class Method Details
.absence!(value, site, member) ⇒ Object
Empty-string is absence, not data (04 §8).
32 33 34 35 36 37 |
# File 'lib/legion/extensions/llm/canonical/thinking.rb', line 32 def self.absence!(value, site, member) return nil if value.nil? Strict.expect_type!(value, [::String], site, member) value.empty? ? nil : value end |
.build(content: nil, signature: nil, metadata: {}) ⇒ Object
Build from keyword args (primary constructor).
15 16 17 18 19 20 21 |
# File 'lib/legion/extensions/llm/canonical/thinking.rb', line 15 def self.build(content: nil, signature: nil, metadata: {}) new( content: absence!(content, self::BUILD_SITE, :content), signature: absence!(signature, self::BUILD_SITE, :signature), metadata: Strict.(, self::BUILD_SITE) ) end |
.from_hash(source) ⇒ Object
Build from a Hash (raw provider response or deserialized wire payload).
24 25 26 27 28 29 |
# File 'lib/legion/extensions/llm/canonical/thinking.rb', line 24 def self.from_hash(source) Strict.require_hash!(source, self::FROM_HASH_SITE) hash = Strict.symbolize_keys(source) = Strict.fold_unknowns!(self, self::FROM_HASH_SITE, hash) build(content: hash[:content], signature: hash[:signature], metadata:) end |
Instance Method Details
#as_json ⇒ Object
MultiJson/Oj/::JSON callback — prevents Data.define #inspect leak into JSON.
45 46 47 |
# File 'lib/legion/extensions/llm/canonical/thinking.rb', line 45 def as_json(*) to_h end |
#empty? ⇒ Boolean
Whether this thinking block has any content.
54 55 56 |
# File 'lib/legion/extensions/llm/canonical/thinking.rb', line 54 def empty? content.nil? && signature.nil? end |
#to_h ⇒ Object
Serialize to a Hash for AMQP/fleet/wire transport.
40 41 42 |
# File 'lib/legion/extensions/llm/canonical/thinking.rb', line 40 def to_h super.compact end |
#to_json ⇒ Object
49 50 51 |
# File 'lib/legion/extensions/llm/canonical/thinking.rb', line 49 def to_json(*) to_h.to_json(*) end |