Class: ActiveMatrix::Agent
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ActiveMatrix::Agent
- Defined in:
- app/models/active_matrix/agent.rb,
app/models/active_matrix/agent/jobs/memory_reaper.rb
Defined Under Namespace
Modules: Jobs
Instance Attribute Summary collapse
-
#password ⇒ Object
Password handling.
Instance Method Summary collapse
- #authenticate(password) ⇒ Object
-
#bot_instance ⇒ Object
Instance methods.
-
#client ⇒ Object
Returns a Matrix client using resolved connection config Resolution order: 1.
-
#connection_config ⇒ Hash
Returns the resolved connection configuration.
- #increment_messages_handled! ⇒ Object
- #memory ⇒ Object
- #running? ⇒ Boolean
- #update_activity! ⇒ Object
Instance Attribute Details
#password ⇒ Object
Password handling
153 154 155 |
# File 'app/models/active_matrix/agent.rb', line 153 def password @password end |
Instance Method Details
#authenticate(password) ⇒ Object
155 156 157 158 159 |
# File 'app/models/active_matrix/agent.rb', line 155 def authenticate(password) return false if encrypted_password.blank? BCrypt::Password.new(encrypted_password) == password end |
#bot_instance ⇒ Object
Instance methods
110 111 112 |
# File 'app/models/active_matrix/agent.rb', line 110 def bot_instance @bot_instance ||= bot_class.constantize.new(client) if running? end |
#client ⇒ Object
Returns a Matrix client using resolved connection config Resolution order:
1. matrix_connection → lookup from config/active_matrix.yml
2. Inline credentials (homeserver, access_token) → user-uploaded bots
118 119 120 |
# File 'app/models/active_matrix/agent.rb', line 118 def client @client ||= build_client end |
#connection_config ⇒ Hash
Returns the resolved connection configuration
124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/models/active_matrix/agent.rb', line 124 def connection_config if matrix_connection.present? ActiveMatrix.connection(matrix_connection) else { homeserver_url: homeserver, access_token: access_token, username: username }.compact end end |
#increment_messages_handled! ⇒ Object
144 145 146 |
# File 'app/models/active_matrix/agent.rb', line 144 def update!(messages_handled: + 1) end |
#memory ⇒ Object
140 141 142 |
# File 'app/models/active_matrix/agent.rb', line 140 def memory @memory ||= ActiveMatrix::Memory::AgentMemory.new(self) end |
#running? ⇒ Boolean
136 137 138 |
# File 'app/models/active_matrix/agent.rb', line 136 def running? %i[online_idle online_busy].include?(state.to_sym) end |
#update_activity! ⇒ Object
148 149 150 |
# File 'app/models/active_matrix/agent.rb', line 148 def update_activity! update(last_active_at: Time.current) end |