console_agent 0.9.0 → 0.11.0

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.
@@ -1,6 +1,6 @@
1
1
  module ConsoleAgent
2
2
  class Configuration
3
- PROVIDERS = %i[anthropic openai].freeze
3
+ PROVIDERS = %i[anthropic openai local].freeze
4
4
 
5
5
  PRICING = {
6
6
  'claude-sonnet-4-6' => { input: 3.0 / 1_000_000, output: 15.0 / 1_000_000 },
@@ -20,7 +20,9 @@ module ConsoleAgent
20
20
  :storage_adapter, :memories_enabled,
21
21
  :session_logging, :connection_class,
22
22
  :admin_username, :admin_password,
23
- :authenticate
23
+ :authenticate,
24
+ :slack_bot_token, :slack_app_token, :slack_channel_ids,
25
+ :local_url, :local_model, :local_api_key
24
26
 
25
27
  def initialize
26
28
  @provider = :anthropic
@@ -40,6 +42,58 @@ module ConsoleAgent
40
42
  @admin_username = nil
41
43
  @admin_password = nil
42
44
  @authenticate = nil
45
+ @safety_guards = nil
46
+ @slack_bot_token = nil
47
+ @slack_app_token = nil
48
+ @slack_channel_ids = nil
49
+ @local_url = 'http://localhost:11434'
50
+ @local_model = 'qwen2.5:7b'
51
+ @local_api_key = nil
52
+ end
53
+
54
+ def safety_guards
55
+ @safety_guards ||= begin
56
+ require 'console_agent/safety_guards'
57
+ SafetyGuards.new
58
+ end
59
+ end
60
+
61
+ # Register a custom safety guard by name with an around-block.
62
+ #
63
+ # config.safety_guard :mailers do |&execute|
64
+ # ActionMailer::Base.perform_deliveries = false
65
+ # execute.call
66
+ # ensure
67
+ # ActionMailer::Base.perform_deliveries = true
68
+ # end
69
+ def safety_guard(name, &block)
70
+ safety_guards.add(name, &block)
71
+ end
72
+
73
+ # Register a built-in safety guard by name.
74
+ # Available: :database_writes, :http_mutations, :mailers
75
+ #
76
+ # Options:
77
+ # allow: Array of strings or regexps to allowlist for this guard.
78
+ # - :http_mutations → hosts (e.g. "s3.amazonaws.com", /googleapis\.com/)
79
+ # - :database_writes → table names (e.g. "console_agent_sessions")
80
+ def use_builtin_safety_guard(name, allow: nil)
81
+ require 'console_agent/safety_guards'
82
+ guard_name = name.to_sym
83
+ case guard_name
84
+ when :database_writes
85
+ safety_guards.add(:database_writes, &BuiltinGuards.database_writes)
86
+ when :http_mutations
87
+ safety_guards.add(:http_mutations, &BuiltinGuards.http_mutations)
88
+ when :mailers
89
+ safety_guards.add(:mailers, &BuiltinGuards.mailers)
90
+ else
91
+ raise ConfigurationError, "Unknown built-in safety guard: #{name}. Available: database_writes, http_mutations, mailers"
92
+ end
93
+
94
+ if allow
95
+ Array(allow).each { |key| safety_guards.allow(guard_name, key) }
96
+ end
43
97
  end
44
98
 
45
99
  def resolved_api_key
@@ -50,6 +104,8 @@ module ConsoleAgent
50
104
  ENV['ANTHROPIC_API_KEY']
51
105
  when :openai
52
106
  ENV['OPENAI_API_KEY']
107
+ when :local
108
+ @local_api_key || 'no-key'
53
109
  end
54
110
  end
55
111
 
@@ -61,6 +117,8 @@ module ConsoleAgent
61
117
  'claude-sonnet-4-6'
62
118
  when :openai
63
119
  'gpt-5.3-codex'
120
+ when :local
121
+ @local_model
64
122
  end
65
123
  end
66
124
 
@@ -78,17 +136,27 @@ module ConsoleAgent
78
136
  'claude-opus-4-6'
79
137
  when :openai
80
138
  'gpt-5.3-codex'
139
+ when :local
140
+ @local_model
81
141
  end
82
142
  end
83
143
 
144
+ def resolved_timeout
145
+ @provider == :local ? [@timeout, 300].max : @timeout
146
+ end
147
+
84
148
  def validate!
85
149
  unless PROVIDERS.include?(@provider)
86
150
  raise ConfigurationError, "Unknown provider: #{@provider}. Valid: #{PROVIDERS.join(', ')}"
87
151
  end
88
152
 
89
- unless resolved_api_key
90
- env_var = @provider == :anthropic ? 'ANTHROPIC_API_KEY' : 'OPENAI_API_KEY'
91
- raise ConfigurationError, "No API key. Set config.api_key or #{env_var} env var."
153
+ if @provider == :local
154
+ raise ConfigurationError, "No local_url configured for :local provider." unless @local_url && !@local_url.empty?
155
+ else
156
+ unless resolved_api_key
157
+ env_var = @provider == :anthropic ? 'ANTHROPIC_API_KEY' : 'OPENAI_API_KEY'
158
+ raise ConfigurationError, "No API key. Set config.api_key or #{env_var} env var."
159
+ end
92
160
  end
93
161
  end
94
162
  end