Class: Kward::RPC::ConfigManager
- Inherits:
-
Object
- Object
- Kward::RPC::ConfigManager
- Defined in:
- lib/kward/rpc/config_manager.rb
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
- #set_api_key(provider_id, api_key) ⇒ Object
- #set_model(model, provider: nil) ⇒ Object
- #set_reasoning_effort(effort, provider: nil) ⇒ Object
- #update(values) ⇒ Object
Constructor Details
#initialize(config_path: OpenAIOAuth.default_config_path) ⇒ ConfigManager
Returns a new instance of ConfigManager.
9 10 11 |
# File 'lib/kward/rpc/config_manager.rb', line 9 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.
13 14 15 |
# File 'lib/kward/rpc/config_manager.rb', line 13 def config_path @config_path end |
Instance Method Details
#delete_key(key) ⇒ Object
47 48 49 |
# File 'lib/kward/rpc/config_manager.rb', line 47 def delete_key(key) ConfigFiles.delete_config_key(key, @config_path) end |
#read(redacted: true) ⇒ Object
15 16 17 18 |
# File 'lib/kward/rpc/config_manager.rb', line 15 def read(redacted: true) config = load_config redacted ? Redactor.redact(config) : config end |
#set_api_key(provider_id, api_key) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/kward/rpc/config_manager.rb', line 38 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
24 25 26 27 28 29 |
# File 'lib/kward/rpc/config_manager.rb', line 24 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
31 32 33 34 35 36 |
# File 'lib/kward/rpc/config_manager.rb', line 31 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
20 21 22 |
# File 'lib/kward/rpc/config_manager.rb', line 20 def update(values) Redactor.redact(ConfigFiles.update_config(values, @config_path)) end |