Class: SolidAgent::AgentManifest::Registry::Client
- Inherits:
-
Object
- Object
- SolidAgent::AgentManifest::Registry::Client
- Defined in:
- lib/solid_agent/agent_manifest/registry/client.rb
Overview
Client provides HTTP API access to the ActiveAgents registry.
Constant Summary collapse
- BASE_URL =
"https://api.activeagents.ai/v1"
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
-
#deprecate(name, version, message:) ⇒ Hash
Deprecate a version.
-
#download(name, version: nil, path: nil, format: :agent_md) ⇒ String
Download an agent manifest.
-
#download_file(name, file_path, version: nil) ⇒ String
Download a specific file from an agent package.
-
#fork(name, new_name:, scope: nil) ⇒ Hash
Fork an agent.
-
#get(name, version: nil) ⇒ Hash
Get an agent by name.
-
#initialize(token: nil, base_url: BASE_URL) ⇒ Client
constructor
Initialize a new client.
-
#me ⇒ Hash
Get current user info.
-
#my_agents ⇒ Array<Hash>
Get user's published agents.
-
#my_stars ⇒ Array<Hash>
Get user's starred agents.
-
#publish(path, tag: "latest", scope: nil, access: "public") ⇒ Hash
Publish an agent manifest.
-
#run(name, input:, model: nil, stream: false) ⇒ Hash
Run an agent in the sandbox.
-
#run_status(run_id) ⇒ Hash
Get status of a sandbox run.
-
#search(q: nil, tags: nil, framework: nil, author: nil, sort: "popular", page: 1, per_page: 20) ⇒ Hash
Search for agents.
-
#star(name) ⇒ Boolean
Star an agent.
-
#unpublish(name, version) ⇒ Boolean
Unpublish a version.
-
#unstar(name) ⇒ Boolean
Unstar an agent.
-
#versions(name) ⇒ Array<Hash>
List all versions of an agent.
Constructor Details
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
27 28 29 |
# File 'lib/solid_agent/agent_manifest/registry/client.rb', line 27 def base_url @base_url end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
27 28 29 |
# File 'lib/solid_agent/agent_manifest/registry/client.rb', line 27 def token @token end |
Instance Method Details
#deprecate(name, version, message:) ⇒ Hash
Deprecate a version
178 179 180 181 |
# File 'lib/solid_agent/agent_manifest/registry/client.rb', line 178 def deprecate(name, version, message:) require_auth! patch("/agents/#{encode_name(name)}/versions/#{version}", { deprecated: true, deprecation_message: }) end |
#download(name, version: nil, path: nil, format: :agent_md) ⇒ String
Download an agent manifest
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/solid_agent/agent_manifest/registry/client.rb', line 91 def download(name, version: nil, path: nil, format: :agent_md) # Get agent metadata agent = get(name, version: version) # Determine output path output_dir = path || Dir.pwd FileUtils.mkdir_p(output_dir) filename = agent_filename(agent, format) output_path = File.join(output_dir, filename) # Download content content_url = agent["download_url"] || agent.dig("links", "download") if content_url content = fetch_content(content_url) else # Fetch from content endpoint content = get_request("/agents/#{encode_name(name)}/content", accept: "text/markdown") end # Convert format if needed source_format = agent["format"]&.to_sym || :agent_md if format != source_format manifest = ParserRegistry.parse_string(content, format: source_format) content = ExporterRegistry.export(manifest, format) end File.write(output_path, content, encoding: "UTF-8") output_path end |
#download_file(name, file_path, version: nil) ⇒ String
Download a specific file from an agent package
128 129 130 131 132 |
# File 'lib/solid_agent/agent_manifest/registry/client.rb', line 128 def download_file(name, file_path, version: nil) path = "/agents/#{encode_name(name)}/files/#{file_path}" path += "?version=#{version}" if version get_request(path, accept: "*/*") end |
#fork(name, new_name:, scope: nil) ⇒ Hash
Fork an agent
222 223 224 225 |
# File 'lib/solid_agent/agent_manifest/registry/client.rb', line 222 def fork(name, new_name:, scope: nil) require_auth! post("/agents/#{encode_name(name)}/fork", { new_name: new_name, scope: scope }) end |
#get(name, version: nil) ⇒ Hash
Get an agent by name
69 70 71 72 |
# File 'lib/solid_agent/agent_manifest/registry/client.rb', line 69 def get(name, version: nil) path = version ? "/agents/#{encode_name(name)}/versions/#{version}" : "/agents/#{encode_name(name)}" get_request(path) end |
#me ⇒ Hash
Get current user info
256 257 258 259 |
# File 'lib/solid_agent/agent_manifest/registry/client.rb', line 256 def me require_auth! get_request("/me") end |
#my_agents ⇒ Array<Hash>
Get user's published agents
272 273 274 275 |
# File 'lib/solid_agent/agent_manifest/registry/client.rb', line 272 def my_agents require_auth! get_request("/me/agents") end |
#my_stars ⇒ Array<Hash>
Get user's starred agents
264 265 266 267 |
# File 'lib/solid_agent/agent_manifest/registry/client.rb', line 264 def my_stars require_auth! get_request("/me/stars") end |
#publish(path, tag: "latest", scope: nil, access: "public") ⇒ Hash
Publish an agent manifest
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/solid_agent/agent_manifest/registry/client.rb', line 143 def publish(path, tag: "latest", scope: nil, access: "public") require_auth! manifest = AgentManifest.parse(path) AgentManifest.validate!(manifest, strict: true) content = File.read(path, encoding: "UTF-8") format = ParserRegistry.detect_format(path) body = { name: scope ? "#{scope}/#{manifest.name}" : manifest.name, version: manifest.version, tag: tag, access: access, format: format, content: content, metadata: { description: manifest.description, tags: manifest., model: manifest.model, author: manifest., license: manifest.license, repository: manifest.repository } } post("/agents", body) end |
#run(name, input:, model: nil, stream: false) ⇒ Hash
Run an agent in the sandbox
236 237 238 239 240 |
# File 'lib/solid_agent/agent_manifest/registry/client.rb', line 236 def run(name, input:, model: nil, stream: false) require_auth! body = { input: input, model: model, stream: stream }.compact post("/agents/#{encode_name(name)}/run", body) end |
#run_status(run_id) ⇒ Hash
Get status of a sandbox run
246 247 248 249 |
# File 'lib/solid_agent/agent_manifest/registry/client.rb', line 246 def run_status(run_id) require_auth! get_request("/runs/#{run_id}") end |
#search(q: nil, tags: nil, framework: nil, author: nil, sort: "popular", page: 1, per_page: 20) ⇒ Hash
Search for agents
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/solid_agent/agent_manifest/registry/client.rb', line 50 def search(q: nil, tags: nil, framework: nil, author: nil, sort: "popular", page: 1, per_page: 20) params = { q: q, tags: &.join(","), framework: framework, author: , sort: sort, page: page, per_page: per_page }.compact get("/agents", params) end |
#star(name) ⇒ Boolean
Star an agent
200 201 202 203 204 |
# File 'lib/solid_agent/agent_manifest/registry/client.rb', line 200 def star(name) require_auth! post("/agents/#{encode_name(name)}/star", {}) true end |
#unpublish(name, version) ⇒ Boolean
Unpublish a version
188 189 190 191 192 |
# File 'lib/solid_agent/agent_manifest/registry/client.rb', line 188 def unpublish(name, version) require_auth! delete("/agents/#{encode_name(name)}/versions/#{version}") true end |
#unstar(name) ⇒ Boolean
Unstar an agent
210 211 212 213 214 |
# File 'lib/solid_agent/agent_manifest/registry/client.rb', line 210 def unstar(name) require_auth! delete("/agents/#{encode_name(name)}/star") true end |
#versions(name) ⇒ Array<Hash>
List all versions of an agent
78 79 80 |
# File 'lib/solid_agent/agent_manifest/registry/client.rb', line 78 def versions(name) get_request("/agents/#{encode_name(name)}/versions") end |