Class: ModelContextProtocol::Server::Prompt
- Inherits:
-
Object
- Object
- ModelContextProtocol::Server::Prompt
- Includes:
- Cancellable, ContentHelpers, Progressable
- Defined in:
- lib/model_context_protocol/server/prompt.rb
Defined Under Namespace
Classes: ArgumentDSL, DefinitionDSL, MessageHistoryBuilder
Class Attribute Summary collapse
-
.defined_arguments ⇒ Object
readonly
Returns the value of attribute defined_arguments.
-
.description ⇒ Object
readonly
Returns the value of attribute description.
-
.name ⇒ Object
readonly
Returns the value of attribute name.
-
.title ⇒ Object
readonly
Returns the value of attribute title.
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Class Method Summary collapse
- .call(arguments, logger, context = {}) ⇒ Object
- .complete_for(arg_name, value) ⇒ Object
- .define(&block) ⇒ Object
- .definition ⇒ Object
- .inherited(subclass) ⇒ Object
- .with_argument(&block) ⇒ Object
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(arguments, logger, context = {}) ⇒ Prompt
constructor
A new instance of Prompt.
- #message_history(&block) ⇒ Object
Methods included from Progressable
Methods included from ContentHelpers
#audio_content, #embedded_resource_content, #image_content, #resource_link, #text_content
Methods included from Cancellable
Constructor Details
#initialize(arguments, logger, context = {}) ⇒ Prompt
Returns a new instance of Prompt.
9 10 11 12 13 14 |
# File 'lib/model_context_protocol/server/prompt.rb', line 9 def initialize(arguments, logger, context = {}) validate!(arguments) @arguments = arguments @context = context @logger = logger end |
Class Attribute Details
.defined_arguments ⇒ Object (readonly)
Returns the value of attribute defined_arguments.
58 59 60 |
# File 'lib/model_context_protocol/server/prompt.rb', line 58 def defined_arguments @defined_arguments end |
.description ⇒ Object (readonly)
Returns the value of attribute description.
58 59 60 |
# File 'lib/model_context_protocol/server/prompt.rb', line 58 def description @description end |
.name ⇒ Object (readonly)
Returns the value of attribute name.
58 59 60 |
# File 'lib/model_context_protocol/server/prompt.rb', line 58 def name @name end |
.title ⇒ Object (readonly)
Returns the value of attribute title.
58 59 60 |
# File 'lib/model_context_protocol/server/prompt.rb', line 58 def title @title end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
7 8 9 |
# File 'lib/model_context_protocol/server/prompt.rb', line 7 def arguments @arguments end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
7 8 9 |
# File 'lib/model_context_protocol/server/prompt.rb', line 7 def context @context end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
7 8 9 |
# File 'lib/model_context_protocol/server/prompt.rb', line 7 def logger @logger end |
Class Method Details
.call(arguments, logger, context = {}) ⇒ Object
93 94 95 96 97 |
# File 'lib/model_context_protocol/server/prompt.rb', line 93 def call(arguments, logger, context = {}) new(arguments, logger, context).call rescue ArgumentError => error raise ModelContextProtocol::Server::ParameterValidationError, error. end |
.complete_for(arg_name, value) ⇒ Object
105 106 107 108 109 |
# File 'lib/model_context_protocol/server/prompt.rb', line 105 def complete_for(arg_name, value) arg = @defined_arguments&.find { |a| a[:name] == arg_name.to_s } completion = (arg && arg[:completion]) ? arg[:completion] : ModelContextProtocol::Server::NullCompletion completion.call(arg_name.to_s, value) end |
.define(&block) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/model_context_protocol/server/prompt.rb', line 60 def define(&block) @defined_arguments ||= [] definition_dsl = DefinitionDSL.new definition_dsl.instance_eval(&block) @name = definition_dsl.name @description = definition_dsl.description @title = definition_dsl.title @defined_arguments.concat(definition_dsl.arguments) end |
.definition ⇒ Object
99 100 101 102 103 |
# File 'lib/model_context_protocol/server/prompt.rb', line 99 def definition result = {name: @name, description: @description, arguments: @defined_arguments} result[:title] = @title if @title result end |
.inherited(subclass) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/model_context_protocol/server/prompt.rb', line 86 def inherited(subclass) subclass.instance_variable_set(:@name, @name) subclass.instance_variable_set(:@description, @description) subclass.instance_variable_set(:@title, @title) subclass.instance_variable_set(:@defined_arguments, @defined_arguments&.dup) end |
.with_argument(&block) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/model_context_protocol/server/prompt.rb', line 72 def with_argument(&block) @defined_arguments ||= [] argument_dsl = ArgumentDSL.new argument_dsl.instance_eval(&block) @defined_arguments << { name: argument_dsl.name, description: argument_dsl.description, required: argument_dsl.required, completion: argument_dsl.completion } end |
Instance Method Details
#call ⇒ Object
16 17 18 |
# File 'lib/model_context_protocol/server/prompt.rb', line 16 def call raise NotImplementedError, "Subclasses must implement the call method" end |
#message_history(&block) ⇒ Object
29 30 31 32 33 |
# File 'lib/model_context_protocol/server/prompt.rb', line 29 def (&block) builder = MessageHistoryBuilder.new(self) builder.instance_eval(&block) builder. end |