Class: VectorMCP::Definitions::Prompt
- Inherits:
-
Struct
- Object
- Struct
- VectorMCP::Definitions::Prompt
- Defined in:
- lib/vector_mcp/definitions.rb
Overview
Represents a prompt or templated message workflow for users or AI models.
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Array
An array of argument definitions for the prompt, where each hash can contain :name
,:description
, and:required
(Boolean). -
#description ⇒ Object
String A human-readable description of the prompt.
-
#handler ⇒ Object
Proc A callable that generates the prompt content.
-
#name ⇒ Object
String The unique name of the prompt.
Class Method Summary collapse
-
.with_image_support(name:, description:, image_argument_name: "image", additional_arguments: [], &handler) ⇒ Prompt
Class method to create an image-enabled prompt with common image argument patterns.
Instance Method Summary collapse
-
#as_mcp_definition ⇒ Hash
Converts the prompt to its MCP definition hash.
-
#supports_image_arguments? ⇒ Boolean
Checks if this prompt supports image arguments.
Instance Attribute Details
#arguments ⇒ Object
Array:name
, :description
, and :required
(Boolean).
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/vector_mcp/definitions.rb', line 172 Prompt = Struct.new(:name, :description, :arguments, :handler) do # Converts the prompt to its MCP definition hash. # @return [Hash] A hash representing the prompt in MCP format. def as_mcp_definition { name: name, description: description, arguments: arguments # Expected to be an array of { name:, description:, required: } hashes }.compact end # Checks if this prompt supports image arguments. # @return [Boolean] True if any of the prompt arguments are configured for images. def supports_image_arguments? return false unless arguments.is_a?(Array) arguments.any? do |arg| arg.is_a?(Hash) && ( arg["type"] == "image" || arg[:type] == "image" || (arg["description"] || arg[:description])&.downcase&.include?("image") ) end end # Class method to create an image-enabled prompt with common image argument patterns. # @param name [String] The unique name of the prompt. # @param description [String] A human-readable description. # @param image_argument_name [String] Name of the image argument (default: "image"). # @param additional_arguments [Array<Hash>] Additional prompt arguments. # @param handler [Proc] The prompt handler. # @return [Prompt] A new Prompt instance configured for image input. def self.with_image_support(name:, description:, image_argument_name: "image", additional_arguments: [], &handler) image_arg = { name: image_argument_name, description: "Image file path or image data to include in the prompt", required: false, type: "image" } all_arguments = [image_arg] + additional_arguments new(name, description, all_arguments, handler) end end |
#description ⇒ Object
String A human-readable description of the prompt.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/vector_mcp/definitions.rb', line 172 Prompt = Struct.new(:name, :description, :arguments, :handler) do # Converts the prompt to its MCP definition hash. # @return [Hash] A hash representing the prompt in MCP format. def as_mcp_definition { name: name, description: description, arguments: arguments # Expected to be an array of { name:, description:, required: } hashes }.compact end # Checks if this prompt supports image arguments. # @return [Boolean] True if any of the prompt arguments are configured for images. def supports_image_arguments? return false unless arguments.is_a?(Array) arguments.any? do |arg| arg.is_a?(Hash) && ( arg["type"] == "image" || arg[:type] == "image" || (arg["description"] || arg[:description])&.downcase&.include?("image") ) end end # Class method to create an image-enabled prompt with common image argument patterns. # @param name [String] The unique name of the prompt. # @param description [String] A human-readable description. # @param image_argument_name [String] Name of the image argument (default: "image"). # @param additional_arguments [Array<Hash>] Additional prompt arguments. # @param handler [Proc] The prompt handler. # @return [Prompt] A new Prompt instance configured for image input. def self.with_image_support(name:, description:, image_argument_name: "image", additional_arguments: [], &handler) image_arg = { name: image_argument_name, description: "Image file path or image data to include in the prompt", required: false, type: "image" } all_arguments = [image_arg] + additional_arguments new(name, description, all_arguments, handler) end end |
#handler ⇒ Object
Proc A callable that generates the prompt content. It receives a hash of arguments, validated against the prompt's argument definitions.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/vector_mcp/definitions.rb', line 172 Prompt = Struct.new(:name, :description, :arguments, :handler) do # Converts the prompt to its MCP definition hash. # @return [Hash] A hash representing the prompt in MCP format. def as_mcp_definition { name: name, description: description, arguments: arguments # Expected to be an array of { name:, description:, required: } hashes }.compact end # Checks if this prompt supports image arguments. # @return [Boolean] True if any of the prompt arguments are configured for images. def supports_image_arguments? return false unless arguments.is_a?(Array) arguments.any? do |arg| arg.is_a?(Hash) && ( arg["type"] == "image" || arg[:type] == "image" || (arg["description"] || arg[:description])&.downcase&.include?("image") ) end end # Class method to create an image-enabled prompt with common image argument patterns. # @param name [String] The unique name of the prompt. # @param description [String] A human-readable description. # @param image_argument_name [String] Name of the image argument (default: "image"). # @param additional_arguments [Array<Hash>] Additional prompt arguments. # @param handler [Proc] The prompt handler. # @return [Prompt] A new Prompt instance configured for image input. def self.with_image_support(name:, description:, image_argument_name: "image", additional_arguments: [], &handler) image_arg = { name: image_argument_name, description: "Image file path or image data to include in the prompt", required: false, type: "image" } all_arguments = [image_arg] + additional_arguments new(name, description, all_arguments, handler) end end |
#name ⇒ Object
String The unique name of the prompt.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/vector_mcp/definitions.rb', line 172 Prompt = Struct.new(:name, :description, :arguments, :handler) do # Converts the prompt to its MCP definition hash. # @return [Hash] A hash representing the prompt in MCP format. def as_mcp_definition { name: name, description: description, arguments: arguments # Expected to be an array of { name:, description:, required: } hashes }.compact end # Checks if this prompt supports image arguments. # @return [Boolean] True if any of the prompt arguments are configured for images. def supports_image_arguments? return false unless arguments.is_a?(Array) arguments.any? do |arg| arg.is_a?(Hash) && ( arg["type"] == "image" || arg[:type] == "image" || (arg["description"] || arg[:description])&.downcase&.include?("image") ) end end # Class method to create an image-enabled prompt with common image argument patterns. # @param name [String] The unique name of the prompt. # @param description [String] A human-readable description. # @param image_argument_name [String] Name of the image argument (default: "image"). # @param additional_arguments [Array<Hash>] Additional prompt arguments. # @param handler [Proc] The prompt handler. # @return [Prompt] A new Prompt instance configured for image input. def self.with_image_support(name:, description:, image_argument_name: "image", additional_arguments: [], &handler) image_arg = { name: image_argument_name, description: "Image file path or image data to include in the prompt", required: false, type: "image" } all_arguments = [image_arg] + additional_arguments new(name, description, all_arguments, handler) end end |
Class Method Details
.with_image_support(name:, description:, image_argument_name: "image", additional_arguments: [], &handler) ⇒ Prompt
Class method to create an image-enabled prompt with common image argument patterns.
204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/vector_mcp/definitions.rb', line 204 def self.with_image_support(name:, description:, image_argument_name: "image", additional_arguments: [], &handler) image_arg = { name: image_argument_name, description: "Image file path or image data to include in the prompt", required: false, type: "image" } all_arguments = [image_arg] + additional_arguments new(name, description, all_arguments, handler) end |
Instance Method Details
#as_mcp_definition ⇒ Hash
Converts the prompt to its MCP definition hash.
175 176 177 178 179 180 181 |
# File 'lib/vector_mcp/definitions.rb', line 175 def as_mcp_definition { name: name, description: description, arguments: arguments # Expected to be an array of { name:, description:, required: } hashes }.compact end |
#supports_image_arguments? ⇒ Boolean
Checks if this prompt supports image arguments.
185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/vector_mcp/definitions.rb', line 185 def supports_image_arguments? return false unless arguments.is_a?(Array) arguments.any? do |arg| arg.is_a?(Hash) && ( arg["type"] == "image" || arg[:type] == "image" || (arg["description"] || arg[:description])&.downcase&.include?("image") ) end end |