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



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

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

#guardrail_idObject

The guardrail identifier that triggered the block.

: () -> String



39
40
41
# File 'lib/riffer/stream_events/guardrail_tripwire.rb', line 39

def guardrail_id
  tripwire.guardrail_id
end

#phaseObject

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

: () -> Symbol



32
33
34
# File 'lib/riffer/stream_events/guardrail_tripwire.rb', line 32

def phase
  tripwire.phase
end

#reasonObject

The reason for blocking.

: () -> String



25
26
27
# File 'lib/riffer/stream_events/guardrail_tripwire.rb', line 25

def reason
  tripwire.reason
end

#to_hObject

Converts the event to a hash.

: () -> Hash[Symbol, untyped]



46
47
48
49
50
51
# File 'lib/riffer/stream_events/guardrail_tripwire.rb', line 46

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