Class: Bugsage::Configuration
- Inherits:
-
Object
- Object
- Bugsage::Configuration
- Defined in:
- lib/bugsage/configuration.rb
Constant Summary collapse
- AI_PROVIDERS =
%i[openai cursor].freeze
Instance Attribute Summary collapse
-
#ai_client ⇒ Object
Returns the value of attribute ai_client.
-
#ai_enabled ⇒ Object
Returns the value of attribute ai_enabled.
-
#ai_provider ⇒ Object
Returns the value of attribute ai_provider.
-
#ai_timeout ⇒ Object
Returns the value of attribute ai_timeout.
-
#capture_errors ⇒ Object
Returns the value of attribute capture_errors.
-
#capture_http_errors ⇒ Object
Returns the value of attribute capture_http_errors.
-
#cursor_api_base ⇒ Object
Returns the value of attribute cursor_api_base.
-
#cursor_api_key ⇒ Object
Returns the value of attribute cursor_api_key.
-
#cursor_model ⇒ Object
Returns the value of attribute cursor_model.
-
#enabled_environments ⇒ Object
Returns the value of attribute enabled_environments.
-
#fallback_exceptions_app ⇒ Object
Returns the value of attribute fallback_exceptions_app.
-
#openai_api_base ⇒ Object
Returns the value of attribute openai_api_base.
-
#openai_api_key ⇒ Object
Returns the value of attribute openai_api_key.
-
#openai_model ⇒ Object
Returns the value of attribute openai_model.
-
#show_dashboard ⇒ Object
Returns the value of attribute show_dashboard.
-
#show_error_page ⇒ Object
Returns the value of attribute show_error_page.
-
#show_inline_console ⇒ Object
Returns the value of attribute show_inline_console.
Instance Method Summary collapse
- #ai_configured?(environment = current_environment) ⇒ Boolean
- #ai_enabled?(environment = current_environment) ⇒ Boolean
- #capture_errors?(environment = current_environment) ⇒ Boolean
- #capture_http_errors?(environment = current_environment) ⇒ Boolean
- #credential_available? ⇒ Boolean
- #current_environment ⇒ Object
- #effective_ai_timeout ⇒ Object
- #enabled?(environment = current_environment) ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #resolved_ai_provider ⇒ Object
- #resolved_cursor_api_key ⇒ Object
- #resolved_openai_api_key ⇒ Object
- #show_dashboard?(environment = current_environment) ⇒ Boolean
- #show_error_page?(environment = current_environment) ⇒ Boolean
- #show_inline_console?(environment = current_environment) ⇒ Boolean
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bugsage/configuration.rb', line 25 def initialize @enabled_environments = %i[development test] @show_error_page = nil @show_dashboard = nil @show_inline_console = nil @capture_errors = true @capture_http_errors = true @ai_enabled = nil @ai_provider = nil @openai_api_key = nil @openai_model = "gpt-4o-mini" @openai_api_base = "https://api.openai.com/v1" @cursor_api_key = nil @cursor_model = nil @cursor_api_base = "https://api.cursor.com" @ai_timeout = 15 @ai_client = nil @fallback_exceptions_app = nil end |
Instance Attribute Details
#ai_client ⇒ Object
Returns the value of attribute ai_client.
7 8 9 |
# File 'lib/bugsage/configuration.rb', line 7 def ai_client @ai_client end |
#ai_enabled ⇒ Object
Returns the value of attribute ai_enabled.
7 8 9 |
# File 'lib/bugsage/configuration.rb', line 7 def ai_enabled @ai_enabled end |
#ai_provider ⇒ Object
Returns the value of attribute ai_provider.
7 8 9 |
# File 'lib/bugsage/configuration.rb', line 7 def ai_provider @ai_provider end |
#ai_timeout ⇒ Object
Returns the value of attribute ai_timeout.
7 8 9 |
# File 'lib/bugsage/configuration.rb', line 7 def ai_timeout @ai_timeout end |
#capture_errors ⇒ Object
Returns the value of attribute capture_errors.
7 8 9 |
# File 'lib/bugsage/configuration.rb', line 7 def capture_errors @capture_errors end |
#capture_http_errors ⇒ Object
Returns the value of attribute capture_http_errors.
7 8 9 |
# File 'lib/bugsage/configuration.rb', line 7 def capture_http_errors @capture_http_errors end |
#cursor_api_base ⇒ Object
Returns the value of attribute cursor_api_base.
7 8 9 |
# File 'lib/bugsage/configuration.rb', line 7 def cursor_api_base @cursor_api_base end |
#cursor_api_key ⇒ Object
Returns the value of attribute cursor_api_key.
7 8 9 |
# File 'lib/bugsage/configuration.rb', line 7 def cursor_api_key @cursor_api_key end |
#cursor_model ⇒ Object
Returns the value of attribute cursor_model.
7 8 9 |
# File 'lib/bugsage/configuration.rb', line 7 def cursor_model @cursor_model end |
#enabled_environments ⇒ Object
Returns the value of attribute enabled_environments.
7 8 9 |
# File 'lib/bugsage/configuration.rb', line 7 def enabled_environments @enabled_environments end |
#fallback_exceptions_app ⇒ Object
Returns the value of attribute fallback_exceptions_app.
7 8 9 |
# File 'lib/bugsage/configuration.rb', line 7 def fallback_exceptions_app @fallback_exceptions_app end |
#openai_api_base ⇒ Object
Returns the value of attribute openai_api_base.
7 8 9 |
# File 'lib/bugsage/configuration.rb', line 7 def openai_api_base @openai_api_base end |
#openai_api_key ⇒ Object
Returns the value of attribute openai_api_key.
7 8 9 |
# File 'lib/bugsage/configuration.rb', line 7 def openai_api_key @openai_api_key end |
#openai_model ⇒ Object
Returns the value of attribute openai_model.
7 8 9 |
# File 'lib/bugsage/configuration.rb', line 7 def openai_model @openai_model end |
#show_dashboard ⇒ Object
Returns the value of attribute show_dashboard.
7 8 9 |
# File 'lib/bugsage/configuration.rb', line 7 def show_dashboard @show_dashboard end |
#show_error_page ⇒ Object
Returns the value of attribute show_error_page.
7 8 9 |
# File 'lib/bugsage/configuration.rb', line 7 def show_error_page @show_error_page end |
#show_inline_console ⇒ Object
Returns the value of attribute show_inline_console.
7 8 9 |
# File 'lib/bugsage/configuration.rb', line 7 def show_inline_console @show_inline_console end |
Instance Method Details
#ai_configured?(environment = current_environment) ⇒ Boolean
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/bugsage/configuration.rb', line 90 def ai_configured?(environment = current_environment) return false unless ai_enabled?(environment) return true unless ai_client.nil? case resolved_ai_provider when :cursor !resolved_cursor_api_key.to_s.strip.empty? else !resolved_openai_api_key.to_s.strip.empty? end end |
#ai_enabled?(environment = current_environment) ⇒ Boolean
79 80 81 82 83 84 |
# File 'lib/bugsage/configuration.rb', line 79 def ai_enabled?(environment = current_environment) return false unless enabled?(environment) return ai_enabled unless ai_enabled.nil? credential_available? end |
#capture_errors?(environment = current_environment) ⇒ Boolean
67 68 69 70 71 |
# File 'lib/bugsage/configuration.rb', line 67 def capture_errors?(environment = current_environment) return false unless enabled?(environment) capture_errors end |
#capture_http_errors?(environment = current_environment) ⇒ Boolean
73 74 75 76 77 |
# File 'lib/bugsage/configuration.rb', line 73 def capture_http_errors?(environment = current_environment) return false unless capture_errors?(environment) capture_http_errors != false end |
#credential_available? ⇒ Boolean
86 87 88 |
# File 'lib/bugsage/configuration.rb', line 86 def credential_available? !resolved_openai_api_key.to_s.strip.empty? || !resolved_cursor_api_key.to_s.strip.empty? end |
#current_environment ⇒ Object
135 136 137 138 139 140 141 |
# File 'lib/bugsage/configuration.rb', line 135 def current_environment if defined?(Rails) && Rails.respond_to?(:env) Rails.env.to_s else ENV.fetch("RAILS_ENV", ENV.fetch("RACK_ENV", "development")) end end |
#effective_ai_timeout ⇒ Object
129 130 131 132 133 |
# File 'lib/bugsage/configuration.rb', line 129 def effective_ai_timeout return [ai_timeout, 90].max if resolved_ai_provider == :cursor ai_timeout end |
#enabled?(environment = current_environment) ⇒ Boolean
45 46 47 |
# File 'lib/bugsage/configuration.rb', line 45 def enabled?(environment = current_environment) environment_names.include?(environment.to_s) end |
#resolved_ai_provider ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/bugsage/configuration.rb', line 103 def resolved_ai_provider provider = ai_provider&.to_sym return provider if provider && AI_PROVIDERS.include?(provider) return :cursor if resolved_cursor_api_key.to_s.start_with?("crsr_") :openai end |
#resolved_cursor_api_key ⇒ Object
119 120 121 122 123 124 125 126 127 |
# File 'lib/bugsage/configuration.rb', line 119 def resolved_cursor_api_key explicit = cursor_api_key || ENV["CURSOR_API_KEY"] || ENV.fetch("BUGSAGE_CURSOR_API_KEY", nil) return explicit if explicit.to_s.start_with?("crsr_") misrouted = openai_api_key || ENV["OPENAI_API_KEY"] || ENV.fetch("BUGSAGE_OPENAI_API_KEY", nil) return misrouted if misrouted.to_s.start_with?("crsr_") explicit end |
#resolved_openai_api_key ⇒ Object
112 113 114 115 116 117 |
# File 'lib/bugsage/configuration.rb', line 112 def resolved_openai_api_key key = openai_api_key || ENV["OPENAI_API_KEY"] || ENV.fetch("BUGSAGE_OPENAI_API_KEY", nil) return nil if key.to_s.start_with?("crsr_") key end |
#show_dashboard?(environment = current_environment) ⇒ Boolean
55 56 57 58 59 |
# File 'lib/bugsage/configuration.rb', line 55 def show_dashboard?(environment = current_environment) return show_dashboard unless show_dashboard.nil? environment.to_s == "development" end |
#show_error_page?(environment = current_environment) ⇒ Boolean
49 50 51 52 53 |
# File 'lib/bugsage/configuration.rb', line 49 def show_error_page?(environment = current_environment) return show_error_page unless show_error_page.nil? environment.to_s == "development" end |
#show_inline_console?(environment = current_environment) ⇒ Boolean
61 62 63 64 65 |
# File 'lib/bugsage/configuration.rb', line 61 def show_inline_console?(environment = current_environment) return show_inline_console unless show_inline_console.nil? environment.to_s == "development" end |