Class: Silas::Connection
- Inherits:
-
Object
- Object
- Silas::Connection
- Defined in:
- lib/silas/connection.rb
Overview
A typed MCP integration declared by app/agent/connections/
Defined Under Namespace
Classes: RemoteTool
Constant Summary collapse
- TRANSPORTS =
%w[http].freeze
- APPROVALS =
%i[never once always].freeze
- EFFECTS =
not transactional: a remote call can't share our DB txn
%i[at_most_once idempotent].freeze
Instance Attribute Summary collapse
-
#approval ⇒ Object
readonly
Returns the value of attribute approval.
-
#effect ⇒ Object
readonly
Returns the value of attribute effect.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#transport ⇒ Object
readonly
Returns the value of attribute transport.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #auth_headers ⇒ Object
- #client ⇒ Object
-
#initialize(name, attrs) ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize(name, attrs) ⇒ Connection
Returns a new instance of Connection.
19 20 21 22 23 24 25 26 27 |
# File 'lib/silas/connection.rb', line 19 def initialize(name, attrs) @name = name @transport = attrs.fetch("transport", "http") @url = attrs["url"] @auth = attrs["auth"] || {} @approval = (attrs["approval"] || "never").to_sym @effect = (attrs["effect"] || "at_most_once").to_sym validate! end |
Instance Attribute Details
#approval ⇒ Object (readonly)
Returns the value of attribute approval.
12 13 14 |
# File 'lib/silas/connection.rb', line 12 def approval @approval end |
#effect ⇒ Object (readonly)
Returns the value of attribute effect.
12 13 14 |
# File 'lib/silas/connection.rb', line 12 def effect @effect end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/silas/connection.rb', line 12 def name @name end |
#transport ⇒ Object (readonly)
Returns the value of attribute transport.
12 13 14 |
# File 'lib/silas/connection.rb', line 12 def transport @transport end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
12 13 14 |
# File 'lib/silas/connection.rb', line 12 def url @url end |
Class Method Details
.parse(path) ⇒ Object
14 15 16 17 |
# File 'lib/silas/connection.rb', line 14 def self.parse(path) attrs = YAML.safe_load(File.read(path)) || {} attrs.empty? ? nil : new(File.basename(path, ".yml"), attrs) end |
Instance Method Details
#auth_headers ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/silas/connection.rb', line 31 def auth_headers case @auth["type"] when "bearer" then { "Authorization" => "Bearer #{secret!}" } when "header" then { @auth.fetch("header") => secret! } else {} end end |