ruby_llm-agents 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9c413f46174a6ad550e9ff2a676c92e116d6a8199cc3ff1c8ecb24e48b89b53
4
- data.tar.gz: e4def5034b05f731418622879f15ee8e77be73534e239855612770874545da29
3
+ metadata.gz: 4b7e7cfee5a40b023b0894c44feded232df6e537cd0168ed8605e6e01cbfbba1
4
+ data.tar.gz: 49940010e98428b37f6fe5dd8959e1f235d6706ca30a84b5100ac1febe80186a
5
5
  SHA512:
6
- metadata.gz: 9926a9f54daef58388cc5f6fabbacaf3dbaf3d03f590ef97dc81d180dd3ccb53153f78ec54c8a32247d1abc18c19084a04bf2b31b1378109dd76d159e84bff6a
7
- data.tar.gz: 225a42a4f27f25f41b84521df11464e1bdb64ddbbddc6d8c7476d2039bddc9ddaa9ad96078aeb9e13bddd79ef1ba88a1697b8abb82a9b6239b8b5d00a836e8c0
6
+ metadata.gz: d7ed0784184463044fe36690011a63e0cb9801aec443d21e7ded53c16090c41086ae5529860ce9f3b92fce7e1c78b60f9566c6309e03acae64764e2f08dcfe81
7
+ data.tar.gz: 1f3dfaf1ba66129ce6d23f090288757ca7b445d34ba553abb80d403d6becf4246e412241a395dd4e00d44c0f2d6826d8e0ff90d40f4fa3e4aa2942f0b10597db
@@ -10,10 +10,27 @@ module RubyLLM
10
10
  private
11
11
 
12
12
  def authenticate_dashboard!
13
- auth_proc = RubyLLM::Agents.configuration.dashboard_auth
14
- return if auth_proc.call(self)
13
+ if basic_auth_configured?
14
+ authenticate_with_http_basic_auth
15
+ else
16
+ auth_proc = RubyLLM::Agents.configuration.dashboard_auth
17
+ return if auth_proc.call(self)
15
18
 
16
- render plain: "Unauthorized", status: :unauthorized
19
+ render plain: "Unauthorized", status: :unauthorized
20
+ end
21
+ end
22
+
23
+ def basic_auth_configured?
24
+ config = RubyLLM::Agents.configuration
25
+ config.basic_auth_username.present? && config.basic_auth_password.present?
26
+ end
27
+
28
+ def authenticate_with_http_basic_auth
29
+ config = RubyLLM::Agents.configuration
30
+ authenticate_or_request_with_http_basic("RubyLLM Agents") do |username, password|
31
+ ActiveSupport::SecurityUtils.secure_compare(username, config.basic_auth_username) &&
32
+ ActiveSupport::SecurityUtils.secure_compare(password, config.basic_auth_password)
33
+ end
17
34
  end
18
35
  end
19
36
  end
@@ -27,8 +27,13 @@ RubyLLM::Agents.configure do |config|
27
27
  # config.anomaly_cost_threshold = 5.00 # dollars
28
28
  # config.anomaly_duration_threshold = 10_000 # milliseconds
29
29
 
30
- # Dashboard authentication
30
+ # HTTP Basic Auth (simple username/password protection)
31
+ # config.basic_auth_username = "admin"
32
+ # config.basic_auth_password = Rails.application.credentials.agents_password
33
+
34
+ # Dashboard authentication (advanced - custom logic)
31
35
  # Return true to allow access, false to deny
36
+ # Note: If basic_auth_username/password are set, they take precedence
32
37
  # config.dashboard_auth = ->(controller) { controller.current_user&.admin? }
33
38
 
34
39
  # Parent controller for dashboard (for authentication/layout inheritance)
@@ -11,7 +11,9 @@ module RubyLLM
11
11
  :anomaly_cost_threshold,
12
12
  :anomaly_duration_threshold,
13
13
  :dashboard_auth,
14
- :dashboard_parent_controller
14
+ :dashboard_parent_controller,
15
+ :basic_auth_username,
16
+ :basic_auth_password
15
17
 
16
18
  attr_writer :cache_store
17
19
 
@@ -26,6 +28,8 @@ module RubyLLM
26
28
  @anomaly_duration_threshold = 10_000
27
29
  @dashboard_auth = ->(_controller) { true }
28
30
  @dashboard_parent_controller = "ActionController::Base"
31
+ @basic_auth_username = nil
32
+ @basic_auth_password = nil
29
33
  end
30
34
 
31
35
  def cache_store
@@ -11,6 +11,43 @@ module RubyLLM
11
11
  require_relative "execution_logger_job"
12
12
  require_relative "instrumentation"
13
13
  require_relative "base"
14
+
15
+ # Dynamically set parent controller based on configuration
16
+ parent_class = RubyLLM::Agents.configuration.dashboard_parent_controller.constantize
17
+
18
+ # Remove existing constant if defined, then redefine with correct parent
19
+ RubyLLM::Agents.send(:remove_const, :ApplicationController) if RubyLLM::Agents.const_defined?(:ApplicationController, false)
20
+
21
+ RubyLLM::Agents.const_set(:ApplicationController, Class.new(parent_class) do
22
+ layout "rubyllm/agents/application"
23
+ before_action :authenticate_dashboard!
24
+
25
+ private
26
+
27
+ def authenticate_dashboard!
28
+ if basic_auth_configured?
29
+ authenticate_with_http_basic_auth
30
+ else
31
+ auth_proc = RubyLLM::Agents.configuration.dashboard_auth
32
+ return if auth_proc.call(self)
33
+
34
+ render plain: "Unauthorized", status: :unauthorized
35
+ end
36
+ end
37
+
38
+ def basic_auth_configured?
39
+ config = RubyLLM::Agents.configuration
40
+ config.basic_auth_username.present? && config.basic_auth_password.present?
41
+ end
42
+
43
+ def authenticate_with_http_basic_auth
44
+ config = RubyLLM::Agents.configuration
45
+ authenticate_or_request_with_http_basic("RubyLLM Agents") do |username, password|
46
+ ActiveSupport::SecurityUtils.secure_compare(username, config.basic_auth_username) &&
47
+ ActiveSupport::SecurityUtils.secure_compare(password, config.basic_auth_password)
48
+ end
49
+ end
50
+ end)
14
51
  end
15
52
 
16
53
  # Configure generators
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RubyLLM
4
4
  module Agents
5
- VERSION = "0.2.2"
5
+ VERSION = "0.2.3"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_llm-agents
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - adham90