Class: A2A::Server::Events::Event
- Inherits:
-
Object
- Object
- A2A::Server::Events::Event
- Defined in:
- lib/a2a/server/events/event_queue.rb
Overview
Event object for the event queue system
Represents an event that can be published to and consumed from an event queue. Events can be Task objects, Message objects, or status/artifact update events.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#context_id ⇒ String?
Get the context ID from the event data if available.
-
#initialize(type:, data:, id: nil) ⇒ Event
constructor
Initialize a new event.
-
#message_event? ⇒ Boolean
Check if this is a message event.
-
#task_event? ⇒ Boolean
Check if this is a task-related event.
-
#task_id ⇒ String?
Get the task ID from the event data if available.
-
#to_h ⇒ Hash
Convert event to hash representation.
Constructor Details
#initialize(type:, data:, id: nil) ⇒ Event
Initialize a new event
21 22 23 24 25 26 |
# File 'lib/a2a/server/events/event_queue.rb', line 21 def initialize(type:, data:, id: nil) @type = type @data = data @timestamp = Time.now.utc @id = id || SecureRandom.uuid end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
13 14 15 |
# File 'lib/a2a/server/events/event_queue.rb', line 13 def data @data end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
13 14 15 |
# File 'lib/a2a/server/events/event_queue.rb', line 13 def id @id end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
13 14 15 |
# File 'lib/a2a/server/events/event_queue.rb', line 13 def @timestamp end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
13 14 15 |
# File 'lib/a2a/server/events/event_queue.rb', line 13 def type @type end |
Instance Method Details
#context_id ⇒ String?
Get the context ID from the event data if available
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/a2a/server/events/event_queue.rb', line 76 def context_id case @data when A2A::Types::Task @data.context_id when A2A::Types::TaskStatusUpdateEvent, A2A::Types::TaskArtifactUpdateEvent @data.context_id when A2A::Types::Message @data.context_id else nil end end |
#message_event? ⇒ Boolean
Check if this is a message event
53 54 55 |
# File 'lib/a2a/server/events/event_queue.rb', line 53 def @type == "message" end |
#task_event? ⇒ Boolean
Check if this is a task-related event
45 46 47 |
# File 'lib/a2a/server/events/event_queue.rb', line 45 def task_event? %w[task task_status_update task_artifact_update].include?(@type) end |
#task_id ⇒ String?
Get the task ID from the event data if available
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/a2a/server/events/event_queue.rb', line 61 def task_id case @data when A2A::Types::Task @data.id when A2A::Types::TaskStatusUpdateEvent, A2A::Types::TaskArtifactUpdateEvent @data.task_id else nil end end |
#to_h ⇒ Hash
Convert event to hash representation
32 33 34 35 36 37 38 39 |
# File 'lib/a2a/server/events/event_queue.rb', line 32 def to_h { id: @id, type: @type, data: @data.respond_to?(:to_h) ? @data.to_h : @data, timestamp: @timestamp.iso8601 } end |