Class: Tama::Agentic::MessageParams

Inherits:
Data
  • Object
show all
Defined in:
lib/tama/agentic/message_params.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(recipient:, identifier:, content:, index:, author:, thread:, klass: "user-message") ⇒ MessageParams

Returns a new instance of MessageParams.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/tama/agentic/message_params.rb', line 6

def initialize(recipient:, identifier:, content:, index:, author:, thread:, klass: "user-message")
  Params.require_string!({"recipient" => recipient}, "recipient")
  Params.require_string!({"class" => klass}, "class")
  Params.require_string!({"identifier" => identifier}, "identifier")
  Params.require_string!({"content" => content}, "content")
  unless index.is_a?(Integer)
    raise Error::ValidationError.new("index is required", errors: {index: "must be an integer"})
  end
  raise Error::ValidationError, "author is invalid" unless author.is_a?(Author)
  raise Error::ValidationError, "thread is invalid" unless thread.is_a?(Thread)

  super
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author

Returns:

  • (Object)

    the current value of author



5
6
7
# File 'lib/tama/agentic/message_params.rb', line 5

def author
  @author
end

#contentObject (readonly)

Returns the value of attribute content

Returns:

  • (Object)

    the current value of content



5
6
7
# File 'lib/tama/agentic/message_params.rb', line 5

def content
  @content
end

#identifierObject (readonly)

Returns the value of attribute identifier

Returns:

  • (Object)

    the current value of identifier



5
6
7
# File 'lib/tama/agentic/message_params.rb', line 5

def identifier
  @identifier
end

#indexObject (readonly)

Returns the value of attribute index

Returns:

  • (Object)

    the current value of index



5
6
7
# File 'lib/tama/agentic/message_params.rb', line 5

def index
  @index
end

#klassObject (readonly)

Returns the value of attribute klass

Returns:

  • (Object)

    the current value of klass



5
6
7
# File 'lib/tama/agentic/message_params.rb', line 5

def klass
  @klass
end

#recipientObject (readonly)

Returns the value of attribute recipient

Returns:

  • (Object)

    the current value of recipient



5
6
7
# File 'lib/tama/agentic/message_params.rb', line 5

def recipient
  @recipient
end

#threadObject (readonly)

Returns the value of attribute thread

Returns:

  • (Object)

    the current value of thread



5
6
7
# File 'lib/tama/agentic/message_params.rb', line 5

def thread
  @thread
end

Class Method Details

.parse(value) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/tama/agentic/message_params.rb', line 20

def self.parse(value)
  data = Params.hash(value, "message")
  new(
    recipient: data["recipient"],
    klass: data.fetch("class", "user-message"),
    identifier: data["identifier"],
    content: data["content"],
    index: data["index"],
    author: Author.parse(data["author"]),
    thread: Thread.parse(data["thread"])
  )
end

Instance Method Details

#to_hObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/tama/agentic/message_params.rb', line 33

def to_h
  {
    "recipient" => recipient,
    "class" => klass,
    "identifier" => identifier,
    "content" => content,
    "index" => index,
    "author" => author.to_h,
    "thread" => thread.to_h
  }
end