Class: TurnKit::Message
- Inherits:
-
Object
- Object
- TurnKit::Message
- Defined in:
- lib/turnkit/message.rb
Constant Summary collapse
- ROLES =
%w[user assistant tool].freeze
- KINDS =
%w[text tool_call tool_result context_summary].freeze
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#conversation_id ⇒ Object
readonly
Returns the value of attribute conversation_id.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#provider_message_id ⇒ Object
readonly
Returns the value of attribute provider_message_id.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
-
#sequence ⇒ Object
readonly
Returns the value of attribute sequence.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#tool_execution_id ⇒ Object
readonly
Returns the value of attribute tool_execution_id.
-
#turn_id ⇒ Object
readonly
Returns the value of attribute turn_id.
Instance Method Summary collapse
- #compaction_metadata ⇒ Object
- #context_summary? ⇒ Boolean
-
#initialize(attributes = {}) ⇒ Message
constructor
A new instance of Message.
- #text? ⇒ Boolean
- #to_h ⇒ Object
- #tool_call? ⇒ Boolean
- #tool_result? ⇒ Boolean
Constructor Details
#initialize(attributes = {}) ⇒ Message
Returns a new instance of Message.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/turnkit/message.rb', line 11 def initialize(attributes = {}) attrs = stringify(attributes) @id = attrs["id"] || Id.generate(:message) @conversation_id = attrs.fetch("conversation_id") @turn_id = attrs["turn_id"] @role = attrs.fetch("role").to_s @kind = attrs.fetch("kind", "text").to_s @sequence = attrs.fetch("sequence").to_i @content = normalize_content(attrs["content"] || attrs["text"]) @text = attrs["text"] || extract_text(@content) @tool_execution_id = attrs["tool_execution_id"] @provider_message_id = attrs["provider_message_id"] @metadata = attrs["metadata"] || {} @created_at = attrs["created_at"] || Clock.now validate! end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
9 10 11 |
# File 'lib/turnkit/message.rb', line 9 def content @content end |
#conversation_id ⇒ Object (readonly)
Returns the value of attribute conversation_id.
8 9 10 |
# File 'lib/turnkit/message.rb', line 8 def conversation_id @conversation_id end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
9 10 11 |
# File 'lib/turnkit/message.rb', line 9 def created_at @created_at end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/turnkit/message.rb', line 8 def id @id end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
8 9 10 |
# File 'lib/turnkit/message.rb', line 8 def kind @kind end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
9 10 11 |
# File 'lib/turnkit/message.rb', line 9 def @metadata end |
#provider_message_id ⇒ Object (readonly)
Returns the value of attribute provider_message_id.
9 10 11 |
# File 'lib/turnkit/message.rb', line 9 def @provider_message_id end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
8 9 10 |
# File 'lib/turnkit/message.rb', line 8 def role @role end |
#sequence ⇒ Object (readonly)
Returns the value of attribute sequence.
8 9 10 |
# File 'lib/turnkit/message.rb', line 8 def sequence @sequence end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
9 10 11 |
# File 'lib/turnkit/message.rb', line 9 def text @text end |
#tool_execution_id ⇒ Object (readonly)
Returns the value of attribute tool_execution_id.
9 10 11 |
# File 'lib/turnkit/message.rb', line 9 def tool_execution_id @tool_execution_id end |
#turn_id ⇒ Object (readonly)
Returns the value of attribute turn_id.
8 9 10 |
# File 'lib/turnkit/message.rb', line 8 def turn_id @turn_id end |
Instance Method Details
#compaction_metadata ⇒ Object
62 63 64 |
# File 'lib/turnkit/message.rb', line 62 def .fetch("compaction", {}) end |
#context_summary? ⇒ Boolean
58 59 60 |
# File 'lib/turnkit/message.rb', line 58 def context_summary? kind == "context_summary" end |
#text? ⇒ Boolean
46 47 48 |
# File 'lib/turnkit/message.rb', line 46 def text? kind == "text" end |
#to_h ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/turnkit/message.rb', line 29 def to_h { "id" => id, "conversation_id" => conversation_id, "turn_id" => turn_id, "role" => role, "kind" => kind, "sequence" => sequence, "content" => content, "text" => text, "tool_execution_id" => tool_execution_id, "provider_message_id" => , "metadata" => , "created_at" => created_at } end |
#tool_call? ⇒ Boolean
50 51 52 |
# File 'lib/turnkit/message.rb', line 50 def tool_call? kind == "tool_call" end |
#tool_result? ⇒ Boolean
54 55 56 |
# File 'lib/turnkit/message.rb', line 54 def tool_result? kind == "tool_result" end |