Class: SolidAgent::AgentManifest::Resource
- Inherits:
-
Object
- Object
- SolidAgent::AgentManifest::Resource
- Defined in:
- lib/solid_agent/agent_manifest/resource.rb
Overview
Resource represents an external data source that an agent can access.
Resources follow MCP (Model Context Protocol) conventions and can represent files, APIs, databases, or other data sources.
Instance Attribute Summary collapse
-
#description ⇒ String?
Human-readable description.
-
#mime_type ⇒ String?
MIME type of the resource content.
-
#name ⇒ String
Resource identifier.
-
#uri ⇒ String
URI pattern or URL.
Class Method Summary collapse
-
.from_hash(data) ⇒ Resource
Create from hash (flexible key formats).
Instance Method Summary collapse
-
#file? ⇒ Boolean
Check if this is a file resource.
-
#http? ⇒ Boolean
Check if this is an HTTP resource.
-
#initialize(attributes = {}) ⇒ Resource
constructor
A new instance of Resource.
-
#to_h ⇒ Hash
Convert to hash representation.
-
#valid? ⇒ Boolean
Check if resource is valid.
-
#validation_errors ⇒ Array<String>
Validation errors.
Constructor Details
#initialize(attributes = {}) ⇒ Resource
Returns a new instance of Resource.
39 40 41 42 43 44 |
# File 'lib/solid_agent/agent_manifest/resource.rb', line 39 def initialize(attributes = {}) attributes.each do |key, value| setter = "#{key}=" send(setter, value) if respond_to?(setter) end end |
Instance Attribute Details
#description ⇒ String?
Returns Human-readable description.
31 32 33 |
# File 'lib/solid_agent/agent_manifest/resource.rb', line 31 def description @description end |
#mime_type ⇒ String?
Returns MIME type of the resource content.
37 38 39 |
# File 'lib/solid_agent/agent_manifest/resource.rb', line 37 def mime_type @mime_type end |
#name ⇒ String
Returns Resource identifier.
28 29 30 |
# File 'lib/solid_agent/agent_manifest/resource.rb', line 28 def name @name end |
#uri ⇒ String
Returns URI pattern or URL.
34 35 36 |
# File 'lib/solid_agent/agent_manifest/resource.rb', line 34 def uri @uri end |
Class Method Details
.from_hash(data) ⇒ Resource
Create from hash (flexible key formats)
62 63 64 65 66 67 68 69 |
# File 'lib/solid_agent/agent_manifest/resource.rb', line 62 def self.from_hash(data) new( name: data["name"] || data[:name], description: data["description"] || data[:description], uri: data["uri"] || data[:uri], mime_type: data["mimeType"] || data["mime_type"] || data[:mime_type] || data[:mimeType] ) end |
Instance Method Details
#file? ⇒ Boolean
Check if this is a file resource
74 75 76 |
# File 'lib/solid_agent/agent_manifest/resource.rb', line 74 def file? uri&.start_with?("file://") end |
#http? ⇒ Boolean
Check if this is an HTTP resource
81 82 83 |
# File 'lib/solid_agent/agent_manifest/resource.rb', line 81 def http? uri&.match?(%r{\Ahttps?://}) end |
#to_h ⇒ Hash
Convert to hash representation
49 50 51 52 53 54 55 56 |
# File 'lib/solid_agent/agent_manifest/resource.rb', line 49 def to_h { name: name, description: description, uri: uri, mimeType: mime_type }.compact end |
#valid? ⇒ Boolean
Check if resource is valid
88 89 90 |
# File 'lib/solid_agent/agent_manifest/resource.rb', line 88 def valid? name.present? && uri.present? end |
#validation_errors ⇒ Array<String>
Validation errors
95 96 97 98 99 100 |
# File 'lib/solid_agent/agent_manifest/resource.rb', line 95 def validation_errors errors = [] errors << "Resource must have a name" if name.blank? errors << "Resource must have a uri" if uri.blank? errors end |