Class: SwarmSDK::ContextManagement::Builder
- Inherits:
-
Object
- Object
- SwarmSDK::ContextManagement::Builder
- Defined in:
- lib/swarm_sdk/context_management/builder.rb
Overview
DSL for defining context management handlers
This builder provides a clean, idiomatic way to register handlers for context warning thresholds. Handlers receive a rich context object with message manipulation methods.
Constant Summary collapse
- EVENT_MAP =
Map semantic event names to threshold percentages
{ warning_60: 60, warning_80: 80, warning_90: 90, }.freeze
Instance Method Summary collapse
-
#build ⇒ Array<Hooks::Definition>
Build hook definitions from handlers.
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
-
#on(event) {|ContextManagement::Context| ... } ⇒ void
Register a handler for a context warning threshold.
Constructor Details
#initialize ⇒ Builder
Returns a new instance of Builder.
46 47 48 |
# File 'lib/swarm_sdk/context_management/builder.rb', line 46 def initialize @handlers = {} # { threshold => block } end |
Instance Method Details
#build ⇒ Array<Hooks::Definition>
Build hook definitions from handlers
Creates Hooks::Definition objects that wrap user blocks to provide rich context objects instead of raw Hooks::Context. Each handler becomes a hook for the :context_warning event.
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/swarm_sdk/context_management/builder.rb', line 96 def build @handlers.map do |threshold, user_block| # Create a hook that filters by threshold and wraps context Hooks::Definition.new( event: :context_warning, matcher: nil, # No tool matching needed priority: 0, proc: create_threshold_matcher(threshold, user_block), ) end end |
#on(event) {|ContextManagement::Context| ... } ⇒ void
This method returns an undefined value.
Register a handler for a context warning threshold
Handlers take full responsibility for managing context at their threshold. When a handler is registered for a threshold, automatic compression is disabled for that threshold.
81 82 83 84 85 86 87 |
# File 'lib/swarm_sdk/context_management/builder.rb', line 81 def on(event, &block) threshold = EVENT_MAP[event] raise ArgumentError, "Unknown event: #{event}. Valid events: #{EVENT_MAP.keys.join(", ")}" unless threshold raise ArgumentError, "Block required for #{event}" unless block @handlers[threshold] = block end |