class Riffer::Rig::Loader
Public Class Methods
(cwd: String, host: Riffer::Rig::Hosts::_Host, ?env: Riffer::Rig::Env | Riffer::Rig::Env::Invalid, ?home: String, ?riffer_config: Riffer::Config, ?store: Riffer::Rig::Stores::_Store | nil, ?sdk: singleton(Riffer::Rig::SDK)) → void
Source
# File lib/riffer/rig/loader.rb, line 50 def initialize( cwd:, host:, env: Riffer::Rig::Env.load, home: Dir.home, riffer_config: Riffer.config, store: Riffer::Rig::Stores::JSONL.new(home: home), sdk: Riffer::Rig::SDK ) raise ConfigurationError, env.message if env.is_a?(Riffer::Rig::Env::Invalid) @cwd = cwd @host = host @env = env @home = home @riffer_config = riffer_config @store = store @sdk = sdk @source = Riffer::Rig::Loader::ExtensionSource.new(cwd: cwd, home: home, host: host) @reloaders = ObjectSpace::WeakKeyMap.new end
@rbs cwd: String @rbs host: Riffer::Rig::Hosts::_Host @rbs env: Riffer::Rig::Env | Riffer::Rig::Env::Invalid @rbs home: String @rbs riffer_config: Riffer::Config @rbs store: Riffer::Rig::Stores::_Store | nil @rbs sdk: singleton(Riffer::Rig::SDK) @rbs return: void
(cwd: String, host: Riffer::Rig::Hosts::_Host, ?env: Riffer::Rig::Env | Riffer::Rig::Env::Invalid, ?home: String, ?riffer_config: Riffer::Config, ?store: Riffer::Rig::Stores::_Store | nil, ?options: Riffer::Rig::Loader::Options, ?reload: :auto | :manual | nil, ?extra_extensions: Array[Riffer::Rig::Extension], ?snapshot: (Riffer::Rig::Runtime::Snapshot | Hash[Symbol, untyped])?) → Riffer::Rig::Runtime
Source
# File lib/riffer/rig/loader.rb, line 27 def self.runtime( cwd:, host:, env: Riffer::Rig::Env.load, home: Dir.home, riffer_config: Riffer.config, store: Riffer::Rig::Stores::JSONL.new(home: home), options: Options.new, reload: nil, extra_extensions: [], snapshot: nil ) new(cwd:, host:, env:, home:, riffer_config:, store:).runtime(options, reload:, extra_extensions:, snapshot:) end
@rbs cwd: String @rbs host: Riffer::Rig::Hosts::_Host @rbs env: Riffer::Rig::Env | Riffer::Rig::Env::Invalid @rbs home: String @rbs riffer_config: Riffer::Config @rbs store: Riffer::Rig::Stores::_Store | nil @rbs options: Riffer::Rig::Loader::Options @rbs reload: (:auto | :manual | nil) @rbs extra_extensions: Array @rbs snapshot: (Riffer::Rig::Runtime::Snapshot | Hash[Symbol, untyped])? @rbs return: Riffer::Rig::Runtime
Public Instance Methods
Source
# File lib/riffer/rig/loader.rb, line 141 def continue(options = Options.new) store = @store return nil unless store latest = store.list(cwd: @cwd).max_by { |header| header.updated || Time.at(0) } return nil unless latest resume(latest.id, options) end
@rbs options: Riffer::Rig::Loader::Options @rbs return: Riffer::Rig::Runtime?
(String id) → void
Source
# File lib/riffer/rig/loader.rb, line 187 def delete(id) store = @store return unless store store.delete(id) end
@rbs id: String @rbs return: void
(?all: bool) → Array[::Riffer::Rig::Stores::Header]
Source
# File lib/riffer/rig/loader.rb, line 178 def list(all: false) store = @store return [] unless store all ? store.list : store.list(cwd: @cwd) end
@rbs all: bool @rbs return: Array
(String id) → Array[Hash[Symbol, untyped]]
Source
# File lib/riffer/rig/loader.rb, line 169 def messages(id) store = @store return [] unless store Riffer::Rig::Stores::Entries.messages(store.read(id)) end
A host tier may not name the store, so the messages it replays come from here, in the order they were recorded. @rbs id: String @rbs return: Array[Hash[Symbol, untyped]]
(Riffer::Rig::Runtime runtime, ?force: bool) → (Riffer::Rig::Runtime | String)
Source
# File lib/riffer/rig/loader.rb, line 197 def reload(runtime, force: false) reloader = @reloaders[runtime] reloader ? reloader.reload(runtime, force: force) : runtime end
@rbs runtime: Riffer::Rig::Runtime @rbs force: bool @rbs return: (Riffer::Rig::Runtime | String)
(String id, ?Riffer::Rig::Loader::Options options, ?extra_extensions: Array[Riffer::Rig::Extension]) → Riffer::Rig::Runtime?
Source
# File lib/riffer/rig/loader.rb, line 155 def resume(id, options = Options.new, extra_extensions: []) store = @store return nil unless store entries = store.read(id) return nil if entries.empty? runtime(options, extra_extensions: extra_extensions, snapshot: Riffer::Rig::Stores::Entries.snapshot(entries, id)) end
@rbs id: String @rbs options: Riffer::Rig::Loader::Options @rbs extra_extensions: Array @rbs return: Riffer::Rig::Runtime?
(?Riffer::Rig::Loader::Options options, ?reload: :auto | :manual | nil, ?extra_extensions: Array[Riffer::Rig::Extension], ?snapshot: (Riffer::Rig::Runtime::Snapshot | Hash[Symbol, untyped])?) → Riffer::Rig::Runtime
Source
# File lib/riffer/rig/loader.rb, line 77 def runtime(options = Options.new, reload: nil, extra_extensions: [], snapshot: nil) settings = merged_settings raise ConfigurationError, settings if settings.is_a?(String) document = Riffer::Rig::Settings::Document.new(settings) selected = select_model(options.model || @env.model || document.model) rejection = Riffer::Rig::Loader::Reasoning.rejection(options.reasoning, @env.reasoning) raise ConfigurationError, rejection if rejection provider = Riffer::Rig::Settings::ModelOptions.provider_for(selected).to_s ensure_sdk(provider) credentials = install_credentials(provider) raise ConfigurationError, credentials if credentials.is_a?(String) @riffer_config.catalog_files = document.catalog_files stripped = { skills: options.skills, agents_md: options.agents_md }.reject { |_name, kept| kept }.keys discovered = options.extensions ? @source.discover(autoload: document.autoload) : [] #: Array[Riffer::Rig::Extension] saved = snapshot && Riffer::Rig::Runtime::Snapshot.of(snapshot) recorder = recorder_for(document, resumed: !saved.nil?) recording = recorder ? [Riffer::Rig::Stores::Recorder.extension(recorder)] : [] #: Array[Riffer::Rig::Extension] saved = snapshot_without_forced(saved, options) built = Riffer::Rig::Runtime.new( selected, extensions: bundled(document, stripped) + discovered + extra_extensions + recording, tools: options.tools, settings: settings, host: @host, cwd: @cwd, max_steps: options.max_steps, credentials: { provider.to_sym => credentials }, env: @env, auth_path: home_auth_path, settings_path: home_settings_path, reasoning: Riffer::Rig::Loader::Reasoning.forced(options.reasoning, @env.reasoning), riffer_config: @riffer_config, model_options: Riffer::Rig::Settings::ModelOptions.model_options(selected), native_tools: document.native_tools, snapshot: saved ) reloader = Riffer::Rig::Loader::Reloader.new( source: @source, host: @host, settings: -> { merged_settings }, credentials: ->(name) { install_credentials(name) }, extensions: ->(current, found) { bundled(current, stripped) + extra_extensions + found + recording }, rediscovers: options.extensions, mode: reload ) @reloaders[built] = reloader built.install_command(Riffer::Rig::Commands::Reload.command(reloader)) store = @store built.install_command(Riffer::Rig::Commands::Trace.command(store)) if store && recorder unless (reload || document.reload) == :manual built.install_reload_check(->(runtime) { _ = reloader.reload(runtime) }) end recorder&.attach(built) built end
@rbs options: Riffer::Rig::Loader::Options @rbs reload: (:auto | :manual | nil) @rbs extra_extensions: Array @rbs snapshot: (Riffer::Rig::Runtime::Snapshot | Hash[Symbol, untyped])? @rbs return: Riffer::Rig::Runtime