Class: Kodo::Tools::StoreSecret
- Inherits:
-
RubyLLM::Tool
- Object
- RubyLLM::Tool
- Kodo::Tools::StoreSecret
- Extended by:
- PromptContributor
- Defined in:
- lib/kodo/tools/store_secret.rb
Constant Summary collapse
- MAX_PER_TURN =
2- VALIDATION_TIMEOUT =
5- KNOWN_SECRETS =
{ 'anthropic_api_key' => { description: 'Anthropic API key', prefix: 'sk-ant-' }, 'openai_api_key' => { description: 'OpenAI API key', prefix: 'sk-' }, 'gemini_api_key' => { description: 'Google Gemini API key' }, 'deepseek_api_key' => { description: 'DeepSeek API key' }, 'mistral_api_key' => { description: 'Mistral API key' }, 'openrouter_api_key' => { description: 'OpenRouter API key', prefix: 'sk-or-' }, 'perplexity_api_key' => { description: 'Perplexity API key' }, 'xai_api_key' => { description: 'xAI API key' }, 'tavily_api_key' => { description: 'Tavily API key', prefix: 'tvly-' }, 'telegram_bot_token' => { description: 'Telegram bot token' } }.freeze
Instance Method Summary collapse
-
#execute(secret_name:, secret_value:) ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#initialize(broker:, audit:, on_secret_stored: nil) ⇒ StoreSecret
constructor
A new instance of StoreSecret.
- #name ⇒ Object
- #reset_turn_count! ⇒ Object
Methods included from PromptContributor
capability_name, capability_primary, disabled_guidance, enabled_guidance
Constructor Details
#initialize(broker:, audit:, on_secret_stored: nil) ⇒ StoreSecret
Returns a new instance of StoreSecret.
40 41 42 43 44 45 46 |
# File 'lib/kodo/tools/store_secret.rb', line 40 def initialize(broker:, audit:, on_secret_stored: nil) super() @broker = broker @audit = audit @on_secret_stored = on_secret_stored @turn_count = 0 end |
Instance Method Details
#execute(secret_name:, secret_value:) ⇒ Object
rubocop:disable Metrics/MethodLength
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/kodo/tools/store_secret.rb', line 52 def execute(secret_name:, secret_value:) # rubocop:disable Metrics/MethodLength unless KNOWN_SECRETS.key?(secret_name) return "Unknown secret '#{secret_name}'. Known secrets: #{KNOWN_SECRETS.keys.join(', ')}" end @turn_count += 1 if @turn_count > MAX_PER_TURN return "Rate limit reached (max #{MAX_PER_TURN} secrets per message). Try again next message." end prefix_error = validate_prefix(secret_name, secret_value) return prefix_error if prefix_error validated = validate_key(secret_name, secret_value) @broker.store(secret_name, secret_value, source: 'chat', validated: validated) @audit.log( event: 'secret_stored_via_tool', detail: "secret:#{secret_name} validated:#{validated}" ) @on_secret_stored&.call(secret_name) desc = KNOWN_SECRETS[secret_name][:description] if validated "#{desc} stored and validated successfully. It's now active — no restart needed." else "#{desc} stored and activated. Couldn't verify it online, but it's ready to use." end rescue Kodo::Error => e e. end |
#name ⇒ Object
86 87 88 |
# File 'lib/kodo/tools/store_secret.rb', line 86 def name 'store_secret' end |
#reset_turn_count! ⇒ Object
48 49 50 |
# File 'lib/kodo/tools/store_secret.rb', line 48 def reset_turn_count! @turn_count = 0 end |