Class: Llmshim::StreamEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/llmshim/types.rb

Overview

A typed SSE event from POST /v1/chat/stream.

type is one of: "content", "reasoning", "tool_call", "usage", "done", "error". All variant fields are exposed through raw and the helper accessors below; unknown fields remain reachable via raw.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, raw) ⇒ StreamEvent

Returns a new instance of StreamEvent.



102
103
104
105
# File 'lib/llmshim/types.rb', line 102

def initialize(type, raw)
  @type = type
  @raw = raw || {}
end

Instance Attribute Details

#rawObject (readonly)

Original parsed data Hash for this event.



100
101
102
# File 'lib/llmshim/types.rb', line 100

def raw
  @raw
end

#typeObject (readonly)

Event type string (String).



98
99
100
# File 'lib/llmshim/types.rb', line 98

def type
  @type
end

Instance Method Details

#[](key) ⇒ Object



161
162
163
# File 'lib/llmshim/types.rb', line 161

def [](key)
  raw[key.to_s]
end

#argumentsObject



145
146
147
# File 'lib/llmshim/types.rb', line 145

def arguments
  raw["arguments"]
end

#content?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/llmshim/types.rb', line 107

def content?
  type == "content"
end

#done?Boolean

Returns:

  • (Boolean)


123
124
125
# File 'lib/llmshim/types.rb', line 123

def done?
  type == "done"
end

#error?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/llmshim/types.rb', line 127

def error?
  type == "error"
end

#idObject

tool_call events



137
138
139
# File 'lib/llmshim/types.rb', line 137

def id
  raw["id"]
end

#messageObject

error events



157
158
159
# File 'lib/llmshim/types.rb', line 157

def message
  raw["message"]
end

#nameObject



141
142
143
# File 'lib/llmshim/types.rb', line 141

def name
  raw["name"]
end

#reasoning?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/llmshim/types.rb', line 111

def reasoning?
  type == "reasoning"
end

#textObject

content / reasoning events



132
133
134
# File 'lib/llmshim/types.rb', line 132

def text
  raw["text"]
end

#tool_call?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/llmshim/types.rb', line 115

def tool_call?
  type == "tool_call"
end

#usageObject

usage events



150
151
152
153
154
# File 'lib/llmshim/types.rb', line 150

def usage
  return nil unless usage?

  Usage.from_hash(raw)
end

#usage?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/llmshim/types.rb', line 119

def usage?
  type == "usage"
end