Class: Aidp::Harness::DeprecationCache
- Inherits:
-
Object
- Object
- Aidp::Harness::DeprecationCache
- Defined in:
- lib/aidp/harness/deprecation_cache.rb
Overview
Manages a dynamic cache of deprecated models detected at runtime When deprecation errors are detected from provider APIs, models are added to this cache with metadata (replacement, detected date, etc.)
Defined Under Namespace
Classes: CacheError
Instance Attribute Summary collapse
-
#cache_path ⇒ Object
readonly
Returns the value of attribute cache_path.
Instance Method Summary collapse
-
#add_deprecated_model(provider:, model_id:, replacement: nil, reason: nil) ⇒ Object
Add a deprecated model to the cache.
-
#clear! ⇒ Object
Clear all cached deprecations.
-
#deprecated?(provider:, model_id:) ⇒ Boolean
Check if a model is deprecated.
-
#deprecated_models(provider:) ⇒ Array<String>
Get all deprecated models for a provider.
-
#info(provider:, model_id:) ⇒ Hash?
Get full deprecation info for a model.
-
#initialize(cache_path: nil, root_dir: nil) ⇒ DeprecationCache
constructor
A new instance of DeprecationCache.
-
#remove_deprecated_model(provider:, model_id:) ⇒ Object
Remove a model from the deprecated cache Useful if a model comes back or was incorrectly marked.
-
#replacement_for(provider:, model_id:) ⇒ String?
Get replacement model for a deprecated model.
-
#stats ⇒ Hash
Get cache statistics.
Constructor Details
#initialize(cache_path: nil, root_dir: nil) ⇒ DeprecationCache
Returns a new instance of DeprecationCache.
16 17 18 19 20 21 |
# File 'lib/aidp/harness/deprecation_cache.rb', line 16 def initialize(cache_path: nil, root_dir: nil) @root_dir = root_dir || safe_root_dir @cache_path = cache_path || default_cache_path @cache_data = nil ensure_cache_directory end |
Instance Attribute Details
#cache_path ⇒ Object (readonly)
Returns the value of attribute cache_path.
14 15 16 |
# File 'lib/aidp/harness/deprecation_cache.rb', line 14 def cache_path @cache_path end |
Instance Method Details
#add_deprecated_model(provider:, model_id:, replacement: nil, reason: nil) ⇒ Object
Add a deprecated model to the cache
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/aidp/harness/deprecation_cache.rb', line 28 def add_deprecated_model(provider:, model_id:, replacement: nil, reason: nil) load_cache unless @cache_data @cache_data["providers"][provider] ||= {} @cache_data["providers"][provider][model_id] = { "deprecated_at" => Time.now.iso8601, "replacement" => replacement, "reason" => reason }.compact save_cache Aidp.log_info("deprecation_cache", "Added deprecated model", provider: provider, model: model_id, replacement: replacement) end |
#clear! ⇒ Object
Clear all cached deprecations
95 96 97 98 99 |
# File 'lib/aidp/harness/deprecation_cache.rb', line 95 def clear! @cache_data = default_cache_structure save_cache Aidp.log_info("deprecation_cache", "Cleared all deprecations") end |
#deprecated?(provider:, model_id:) ⇒ Boolean
Check if a model is deprecated
47 48 49 50 |
# File 'lib/aidp/harness/deprecation_cache.rb', line 47 def deprecated?(provider:, model_id:) load_cache unless @cache_data @cache_data.dig("providers", provider, model_id) != nil end |
#deprecated_models(provider:) ⇒ Array<String>
Get all deprecated models for a provider
64 65 66 67 |
# File 'lib/aidp/harness/deprecation_cache.rb', line 64 def deprecated_models(provider:) load_cache unless @cache_data (@cache_data.dig("providers", provider) || {}).keys end |
#info(provider:, model_id:) ⇒ Hash?
Get full deprecation info for a model
89 90 91 92 |
# File 'lib/aidp/harness/deprecation_cache.rb', line 89 def info(provider:, model_id:) load_cache unless @cache_data @cache_data.dig("providers", provider, model_id) end |
#remove_deprecated_model(provider:, model_id:) ⇒ Object
Remove a model from the deprecated cache Useful if a model comes back or was incorrectly marked
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/aidp/harness/deprecation_cache.rb', line 73 def remove_deprecated_model(provider:, model_id:) load_cache unless @cache_data return unless @cache_data.dig("providers", provider, model_id) @cache_data["providers"][provider].delete(model_id) @cache_data["providers"].delete(provider) if @cache_data["providers"][provider].empty? save_cache Aidp.log_info("deprecation_cache", "Removed deprecated model", provider: provider, model: model_id) end |
#replacement_for(provider:, model_id:) ⇒ String?
Get replacement model for a deprecated model
56 57 58 59 |
# File 'lib/aidp/harness/deprecation_cache.rb', line 56 def replacement_for(provider:, model_id:) load_cache unless @cache_data @cache_data.dig("providers", provider, model_id, "replacement") end |
#stats ⇒ Hash
Get cache statistics
103 104 105 106 107 108 109 110 |
# File 'lib/aidp/harness/deprecation_cache.rb', line 103 def stats load_cache unless @cache_data { providers: @cache_data["providers"].keys.sort, total_deprecated: @cache_data["providers"].sum { |_, models| models.size }, by_provider: @cache_data["providers"].transform_values(&:size) } end |