Class: RubyLLM::MCP::Elicitation
- Inherits:
-
Object
- Object
- RubyLLM::MCP::Elicitation
- Defined in:
- lib/ruby_llm/mcp/elicitation.rb
Defined Under Namespace
Classes: DeferredCancellation
Constant Summary collapse
- ACCEPT_ACTION =
"accept"- CANCEL_ACTION =
"cancel"- DECLINE_ACTION =
"decline"
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#requested_schema ⇒ Object
readonly
Returns the value of attribute requested_schema.
-
#structured_response ⇒ Object
writeonly
Sets the attribute structured_response.
-
#timeout ⇒ Object
readonly
Get timeout value for this elicitation.
Instance Method Summary collapse
-
#cancel_async(reason) ⇒ Object
Cancel async elicitation.
-
#complete(response_data) ⇒ Object
Complete async elicitation with response data.
- #execute ⇒ Object
-
#initialize(coordinator, result) ⇒ Elicitation
constructor
A new instance of Elicitation.
- #message ⇒ Object
- #response_valid? ⇒ Boolean
-
#timeout! ⇒ Object
Mark as timed out.
Constructor Details
#initialize(coordinator, result) ⇒ Elicitation
Returns a new instance of Elicitation.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ruby_llm/mcp/elicitation.rb', line 24 def initialize(coordinator, result) @coordinator = coordinator @result = result @id = result.id @message = @result.params["message"] @requested_schema = @result.params["requestedSchema"] # Async support @deferred = false @async_response = nil @timeout = nil @deferred_request_registered = false end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
22 23 24 |
# File 'lib/ruby_llm/mcp/elicitation.rb', line 22 def id @id end |
#requested_schema ⇒ Object (readonly)
Returns the value of attribute requested_schema.
22 23 24 |
# File 'lib/ruby_llm/mcp/elicitation.rb', line 22 def requested_schema @requested_schema end |
#structured_response=(value) ⇒ Object (writeonly)
Sets the attribute structured_response
21 22 23 |
# File 'lib/ruby_llm/mcp/elicitation.rb', line 21 def structured_response=(value) @structured_response = value end |
#timeout ⇒ Object (readonly)
Get timeout value for this elicitation
108 109 110 |
# File 'lib/ruby_llm/mcp/elicitation.rb', line 108 def timeout @timeout end |
Instance Method Details
#cancel_async(reason) ⇒ Object
Cancel async elicitation
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ruby_llm/mcp/elicitation.rb', line 82 def cancel_async(reason) return unless @deferred RubyLLM::MCP.logger.info("Cancelling elicitation #{@id}: #{reason}") @coordinator.elicitation_response( id: @id, elicitation: { action: CANCEL_ACTION, content: nil } ) finalize_deferred_request end |
#complete(response_data) ⇒ Object
Complete async elicitation with response data
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ruby_llm/mcp/elicitation.rb', line 59 def complete(response_data) return unless @deferred @structured_response = response_data valid = response_valid? if valid @coordinator.elicitation_response( id: @id, elicitation: { action: ACCEPT_ACTION, content: @structured_response } ) else @coordinator.elicitation_response( id: @id, elicitation: { action: CANCEL_ACTION, content: nil } ) end finalize_deferred_request end |
#execute ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/ruby_llm/mcp/elicitation.rb', line 39 def execute handler = @coordinator.elicitation_callback if Handlers.handler_class?(handler) execute_with_handler_class(handler) else execute_with_block end end |
#message ⇒ Object
49 50 51 |
# File 'lib/ruby_llm/mcp/elicitation.rb', line 49 def @result.params["message"] end |
#response_valid? ⇒ Boolean
53 54 55 |
# File 'lib/ruby_llm/mcp/elicitation.rb', line 53 def response_valid? SchemaValidator.valid?(@requested_schema, @structured_response) end |
#timeout! ⇒ Object
Mark as timed out
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ruby_llm/mcp/elicitation.rb', line 95 def timeout! return unless @deferred RubyLLM::MCP.logger.warn("Elicitation #{@id} timed out") @coordinator.elicitation_response( id: @id, elicitation: { action: CANCEL_ACTION, content: nil } ) finalize_deferred_request end |