Class: PromptObjects::Repositories::ThreadRepository
- Inherits:
-
BaseRepository
- Object
- BaseRepository
- PromptObjects::Repositories::ThreadRepository
- Defined in:
- lib/prompt_objects/repositories/thread_repository.rb
Instance Method Summary collapse
- #archive(id) ⇒ Object
- #create(workspace_session_id:, po_name:, thread_type:, name: nil, parent_thread_id: nil, parent_run_id: nil, retention_policy: nil, source: "web", id: SecureRandom.uuid) ⇒ Object
- #get(id) ⇒ Object
- #list(workspace_session_id:, po_name: nil, include_archived: false) ⇒ Object
- #rename(id, name) ⇒ Object
Methods inherited from BaseRepository
Constructor Details
This class inherits a constructor from PromptObjects::Repositories::BaseRepository
Instance Method Details
#archive(id) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/prompt_objects/repositories/thread_repository.rb', line 45 def archive(id) now = Time.now.utc.iso8601 transaction do |db| db.execute("UPDATE sessions SET archived = 1, updated_at = ? WHERE id = ?", [now, id]) end get(id) end |
#create(workspace_session_id:, po_name:, thread_type:, name: nil, parent_thread_id: nil, parent_run_id: nil, retention_policy: nil, source: "web", id: SecureRandom.uuid) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/prompt_objects/repositories/thread_repository.rb', line 6 def create(workspace_session_id:, po_name:, thread_type:, name: nil, parent_thread_id: nil, parent_run_id: nil, retention_policy: nil, source: "web", id: SecureRandom.uuid) validate_thread_type!(thread_type) now = Time.now.utc.iso8601 transaction do |db| params = [ id, po_name, name, source, source, now, now, parent_thread_id, po_name_for_parent(db, parent_thread_id), thread_type, workspace_session_id, parent_run_id, retention_policy, now ] db.execute(<<~SQL, params) INSERT INTO sessions ( id, po_name, name, source, last_message_source, created_at, updated_at, parent_session_id, parent_po, thread_type, session_type, workspace_session_id, parent_run_id, retention_policy, archived, last_activity_at ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'thread', ?, ?, ?, 0, ?) SQL end get(id) end |
#get(id) ⇒ Object
28 29 30 31 |
# File 'lib/prompt_objects/repositories/thread_repository.rb', line 28 def get(id) row = read { |db| db.get_first_row("SELECT * FROM sessions WHERE id = ? AND po_name IS NOT NULL", [id]) } row && parse(row) end |
#list(workspace_session_id:, po_name: nil, include_archived: false) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/prompt_objects/repositories/thread_repository.rb', line 33 def list(workspace_session_id:, po_name: nil, include_archived: false) conditions = ["workspace_session_id = ?", "po_name IS NOT NULL"] params = [workspace_session_id] if po_name conditions << "po_name = ?" params << po_name end conditions << "archived = 0" unless include_archived sql = "SELECT * FROM sessions WHERE #{conditions.join(' AND ')} ORDER BY updated_at DESC" read { |db| db.execute(sql, params) }.map { |row| parse(row) } end |
#rename(id, name) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/prompt_objects/repositories/thread_repository.rb', line 53 def rename(id, name) now = Time.now.utc.iso8601 transaction do |db| db.execute("UPDATE sessions SET name = ?, updated_at = ? WHERE id = ?", [name, now, id]) end get(id) end |