Class: A2A::Plugins::ExampleTransport

Inherits:
A2A::Plugin::TransportPlugin show all
Defined in:
lib/a2a/plugins/example_transport.rb

Instance Attribute Summary

Attributes inherited from A2A::Plugin::Base

#config, #logger

Instance Method Summary collapse

Methods inherited from A2A::Plugin::Base

dependencies, depends_on, inherited, #initialize, plugin_type

Constructor Details

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

Instance Method Details

#cleanupObject (private)



71
72
73
# File 'lib/a2a/plugins/example_transport.rb', line 71

def cleanup
  logger&.info("Example Transport plugin cleaned up")
end

#create_stream(**_options) ⇒ Enumerator

Create streaming connection

Parameters:

  • Connection options

Returns:

  • Stream enumerator



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/a2a/plugins/example_transport.rb', line 40

def create_stream(**_options)
  Enumerator.new do |yielder|
    5.times do |i|
      yielder << {
        event: "data",
        data: { message: "Stream message #{i + 1}" }
      }
      sleep(0.1) # Simulate streaming delay
    end
  end
end

#register_hooks(plugin_manager) ⇒ Object

Register hooks for this plugin



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/a2a/plugins/example_transport.rb', line 53

def register_hooks(plugin_manager)
  plugin_manager.add_hook(A2A::Plugin::Events::BEFORE_REQUEST) do |request|
    logger&.debug("Example Transport: Processing request #{request[:id]}")
    request[:transport_metadata] = { plugin: "example_transport" }
  end

  plugin_manager.add_hook(A2A::Plugin::Events::AFTER_RESPONSE) do |response, request|
    logger&.debug("Example Transport: Processed response for #{request[:id]}")
    response
  end
end

#send_request(request, **_options) ⇒ Hash

Send request implementation

Parameters:

  • Request data

  • Transport options

Returns:

  • Response



21
22
23
24
25
26
27
28
29
30
# File 'lib/a2a/plugins/example_transport.rb', line 21

def send_request(request, **_options)
  logger&.info("Sending request via Example Transport: #{request[:method]}")

  # Simulate request processing
  {
    jsonrpc: "2.0",
    result: { message: "Response from Example Transport" },
    id: request[:id]
  }
end

#setupObject (private)



67
68
69
# File 'lib/a2a/plugins/example_transport.rb', line 67

def setup
  logger&.info("Example Transport plugin initialized")
end

#supports_streaming?Boolean

This transport supports streaming

Returns:



33
34
35
# File 'lib/a2a/plugins/example_transport.rb', line 33

def supports_streaming?
  true
end

#transport_nameObject

Transport name for identification



13
14
15
# File 'lib/a2a/plugins/example_transport.rb', line 13

def transport_name
  "EXAMPLE"
end