Class: SimpleAcp::Models::AgentManifest

Inherits:
Base
  • Object
show all
Defined in:
lib/simple_acp/models/agent_manifest.rb

Overview

Describes agent capabilities for discovery.

Contains the metadata needed to advertise an agent's capabilities, including what content types it accepts and produces.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#==, attribute, attributes, #hash, own_attributes, #to_h, #to_json

Constructor Details

#initialize(**kwargs) ⇒ AgentManifest

Returns a new instance of AgentManifest.



34
35
36
37
38
# File 'lib/simple_acp/models/agent_manifest.rb', line 34

def initialize(**kwargs)
  super
  @input_content_types ||= ["text/plain"]
  @output_content_types ||= ["text/plain"]
end

Instance Attribute Details

#description ⇒ String? (readonly)

Returns human-readable description.

Returns:

  • (String, nil) —

    human-readable description



16
# File 'lib/simple_acp/models/agent_manifest.rb', line 16

attribute :description

#input_content_types ⇒ Array<String> (readonly)

Returns accepted MIME types (default: ["text/plain"]).

Returns:

  • (Array<String>) —

    accepted MIME types (default: ["text/plain"])



24
# File 'lib/simple_acp/models/agent_manifest.rb', line 24

attribute :input_content_types, default: -> { ["text/plain"] }

#metadata ⇒ Metadata? (readonly)

Returns additional metadata.

Returns:

  • (Metadata, nil) —

    additional metadata



20
# File 'lib/simple_acp/models/agent_manifest.rb', line 20

attribute :metadata

#name ⇒ String (readonly)

Returns agent name (RFC 1123 DNS label format).

Returns:

  • (String) —

    agent name (RFC 1123 DNS label format)



12
# File 'lib/simple_acp/models/agent_manifest.rb', line 12

attribute :name, required: true

#output_content_types ⇒ Array<String> (readonly)

Returns produced MIME types (default: ["text/plain"]).

Returns:

  • (Array<String>) —

    produced MIME types (default: ["text/plain"])



28
# File 'lib/simple_acp/models/agent_manifest.rb', line 28

attribute :output_content_types, default: -> { ["text/plain"] }

#status ⇒ AgentStatus? (readonly)

Returns status metrics.

Returns:



32
# File 'lib/simple_acp/models/agent_manifest.rb', line 32

attribute :status

Class Method Details

.from_hash(hash) ⇒ AgentManifest?

Create from a hash (JSON deserialization).

Parameters:

  • hash (Hash, nil) —

    manifest data

Returns:



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/simple_acp/models/agent_manifest.rb', line 44

def self.from_hash(hash)
  return nil if hash.nil?

  instance = super

  if hash["metadata"] || hash[:metadata]
    instance. = .from_hash(hash["metadata"] || hash[:metadata])
  end

  if hash["status"] || hash[:status]
    instance.status = AgentStatus.from_hash(hash["status"] || hash[:status])
  end

  instance
end

Instance Method Details

#accepts_content_type?(content_type) ⇒ Boolean

Check if the agent accepts a content type.

Parameters:

  • content_type (String) —

    MIME type to check

Returns:

  • (Boolean) —

    true if accepted



64
65
66
67
68
69
70
# File 'lib/simple_acp/models/agent_manifest.rb', line 64

def accepts_content_type?(content_type)
  return true if @input_content_types.include?("*/*")

  @input_content_types.any? do |accepted|
    matches_content_type?(accepted, content_type)
  end
end

#produces_content_type?(content_type) ⇒ Boolean

Check if the agent produces a content type.

Parameters:

  • content_type (String) —

    MIME type to check

Returns:

  • (Boolean) —

    true if produced



76
77
78
79
80
81
82
# File 'lib/simple_acp/models/agent_manifest.rb', line 76

def produces_content_type?(content_type)
  return true if @output_content_types.include?("*/*")

  @output_content_types.any? do |produced|
    matches_content_type?(produced, content_type)
  end
end

#valid? ⇒ Boolean

Validate the manifest.

Returns:

  • (Boolean) —

    true if name is valid and content types are non-empty



87
88
89
90
91
92
93
# File 'lib/simple_acp/models/agent_manifest.rb', line 87

def valid?
  return false unless Types.valid_agent_name?(@name)
  return false if @input_content_types.empty?
  return false if @output_content_types.empty?

  true
end