Class: Kreator::RPCServer

Inherits:
Object
  • Object
show all
Defined in:
lib/kreator/rpc_server.rb

Defined Under Namespace

Classes: Config

Constant Summary collapse

RPC_COMMANDS =
{
  "prompt" => :handle_prompt,
  "abort" => :handle_abort_command,
  "get_state" => :handle_get_state_command,
  "get_messages" => :handle_get_messages_command,
  "search_sessions" => :handle_search_sessions_command,
  "label_session" => :handle_label_session_command,
  "export_session" => :handle_export_session_command,
  "cleanup_sessions" => :handle_cleanup_sessions_command,
  "get_resources" => :handle_get_resources_command,
  "plugin_list" => :handle_plugin_list_command,
  "plugin_validate" => :handle_plugin_validate_command,
  "plugin_install" => :handle_plugin_install_command,
  "plugin_update" => :handle_plugin_update_command,
  "plugin_remove" => :handle_plugin_remove_command,
  "list_branches" => :handle_list_branches_command,
  "fork_session" => :handle_fork_session_command,
  "new_session" => :handle_new_session_command,
  "set_model" => :handle_set_model_command
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) ⇒ RPCServer

Returns a new instance of RPCServer.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/kreator/rpc_server.rb', line 44

def initialize(config = nil, **)
  config ||= Config.new(**)
  @provider_builder = config.provider_builder
  @provider_name = config.provider_name
  @model = config.model
  @tools = config.tools
  @context = config.context
  @session_manager = config.session_manager
  @session = config.session
  @stdin = config.stdin
  @stdout = config.stdout
  @resources = config.resources || Resources.new
  @compact_threshold = config.compact_threshold
  @messages = session&.messages || []
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



7
8
9
# File 'lib/kreator/rpc_server.rb', line 7

def context
  @context
end

#modelObject (readonly)

Returns the value of attribute model.



7
8
9
# File 'lib/kreator/rpc_server.rb', line 7

def model
  @model
end

#provider_builderObject (readonly)

Returns the value of attribute provider_builder.



7
8
9
# File 'lib/kreator/rpc_server.rb', line 7

def provider_builder
  @provider_builder
end

#provider_nameObject (readonly)

Returns the value of attribute provider_name.



7
8
9
# File 'lib/kreator/rpc_server.rb', line 7

def provider_name
  @provider_name
end

#resourcesObject (readonly)

Returns the value of attribute resources.



7
8
9
# File 'lib/kreator/rpc_server.rb', line 7

def resources
  @resources
end

#sessionObject (readonly)

Returns the value of attribute session.



7
8
9
# File 'lib/kreator/rpc_server.rb', line 7

def session
  @session
end

#session_managerObject (readonly)

Returns the value of attribute session_manager.



7
8
9
# File 'lib/kreator/rpc_server.rb', line 7

def session_manager
  @session_manager
end

#toolsObject (readonly)

Returns the value of attribute tools.



7
8
9
# File 'lib/kreator/rpc_server.rb', line 7

def tools
  @tools
end

Instance Method Details

#runObject



60
61
62
63
64
65
66
67
68
# File 'lib/kreator/rpc_server.rb', line 60

def run
  @stdin.each_line do |line|
    line = line.strip
    next if line.empty?

    handle_line(line)
  end
  0
end