Skip to content
Kward Search API index

Class: Kward::Transport::Host::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/kward/transport/host.rb

Overview

Narrow session operations exposed to a transport.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, handle, actor) ⇒ Session

Returns a new instance of Session.



128
129
130
131
132
133
134
# File 'lib/kward/transport/host.rb', line 128

def initialize(host, handle, actor)
  @host = host
  @actor = actor
  @id = handle.id.to_s.freeze
  @workspace_root = handle.workspace_root.to_s.freeze
  @name = handle.name&.to_s&.freeze
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



126
127
128
# File 'lib/kward/transport/host.rb', line 126

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



126
127
128
# File 'lib/kward/transport/host.rb', line 126

def name
  @name
end

#workspace_rootObject (readonly)

Returns the value of attribute workspace_root.



126
127
128
# File 'lib/kward/transport/host.rb', line 126

def workspace_root
  @workspace_root
end

Instance Method Details

#answer_interaction(request_id:, answer:) ⇒ Object



155
156
157
158
159
160
161
162
# File 'lib/kward/transport/host.rb', line 155

def answer_interaction(request_id:, answer:)
  if @host.execution_profile&.approval_mode == :deny
    raise PolicyDenied, "Transport execution profile does not allow interactions"
  end

  @host.authorize!(:answer_interaction, actor: @actor, session_id: @id, request_id: request_id)
  @host.gateway.answer_transport_interaction(session_id: @id, request_id: request_id, answer: answer)
end

#start_turn(input, attachments: [], options: {}, streaming_behavior: nil) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/kward/transport/host.rb', line 136

def start_turn(input, attachments: [], options: {}, streaming_behavior: nil)
  @host.authorize!(:start_turn, actor: @actor, session_id: @id, input: input.to_s)
  result = @host.gateway.start_transport_turn(
    session_id: @id,
    input: input.to_s,
    attachments: attachments,
    options: options,
    streaming_behavior: streaming_behavior,
    execution_profile: @host.execution_profile
  )
  handle = result.is_a?(TurnHandle) ? result : TurnHandle.new(**result.transform_keys(&:to_sym))
  Turn.new(@host, handle, @actor)
end

#transcriptObject



150
151
152
153
# File 'lib/kward/transport/host.rb', line 150

def transcript
  @host.authorize!(:read_transcript, actor: @actor, session_id: @id)
  @host.gateway.transport_transcript(session_id: @id)
end