console_agent 0.10.0 → 0.12.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +101 -1
- data/app/helpers/console_agent/sessions_helper.rb +14 -0
- data/app/models/console_agent/session.rb +1 -1
- data/app/views/console_agent/sessions/index.html.erb +4 -4
- data/app/views/console_agent/sessions/show.html.erb +16 -6
- data/app/views/layouts/console_agent/application.html.erb +1 -0
- data/lib/console_agent/channel/base.rb +23 -0
- data/lib/console_agent/channel/console.rb +457 -0
- data/lib/console_agent/channel/slack.rb +182 -0
- data/lib/console_agent/configuration.rb +74 -5
- data/lib/console_agent/conversation_engine.rb +1122 -0
- data/lib/console_agent/executor.rb +239 -47
- data/lib/console_agent/providers/base.rb +7 -2
- data/lib/console_agent/providers/local.rb +112 -0
- data/lib/console_agent/railtie.rb +4 -0
- data/lib/console_agent/repl.rb +26 -1291
- data/lib/console_agent/safety_guards.rb +207 -0
- data/lib/console_agent/session_logger.rb +14 -3
- data/lib/console_agent/slack_bot.rb +473 -0
- data/lib/console_agent/tools/registry.rb +48 -16
- data/lib/console_agent/version.rb +1 -1
- data/lib/console_agent.rb +17 -3
- data/lib/generators/console_agent/templates/initializer.rb +34 -1
- data/lib/tasks/console_agent.rake +7 -0
- metadata +9 -1
|
@@ -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, :slack_allowed_usernames,
|
|
25
|
+
:local_url, :local_model, :local_api_key
|
|
24
26
|
|
|
25
27
|
def initialize
|
|
26
28
|
@provider = :anthropic
|
|
@@ -40,6 +42,59 @@ 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
|
+
@slack_allowed_usernames = nil
|
|
50
|
+
@local_url = 'http://localhost:11434'
|
|
51
|
+
@local_model = 'qwen2.5:7b'
|
|
52
|
+
@local_api_key = nil
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def safety_guards
|
|
56
|
+
@safety_guards ||= begin
|
|
57
|
+
require 'console_agent/safety_guards'
|
|
58
|
+
SafetyGuards.new
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Register a custom safety guard by name with an around-block.
|
|
63
|
+
#
|
|
64
|
+
# config.safety_guard :mailers do |&execute|
|
|
65
|
+
# ActionMailer::Base.perform_deliveries = false
|
|
66
|
+
# execute.call
|
|
67
|
+
# ensure
|
|
68
|
+
# ActionMailer::Base.perform_deliveries = true
|
|
69
|
+
# end
|
|
70
|
+
def safety_guard(name, &block)
|
|
71
|
+
safety_guards.add(name, &block)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Register a built-in safety guard by name.
|
|
75
|
+
# Available: :database_writes, :http_mutations, :mailers
|
|
76
|
+
#
|
|
77
|
+
# Options:
|
|
78
|
+
# allow: Array of strings or regexps to allowlist for this guard.
|
|
79
|
+
# - :http_mutations → hosts (e.g. "s3.amazonaws.com", /googleapis\.com/)
|
|
80
|
+
# - :database_writes → table names (e.g. "console_agent_sessions")
|
|
81
|
+
def use_builtin_safety_guard(name, allow: nil)
|
|
82
|
+
require 'console_agent/safety_guards'
|
|
83
|
+
guard_name = name.to_sym
|
|
84
|
+
case guard_name
|
|
85
|
+
when :database_writes
|
|
86
|
+
safety_guards.add(:database_writes, &BuiltinGuards.database_writes)
|
|
87
|
+
when :http_mutations
|
|
88
|
+
safety_guards.add(:http_mutations, &BuiltinGuards.http_mutations)
|
|
89
|
+
when :mailers
|
|
90
|
+
safety_guards.add(:mailers, &BuiltinGuards.mailers)
|
|
91
|
+
else
|
|
92
|
+
raise ConfigurationError, "Unknown built-in safety guard: #{name}. Available: database_writes, http_mutations, mailers"
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
if allow
|
|
96
|
+
Array(allow).each { |key| safety_guards.allow(guard_name, key) }
|
|
97
|
+
end
|
|
43
98
|
end
|
|
44
99
|
|
|
45
100
|
def resolved_api_key
|
|
@@ -50,6 +105,8 @@ module ConsoleAgent
|
|
|
50
105
|
ENV['ANTHROPIC_API_KEY']
|
|
51
106
|
when :openai
|
|
52
107
|
ENV['OPENAI_API_KEY']
|
|
108
|
+
when :local
|
|
109
|
+
@local_api_key || 'no-key'
|
|
53
110
|
end
|
|
54
111
|
end
|
|
55
112
|
|
|
@@ -61,6 +118,8 @@ module ConsoleAgent
|
|
|
61
118
|
'claude-sonnet-4-6'
|
|
62
119
|
when :openai
|
|
63
120
|
'gpt-5.3-codex'
|
|
121
|
+
when :local
|
|
122
|
+
@local_model
|
|
64
123
|
end
|
|
65
124
|
end
|
|
66
125
|
|
|
@@ -78,17 +137,27 @@ module ConsoleAgent
|
|
|
78
137
|
'claude-opus-4-6'
|
|
79
138
|
when :openai
|
|
80
139
|
'gpt-5.3-codex'
|
|
140
|
+
when :local
|
|
141
|
+
@local_model
|
|
81
142
|
end
|
|
82
143
|
end
|
|
83
144
|
|
|
145
|
+
def resolved_timeout
|
|
146
|
+
@provider == :local ? [@timeout, 300].max : @timeout
|
|
147
|
+
end
|
|
148
|
+
|
|
84
149
|
def validate!
|
|
85
150
|
unless PROVIDERS.include?(@provider)
|
|
86
151
|
raise ConfigurationError, "Unknown provider: #{@provider}. Valid: #{PROVIDERS.join(', ')}"
|
|
87
152
|
end
|
|
88
153
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
154
|
+
if @provider == :local
|
|
155
|
+
raise ConfigurationError, "No local_url configured for :local provider." unless @local_url && !@local_url.empty?
|
|
156
|
+
else
|
|
157
|
+
unless resolved_api_key
|
|
158
|
+
env_var = @provider == :anthropic ? 'ANTHROPIC_API_KEY' : 'OPENAI_API_KEY'
|
|
159
|
+
raise ConfigurationError, "No API key. Set config.api_key or #{env_var} env var."
|
|
160
|
+
end
|
|
92
161
|
end
|
|
93
162
|
end
|
|
94
163
|
end
|