Class: AgUiProtocol::Core::Events::TextMessageChunkEvent

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

Overview

Convenience event for complete text messages without manually emitting ‘TextMessageStart`/`TextMessageEnd`.

“‘ruby event = AgUiProtocol::Core::Events::TextMessageChunkEvent.new(

message_id: "m1",
delta: "Hello"

)

“‘

Behavior:

  • Convenience: Some consumers (e.g., the JS/TS client) expand chunk events into the standard start/content/end sequence automatically, allowing producers to omit explicit start/end events when using chunks.

  • First chunk requirements: The first chunk for a given message must include ‘message_id`.

  • Streaming: Subsequent chunks with the same ‘message_id` correspond to content pieces; completion triggers an implied end in clients that perform expansion.

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(message_id: nil, role: nil, delta: nil, timestamp: nil, raw_event: nil) ⇒ TextMessageChunkEvent

Returns a new instance of TextMessageChunkEvent.

Raises:

  • (ArgumentError)


269
270
271
272
273
274
275
276
# File 'lib/ag_ui_protocol/core/events.rb', line 269

def initialize(message_id: nil, role: nil, delta: nil, timestamp: nil, raw_event: nil)
  raise ArgumentError, "role must be one of #{TEXT_MESSAGE_ROLE_VALUES.join(", ")}, got #{role}" if !role.nil? && !TEXT_MESSAGE_ROLE_VALUES.include?(role)

  super(type: EventType::TEXT_MESSAGE_CHUNK, timestamp: timestamp, raw_event: raw_event)
  @message_id = message_id
  @role = role
  @delta = delta
end

Instance Attribute Details

#deltaObject (readonly)

Returns the value of attribute delta.



253
254
255
# File 'lib/ag_ui_protocol/core/events.rb', line 253

def delta
  @delta
end

#message_idObject (readonly)

Returns the value of attribute message_id.



247
248
249
# File 'lib/ag_ui_protocol/core/events.rb', line 247

def message_id
  @message_id
end

#roleObject (readonly)

Returns the value of attribute role.



250
251
252
# File 'lib/ag_ui_protocol/core/events.rb', line 250

def role
  @role
end

Instance Method Details

#to_hObject



279
280
281
# File 'lib/ag_ui_protocol/core/events.rb', line 279

def to_h
  super.merge(message_id: @message_id, role: @role, delta: @delta)
end