Class: SolidAgent::AgentManifest::Resource

Inherits:
Object
  • Object
show all
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.

Examples:

File resource

resource = Resource.new(
  name: "company_docs",
  description: "Internal company documentation",
  uri: "file:///docs/**/*.md",
  mime_type: "text/markdown"
)

API resource

resource = Resource.new(
  name: "api_spec",
  description: "OpenAPI specification",
  uri: "https://api.example.com/openapi.json",
  mime_type: "application/json"
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#descriptionString?

Returns Human-readable description.

Returns:

  • (String, nil)

    Human-readable description



31
32
33
# File 'lib/solid_agent/agent_manifest/resource.rb', line 31

def description
  @description
end

#mime_typeString?

Returns MIME type of the resource content.

Returns:

  • (String, nil)

    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

#nameString

Returns Resource identifier.

Returns:

  • (String)

    Resource identifier



28
29
30
# File 'lib/solid_agent/agent_manifest/resource.rb', line 28

def name
  @name
end

#uriString

Returns URI pattern or URL.

Returns:

  • (String)

    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)

Parameters:

  • data (Hash)

Returns:



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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


81
82
83
# File 'lib/solid_agent/agent_manifest/resource.rb', line 81

def http?
  uri&.match?(%r{\Ahttps?://})
end

#to_hHash

Convert to hash representation

Returns:

  • (Hash)


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

Returns:

  • (Boolean)


88
89
90
# File 'lib/solid_agent/agent_manifest/resource.rb', line 88

def valid?
  name.present? && uri.present?
end

#validation_errorsArray<String>

Validation errors

Returns:

  • (Array<String>)


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