Class: Askcii::Commands::ListSessionsCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/askcii/commands/list_sessions_command.rb

Overview

Lists all available chat sessions

Instance Attribute Summary

Attributes inherited from BaseCommand

#cli, #config

Instance Method Summary collapse

Methods inherited from BaseCommand

#initialize

Constructor Details

This class inherits a constructor from Askcii::Commands::BaseCommand

Instance Method Details

#executeObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/askcii/commands/list_sessions_command.rb', line 7

def execute
  verbose "Listing all sessions..."

  chats = Chat.order(Sequel.desc(:created_at)).all

  if chats.empty?
    puts "No sessions found."
    exit 0
  end

  puts "Available sessions:"
  puts

  chats.each do |chat|
    message_count = chat.messages.count
    last_message = chat.messages_dataset.order(Sequel.desc(:created_at)).first
    last_updated = last_message&.created_at || chat.created_at

    puts "Session: #{chat.context}"
    puts "  Model: #{chat.model_id}"
    puts "  Messages: #{message_count}"
    puts "  Last updated: #{last_updated}"
    puts
  end

  exit 0
end