Class: Kward::RPC::ConfigManager
- Inherits:
-
Object
- Object
- Kward::RPC::ConfigManager
- Defined in:
- lib/kward/rpc/config_manager.rb
Overview
RPC configuration manager for reading and updating user config.
Instance Attribute Summary collapse
-
#config_path ⇒ Object
readonly
Returns the value of attribute config_path.
Instance Method Summary collapse
- #delete_key(key) ⇒ Object
-
#initialize(config_path: OpenAIOAuth.default_config_path) ⇒ ConfigManager
constructor
A new instance of ConfigManager.
- #read(redacted: true) ⇒ Object
- #session_auto_resume_enabled? ⇒ Boolean
- #set_api_key(provider_id, api_key) ⇒ Object
- #set_model(model, provider: nil) ⇒ Object
- #set_reasoning_effort(effort, provider: nil) ⇒ Object
- #update(values) ⇒ Object
- #workspace_guardrails_enabled? ⇒ Boolean
Constructor Details
#initialize(config_path: OpenAIOAuth.default_config_path) ⇒ ConfigManager
Returns a new instance of ConfigManager.
12 13 14 |
# File 'lib/kward/rpc/config_manager.rb', line 12 def initialize(config_path: OpenAIOAuth.default_config_path) @config_path = File.(config_path) end |
Instance Attribute Details
#config_path ⇒ Object (readonly)
Returns the value of attribute config_path.
16 17 18 |
# File 'lib/kward/rpc/config_manager.rb', line 16 def config_path @config_path end |
Instance Method Details
#delete_key(key) ⇒ Object
50 51 52 |
# File 'lib/kward/rpc/config_manager.rb', line 50 def delete_key(key) ConfigFiles.delete_config_key(key, @config_path) end |
#read(redacted: true) ⇒ Object
18 19 20 21 |
# File 'lib/kward/rpc/config_manager.rb', line 18 def read(redacted: true) config = load_config redacted ? Redactor.redact(config) : config end |
#session_auto_resume_enabled? ⇒ Boolean
58 59 60 |
# File 'lib/kward/rpc/config_manager.rb', line 58 def session_auto_resume_enabled? ConfigFiles.session_auto_resume_enabled?(read(redacted: false)) end |
#set_api_key(provider_id, api_key) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/kward/rpc/config_manager.rb', line 41 def set_api_key(provider_id, api_key) provider_id = provider_id.to_s api_key = api_key.to_s.strip raise "API key must be a non-empty string" if api_key.empty? raise "Unsupported API key provider: #{provider_id}" unless provider_id == "openrouter" update("openrouter_api_key" => api_key) end |
#set_model(model, provider: nil) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/kward/rpc/config_manager.rb', line 27 def set_model(model, provider: nil) model = model.to_s.strip raise "Model must be a non-empty string" if model.empty? update(ModelInfo.config_values_for_selection(provider, model)) end |
#set_reasoning_effort(effort, provider: nil) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/kward/rpc/config_manager.rb', line 34 def set_reasoning_effort(effort, provider: nil) effort = effort.to_s.strip raise "Reasoning effort must be a non-empty string" if effort.empty? update(ModelInfo.reasoning_config_key_for_provider(provider) => effort) end |
#update(values) ⇒ Object
23 24 25 |
# File 'lib/kward/rpc/config_manager.rb', line 23 def update(values) Redactor.redact(ConfigFiles.update_config(values, @config_path)) end |
#workspace_guardrails_enabled? ⇒ Boolean
54 55 56 |
# File 'lib/kward/rpc/config_manager.rb', line 54 def workspace_guardrails_enabled? ConfigFiles.workspace_guardrails_enabled?(read(redacted: false)) end |