Class: RubynCode::IDE::Handlers::SessionListHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyn_code/ide/handlers/session_list_handler.rb

Overview

Handles the “session/list” JSON-RPC request.

Returns a list of past sessions from SessionPersistence, optionally filtered by project path. If SessionPersistence is not available (e.g. no database configured), returns an empty sessions array.

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ SessionListHandler

Returns a new instance of SessionListHandler.



12
13
14
# File 'lib/rubyn_code/ide/handlers/session_list_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
# File 'lib/rubyn_code/ide/handlers/session_list_handler.rb', line 16

def call(params)
  persistence = @server.session_persistence
  unless persistence
    return { 'sessions' => [] }
  end

  project_path = params['projectPath']
  limit = params['limit'] || 20

  summaries = persistence.list_sessions(project_path: project_path, limit: limit)

  sessions = summaries.map do |s|
    {
      'id' => s[:id],
      'title' => s[:title],
      'updatedAt' => s[:updated_at],
      'messageCount' => (s[:metadata] || {})[:message_count] || 0
    }
  end

  { 'sessions' => sessions }
end