Class: Ask::SessionProtocol::Interactions::Interaction

Inherits:
Data
  • Object
show all
Defined in:
lib/ask/session_protocol/interactions.rb

Overview

An interaction on the wire. Immutable.

{ "id" => "act_123", "kind" => "approval",
"status" => "pending", "payload" => { "toolName" => "bash", ... } }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, kind:, status: "pending", payload: {}) ⇒ Interaction

Returns a new instance of Interaction.

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ask/session_protocol/interactions.rb', line 29

def initialize(id:, kind:, status: "pending", payload: {})
  unless id.is_a?(String) && !id.empty?
    raise ArgumentError, "interaction id must be a non-empty String"
  end
  unless KINDS.include?(kind)
    raise ArgumentError, "unknown interaction kind: #{kind.inspect} (expected one of #{KINDS.inspect})"
  end
  unless STATUSES.include?(status)
    raise ArgumentError, "unknown interaction status: #{status.inspect} (expected one of #{STATUSES.inspect})"
  end
  raise ArgumentError, "interaction payload must be a Hash" unless payload.is_a?(Hash)

  super
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



28
29
30
# File 'lib/ask/session_protocol/interactions.rb', line 28

def id
  @id
end

#kindObject (readonly)

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



28
29
30
# File 'lib/ask/session_protocol/interactions.rb', line 28

def kind
  @kind
end

#payloadObject (readonly)

Returns the value of attribute payload

Returns:

  • (Object)

    the current value of payload



28
29
30
# File 'lib/ask/session_protocol/interactions.rb', line 28

def payload
  @payload
end

#statusObject (readonly)

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



28
29
30
# File 'lib/ask/session_protocol/interactions.rb', line 28

def status
  @status
end

Instance Method Details

#pending?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/ask/session_protocol/interactions.rb', line 44

def pending?
  status == "pending"
end

#resolved?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/ask/session_protocol/interactions.rb', line 48

def resolved?
  status != "pending"
end

#to_hObject



52
53
54
# File 'lib/ask/session_protocol/interactions.rb', line 52

def to_h
  { "id" => id, "kind" => kind, "status" => status, "payload" => payload }
end