Class: A2A::Client::SSE

Inherits:
Base
  • Object
show all
Defined in:
lib/simple_a2a/client/sse.rb

Constant Summary collapse

EVENT_CLASSES =
{
  "TaskStatusUpdateEvent"   => Models::TaskStatusUpdateEvent,
  "TaskArtifactUpdateEvent" => Models::TaskArtifactUpdateEvent
}.freeze

Instance Method Summary collapse

Methods inherited from Base

#agent_card, #cancel_task, #get_task, #initialize, #list_tasks, #send_task

Constructor Details

This class inherits a constructor from A2A::Client::Base

Instance Method Details

#resubscribe(task_id:, &block) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/simple_a2a/client/sse.rb', line 26

def resubscribe(task_id:, &block)
  body = JSON.generate({
    "jsonrpc" => "2.0",
    "id"      => SecureRandom.uuid,
    "method"  => "tasks/resubscribe",
    "params"  => { "id" => task_id }
  })

  run_async do |internet|
    headers  = rpc_headers.merge("accept" => "text/event-stream")
    response = internet.post(@url, headers: headers, body: body)
    parse_sse_stream(response, &block)
  end
end

#send_subscribe(message:, **opts, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/simple_a2a/client/sse.rb', line 11

def send_subscribe(message:, **opts, &block)
  body = JSON.generate({
    "jsonrpc" => "2.0",
    "id"      => SecureRandom.uuid,
    "method"  => "tasks/sendSubscribe",
    "params"  => build_send_params(message, opts)
  })

  run_async do |internet|
    headers  = rpc_headers.merge("accept" => "text/event-stream")
    response = internet.post(@url, headers: headers, body: body)
    parse_sse_stream(response, &block)
  end
end