Class: AgUiProtocol::Core::Events::StateDeltaEvent

Inherits:
BaseEvent show all
Defined in:
lib/ag_ui_protocol/core/events.rb

Overview

Provides a partial update to an agent’s state using JSON Patch.

“‘ruby event = AgUiProtocol::Core::Events::StateDeltaEvent.new(delta: [{ “op” => “replace”, “path” => “/a”, “value” => 2 }]) “`

Instance Attribute Summary collapse

Attributes inherited from BaseEvent

#raw_event, #timestamp, #type

Instance Method Summary collapse

Methods inherited from Types::Model

#as_json, #to_json

Constructor Details

#initialize(delta:, timestamp: nil, raw_event: nil) ⇒ StateDeltaEvent

Returns a new instance of StateDeltaEvent.



652
653
654
655
# File 'lib/ag_ui_protocol/core/events.rb', line 652

def initialize(delta:, timestamp: nil, raw_event: nil)
  super(type: EventType::STATE_DELTA, timestamp: timestamp, raw_event: raw_event)
  @delta = delta
end

Instance Attribute Details

#deltaObject (readonly)

Returns the value of attribute delta.



646
647
648
# File 'lib/ag_ui_protocol/core/events.rb', line 646

def delta
  @delta
end

Instance Method Details

#to_hObject



658
659
660
661
662
663
# File 'lib/ag_ui_protocol/core/events.rb', line 658

def to_h
  # `delta` is an array of JSON Patch ops; each op's `value` may carry
  # arbitrary user-defined keys (RFC 6902). Preserve the array
  # contents verbatim on the wire.
  super.merge(delta: @delta.nil? ? nil : AgUiProtocol::Util::Opaque.new(@delta))
end