Class: Riffer::StreamEvents::GuardrailTripwire

Inherits:
Base
  • Object
show all
Defined in:
lib/riffer/stream_events/guardrail_tripwire.rb

Overview

Represents a guardrail tripwire event during streaming.

Emitted when a guardrail blocks execution during the streaming pipeline.

Instance Attribute Summary collapse

Attributes inherited from Base

#role

Instance Method Summary collapse

Constructor Details

#initialize(tripwire, role: :assistant) ⇒ GuardrailTripwire

Creates a new tripwire stream event.

tripwire

the tripwire details.

role

the message role (defaults to :assistant).

– : (Riffer::Guardrails::Tripwire, ?role: Symbol) -> void



18
19
20
21
# File 'lib/riffer/stream_events/guardrail_tripwire.rb', line 18

def initialize(tripwire, role: :assistant)
  super(role: role)
  @tripwire = tripwire
end

Instance Attribute Details

#tripwireObject (readonly)

The tripwire containing block details.



9
10
11
# File 'lib/riffer/stream_events/guardrail_tripwire.rb', line 9

def tripwire
  @tripwire
end

Instance Method Details

#guardrailObject

The guardrail class that triggered the block.

– : () -> singleton(Riffer::Guardrail)



43
44
45
# File 'lib/riffer/stream_events/guardrail_tripwire.rb', line 43

def guardrail
  tripwire.guardrail
end

#phaseObject

The phase when blocking occurred (:before or :after).

– : () -> Symbol



35
36
37
# File 'lib/riffer/stream_events/guardrail_tripwire.rb', line 35

def phase
  tripwire.phase
end

#reasonObject

The reason for blocking.

– : () -> String



27
28
29
# File 'lib/riffer/stream_events/guardrail_tripwire.rb', line 27

def reason
  tripwire.reason
end

#to_hObject

Converts the event to a hash.

– : () -> Hash[Symbol, untyped]



51
52
53
54
55
56
# File 'lib/riffer/stream_events/guardrail_tripwire.rb', line 51

def to_h
  {
    role: @role,
    tripwire: tripwire.to_h
  }
end