Class: RubyLLM::MCP::Handlers::ElicitationRegistry
- Inherits:
-
Object
- Object
- RubyLLM::MCP::Handlers::ElicitationRegistry
- Defined in:
- lib/ruby_llm/mcp/handlers/elicitation_registry.rb
Overview
Registry for tracking pending elicitations Provides thread-safe storage and retrieval for async completions
Class Method Summary collapse
- .cancel(id, reason: "Cancelled") ⇒ Object
- .clear ⇒ Object
- .complete(id, response:) ⇒ Object
-
.instance ⇒ Object
Get the singleton registry instance.
- .remove(id) ⇒ Object
- .retrieve(id) ⇒ Object
- .size ⇒ Object
-
.store(id, elicitation, schedule_timeout: true) ⇒ Object
Delegate class methods to instance.
Instance Method Summary collapse
-
#cancel(id, reason: "Cancelled") ⇒ Object
Cancel a pending elicitation.
-
#clear ⇒ Object
Clear all pending elicitations.
-
#complete(id, response:) ⇒ Object
Complete a pending elicitation.
-
#initialize ⇒ ElicitationRegistry
constructor
A new instance of ElicitationRegistry.
-
#remove(id) ⇒ RubyLLM::MCP::Elicitation?
Remove an elicitation from the registry.
-
#retrieve(id) ⇒ RubyLLM::MCP::Elicitation?
Retrieve an elicitation from the registry.
-
#size ⇒ Integer
Get number of pending elicitations.
-
#store(id, elicitation, schedule_timeout: true) ⇒ Object
Store an elicitation in the registry.
Constructor Details
#initialize ⇒ ElicitationRegistry
Returns a new instance of ElicitationRegistry.
45 46 47 48 49 50 |
# File 'lib/ruby_llm/mcp/handlers/elicitation_registry.rb', line 45 def initialize @registry = {} @timeouts = {} @registry_mutex = Mutex.new @timeouts_mutex = Mutex.new end |
Class Method Details
.cancel(id, reason: "Cancelled") ⇒ Object
32 33 34 |
# File 'lib/ruby_llm/mcp/handlers/elicitation_registry.rb', line 32 def cancel(id, reason: "Cancelled") instance.cancel(id, reason: reason) end |
.clear ⇒ Object
36 37 38 |
# File 'lib/ruby_llm/mcp/handlers/elicitation_registry.rb', line 36 def clear instance.clear end |
.complete(id, response:) ⇒ Object
28 29 30 |
# File 'lib/ruby_llm/mcp/handlers/elicitation_registry.rb', line 28 def complete(id, response:) instance.complete(id, response: response) end |
.instance ⇒ Object
Get the singleton registry instance
11 12 13 |
# File 'lib/ruby_llm/mcp/handlers/elicitation_registry.rb', line 11 def instance @instance ||= new end |
.remove(id) ⇒ Object
24 25 26 |
# File 'lib/ruby_llm/mcp/handlers/elicitation_registry.rb', line 24 def remove(id) instance.remove(id) end |
.retrieve(id) ⇒ Object
20 21 22 |
# File 'lib/ruby_llm/mcp/handlers/elicitation_registry.rb', line 20 def retrieve(id) instance.retrieve(id) end |
.size ⇒ Object
40 41 42 |
# File 'lib/ruby_llm/mcp/handlers/elicitation_registry.rb', line 40 def size instance.size end |
.store(id, elicitation, schedule_timeout: true) ⇒ Object
Delegate class methods to instance
16 17 18 |
# File 'lib/ruby_llm/mcp/handlers/elicitation_registry.rb', line 16 def store(id, elicitation, schedule_timeout: true) instance.store(id, elicitation, schedule_timeout: schedule_timeout) end |
Instance Method Details
#cancel(id, reason: "Cancelled") ⇒ Object
Cancel a pending elicitation
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/ruby_llm/mcp/handlers/elicitation_registry.rb', line 116 def cancel(id, reason: "Cancelled") elicitation = retrieve(id) if elicitation RubyLLM::MCP.logger.info("Cancelling elicitation #{id}: #{reason}") elicitation.cancel_async(reason) remove(id) else RubyLLM::MCP.logger.warn("Attempted to cancel unknown elicitation #{id}") end end |
#clear ⇒ Object
Clear all pending elicitations
129 130 131 132 133 134 |
# File 'lib/ruby_llm/mcp/handlers/elicitation_registry.rb', line 129 def clear ids = @registry_mutex.synchronize { @registry.keys } ids.each { |id| cancel_timeout(id) } @registry_mutex.synchronize { @registry.clear } RubyLLM::MCP.logger.debug("Cleared elicitation registry") end |
#complete(id, response:) ⇒ Object
Complete a pending elicitation
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/ruby_llm/mcp/handlers/elicitation_registry.rb', line 101 def complete(id, response:) elicitation = retrieve(id) if elicitation RubyLLM::MCP.logger.info("Completing elicitation #{id}") elicitation.complete(response) remove(id) else RubyLLM::MCP.logger.warn("Attempted to complete unknown elicitation #{id}") end end |
#remove(id) ⇒ RubyLLM::MCP::Elicitation?
Remove an elicitation from the registry
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ruby_llm/mcp/handlers/elicitation_registry.rb', line 80 def remove(id) elicitation = nil # Cancel timeout first (before removing from registry) cancel_timeout(id) # Remove from registry elicitation = @registry_mutex.synchronize do @registry.delete(id) end RubyLLM::MCP.logger.debug("Removed elicitation #{id} from registry") if elicitation elicitation ensure # Ensure timeout thread is cleaned up even if removal fails cancel_timeout(id) unless elicitation end |
#retrieve(id) ⇒ RubyLLM::MCP::Elicitation?
Retrieve an elicitation from the registry
71 72 73 74 75 |
# File 'lib/ruby_llm/mcp/handlers/elicitation_registry.rb', line 71 def retrieve(id) @registry_mutex.synchronize do @registry[id] end end |
#size ⇒ Integer
Get number of pending elicitations
138 139 140 |
# File 'lib/ruby_llm/mcp/handlers/elicitation_registry.rb', line 138 def size @registry_mutex.synchronize { @registry.size } end |
#store(id, elicitation, schedule_timeout: true) ⇒ Object
Store an elicitation in the registry
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ruby_llm/mcp/handlers/elicitation_registry.rb', line 55 def store(id, elicitation, schedule_timeout: true) @registry_mutex.synchronize do @registry[id] = elicitation end # Set up timeout if specified if schedule_timeout && elicitation.timeout schedule_timeout(id, elicitation.timeout) end RubyLLM::MCP.logger.debug("Stored elicitation #{id} in registry") end |