Class: RubynCode::IDE::Handlers::SessionResumeHandler
- Inherits:
-
Object
- Object
- RubynCode::IDE::Handlers::SessionResumeHandler
- Defined in:
- lib/rubyn_code/ide/handlers/session_resume_handler.rb
Overview
Handles the “session/resume” JSON-RPC request.
Loads a previously persisted session from SessionPersistence and pre-populates the PromptHandler’s conversation cache so that the next prompt continues from where the session left off.
Instance Method Summary collapse
- #call(params) ⇒ Object
-
#initialize(server) ⇒ SessionResumeHandler
constructor
A new instance of SessionResumeHandler.
Constructor Details
#initialize(server) ⇒ SessionResumeHandler
Returns a new instance of SessionResumeHandler.
12 13 14 |
# File 'lib/rubyn_code/ide/handlers/session_resume_handler.rb', line 12 def initialize(server) @server = server end |
Instance Method Details
#call(params) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rubyn_code/ide/handlers/session_resume_handler.rb', line 16 def call(params) session_id = params['sessionId'] return { 'resumed' => false, 'error' => 'Missing sessionId' } unless session_id persistence = @server.session_persistence return { 'resumed' => false, 'error' => 'Session persistence not available' } unless persistence data = persistence.load_session(session_id) return { 'resumed' => false, 'error' => 'Session not found' } unless data = data[:messages] || [] # Pre-populate the prompt handler's conversation cache so the next # prompt picks up from the restored history. prompt = @server.handler_instance(:prompt) if prompt conversation = Agent::Conversation.new .each { |msg| conversation. << msg } prompt.inject_conversation(session_id, conversation) end { 'resumed' => true, 'sessionId' => session_id, 'messages' => } end |