Skip to content
Kward Search API index

Class: Kward::Transport::Host::PluginChat

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

Overview

Narrow plugin-chat operations exposed to a transport.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, handle, actor) ⇒ PluginChat

Returns a new instance of PluginChat.



211
212
213
214
215
216
217
218
# File 'lib/kward/transport/host.rb', line 211

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

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



209
210
211
# File 'lib/kward/transport/host.rb', line 209

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



209
210
211
# File 'lib/kward/transport/host.rb', line 209

def name
  @name
end

#scope_keyObject (readonly)

Returns the value of attribute scope_key.



209
210
211
# File 'lib/kward/transport/host.rb', line 209

def scope_key
  @scope_key
end

#type_idObject (readonly)

Returns the value of attribute type_id.



209
210
211
# File 'lib/kward/transport/host.rb', line 209

def type_id
  @type_id
end

Instance Method Details

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



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/kward/transport/host.rb', line 220

def start_turn(input, attachments: [], options: {}, streaming_behavior: nil)
  @host.authorize!(:start_plugin_chat_turn, actor: @actor, chat_id: @id, type_id: @type_id, input: input.to_s)
  if @host.execution_profile && !@host.execution_profile.attachments && !Array(attachments).empty?
    raise PolicyDenied, "Transport execution profile does not allow attachments"
  end
  unless options.nil? || options.empty?
    raise ArgumentError, "plugin chat turns do not support options"
  end
  unless streaming_behavior.nil? || %i[aggregate none].include?(streaming_behavior.to_sym)
    raise ArgumentError, "plugin chat turns do not support #{streaming_behavior} streaming"
  end

  result = @host.plugin_chat_gateway.start_transport_plugin_chat_turn(
    chat_id: @id,
    actor: @actor,
    input: input,
    attachments: attachments,
    streaming_behavior: streaming_behavior,
    execution_profile: @host.execution_profile
  )
  handle = result.is_a?(PluginChatTurnHandle) ? result : PluginChatTurnHandle.new(**result.transform_keys(&:to_sym))
  PluginChatTurn.new(@host, handle, @actor)
end

#transcriptObject



244
245
246
247
# File 'lib/kward/transport/host.rb', line 244

def transcript
  @host.authorize!(:read_plugin_chat_transcript, actor: @actor, chat_id: @id, type_id: @type_id)
  @host.plugin_chat_gateway.transport_plugin_chat_transcript(chat_id: @id)
end