Class: Cline::SessionMessage
- Defined in:
- lib/cline/session_message.rb
Overview
Session's message
Defined Under Namespace
Classes: MessageContent, Metrics, ModelInfo
Internal collapse
-
#cline_models ⇒ Models
The Clines models used to interpret the message.
Attributes inherited from Schema
Public API collapse
-
#content ⇒ Array<MessageContent>
Content blocks.
-
#id ⇒ String
Message identifier.
-
#metrics ⇒ Metrics?
Usage metrics.
-
#model_info ⇒ ModelInfo?
Model metadata.
-
#role ⇒ String
Role (user or assistant).
-
#timestamp ⇒ Time
Get the message timestamp as a Ruby time.
-
#to_human(limit: 128) ⇒ String
Return a human-friendly version of a message.
-
#ts ⇒ Integer
Message timestamp in milliseconds.
-
#usage ⇒ Usage?
Get the usage statistics of this message, if any.
Internal collapse
-
.of_hash(hash, *args, cline_models: nil, **kwargs) ⇒ Schema
Parse a Hash object and instantiate the proper instance from it.
Methods inherited from Schema
#==, as_hash, cast, cline_snake_attributes, #to_cline_json, #to_hash
Instance Attribute Details
#cline_models ⇒ Models
Returns The Clines models used to interpret the message.
167 168 169 |
# File 'lib/cline/session_message.rb', line 167 def cline_models @cline_models end |
Class Method Details
.of_hash(hash, *args, cline_models: nil, **kwargs) ⇒ Schema
Parse a Hash object and instantiate the proper instance from it.
160 161 162 163 164 |
# File 'lib/cline/session_message.rb', line 160 def self.of_hash(hash, *args, cline_models: nil, **kwargs) instance = super(hash, *args, **kwargs) instance.cline_models = cline_models if cline_models instance end |
Instance Method Details
#content ⇒ Array<MessageContent>
Returns Content blocks.
90 |
# File 'lib/cline/session_message.rb', line 90 attribute :content, Utils::Schema.collection(MessageContent) |
#id ⇒ String
Returns Message identifier.
84 |
# File 'lib/cline/session_message.rb', line 84 attribute :id, :string |
#metrics ⇒ Metrics?
Returns Usage metrics.
99 |
# File 'lib/cline/session_message.rb', line 99 attribute :metrics, Metrics |
#model_info ⇒ ModelInfo?
Returns Model metadata.
96 |
# File 'lib/cline/session_message.rb', line 96 attribute :model_info, ModelInfo |
#role ⇒ String
Returns Role (user or assistant).
87 |
# File 'lib/cline/session_message.rb', line 87 attribute :role, :string |
#timestamp ⇒ Time
Get the message timestamp as a Ruby time
104 105 106 |
# File 'lib/cline/session_message.rb', line 104 def @timestamp ||= Time.at(ts / 1000.0) end |
#to_human(limit: 128) ⇒ String
Return a human-friendly version of a message. Useful for stdout or logging.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/cline/session_message.rb', line 131 def to_human(limit: 128) ( case role when 'user' "User: #{first_text}" when 'assistant' tool_use = content.find { |c| c.type == 'tool_use' } if tool_use "Assistant uses #{tool_use.name}" else "Assistant: #{first_text}" end when 'tool' "Tool result: #{content.find { |c| c.type == 'tool_result' }&.content}" else to_s end ).ellipsized(limit) end |
#ts ⇒ Integer
Returns Message timestamp in milliseconds.
93 |
# File 'lib/cline/session_message.rb', line 93 attribute :ts, :integer |
#usage ⇒ Usage?
Get the usage statistics of this message, if any
111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/cline/session_message.rb', line 111 def usage return unless metrics @usage ||= Usage.new( **{ cost: metrics.cost, input_tokens: metrics.input_tokens, output_tokens: metrics.output_tokens, cache_read_tokens: metrics.cache_read_tokens, cache_write_tokens: metrics.cache_write_tokens, cline_model: cline_models && cline_models[model_info.id] }.compact ) end |