Class: Yorishiro::SessionResume
- Inherits:
-
Object
- Object
- Yorishiro::SessionResume
- Defined in:
- lib/yorishiro/session_resume.rb
Overview
Interactive session-resume flows shared by the --continue/--resume CLI flags and the /resume command. Applies the chosen session to the conversation and returns its id, or nil when nothing was resumed (the caller keeps its current session in that case).
Instance Method Summary collapse
- #continue_latest ⇒ Object
-
#initialize(store:, conversation:, output:, current_target:) ⇒ SessionResume
constructor
A new instance of SessionResume.
- #pick ⇒ Object
- #resume_by_id(id) ⇒ Object
Constructor Details
#initialize(store:, conversation:, output:, current_target:) ⇒ SessionResume
Returns a new instance of SessionResume.
11 12 13 14 15 16 |
# File 'lib/yorishiro/session_resume.rb', line 11 def initialize(store:, conversation:, output:, current_target:) @store = store @conversation = conversation @output = output @current_target = current_target # "provider:model" of the running CLI end |
Instance Method Details
#continue_latest ⇒ Object
18 19 20 |
# File 'lib/yorishiro/session_resume.rb', line 18 def continue_latest apply(@store.latest, missing: "No previous session found. Starting a new one.") end |
#pick ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/yorishiro/session_resume.rb', line 26 def pick sessions = @store.list if sessions.empty? @output.puts "[i] No saved sessions." return nil end print_list(sessions) answer = Reline.readline("Select session [1-#{sessions.length}]: ", false)&.strip index = answer.to_i unless index.between?(1, sessions.length) @output.puts "Cancelled." return nil end apply(sessions[index - 1]) end |
#resume_by_id(id) ⇒ Object
22 23 24 |
# File 'lib/yorishiro/session_resume.rb', line 22 def resume_by_id(id) apply(@store.load(id), missing: "Session not found: #{id}") end |