Class: A2A::Operation::SendStreamingMessage

Inherits:
Object
  • Object
show all
Includes:
Executable
Defined in:
lib/a2a/operation/send_streaming_message.rb

Constant Summary collapse

METHOD =
"SendStreamingMessage"
Configuration =
SendMessage::Configuration

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Executable

#execute

Constructor Details

#initialize(message, configuration: {}, metadata: nil, tenant: nil) ⇒ SendStreamingMessage

Returns a new instance of SendStreamingMessage.



14
15
16
17
18
19
20
21
22
23
# File 'lib/a2a/operation/send_streaming_message.rb', line 14

def initialize(message, configuration: {}, metadata: nil, tenant: nil)
  @message = message.is_a?(Message) ? message : Message.from_h(message)
  @configuration = if configuration.is_a?(Configuration)
                     configuration
                   else
                     Configuration.new(**configuration.transform_keys(&:to_sym))
                   end
  @metadata = 
  @tenant = tenant
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



12
13
14
# File 'lib/a2a/operation/send_streaming_message.rb', line 12

def configuration
  @configuration
end

#messageObject (readonly)

Returns the value of attribute message.



12
13
14
# File 'lib/a2a/operation/send_streaming_message.rb', line 12

def message
  @message
end

#metadataObject (readonly)

Returns the value of attribute metadata.



12
13
14
# File 'lib/a2a/operation/send_streaming_message.rb', line 12

def 
  @metadata
end

#tenantObject (readonly)

Returns the value of attribute tenant.



12
13
14
# File 'lib/a2a/operation/send_streaming_message.rb', line 12

def tenant
  @tenant
end

Instance Method Details

#execute_http_json(protocol, &block) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/a2a/operation/send_streaming_message.rb', line 34

def execute_http_json(protocol, &block)
  protocol.stream("/message:stream", method: :post, body: params) do |response|
    sub = Streaming::Subscription.new(response)
    return sub unless block

    sub.each(&block)
  end
end

#execute_json_rpc(protocol, &block) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/a2a/operation/send_streaming_message.rb', line 25

def execute_json_rpc(protocol, &block)
  protocol.stream(METHOD, params) do |response|
    sub = Streaming::Subscription.new(response)
    return sub unless block

    sub.each(&block)
  end
end

#paramsObject



43
44
45
46
47
48
49
50
# File 'lib/a2a/operation/send_streaming_message.rb', line 43

def params
  p = { "message" => message.to_h }
  config_h = configuration.to_h
  p["configuration"] = config_h unless config_h.empty?
  p["metadata"] =  if 
  p["tenant"] = tenant if tenant
  p
end