Class: Portage::Ucp::Dispatcher
- Inherits:
-
Object
- Object
- Portage::Ucp::Dispatcher
- Defined in:
- lib/portage/ucp/dispatcher.rb
Overview
Accepts a UCP-shaped request (capability + action + arguments), routes it through the CapabilityRegistry to the backing Adapter method, and wraps the result as MCP's dual content/structuredContent output (see §5).
Constant Summary collapse
- PAYMENT_COMPLETING_ACTION =
The one action that moves money — see docs/plans/agentic-payments.md Phase 0. Gated by name, not capability, since
complete_checkoutis the onlydev.ucp.shopping.checkoutaction that dispatches a charge. "complete_checkout".freeze
Instance Method Summary collapse
- #call(capability:, action:, arguments: {}, correlation_id: nil, agent_profile: nil) ⇒ Object
-
#initialize(adapter:, registry: CapabilityRegistry.default, logger: Portage::Ucp.configuration.logger, shop: nil, transaction_log: Support::TransactionLog.new, policy: Policy.load, confirmer: Confirmer::Terminal.new, order_ledger: Support::OrderLedger.new, journal: nil, mandate_trust_keys: Portage::Ucp.configuration.mandate_trusted_keys, require_mandate_signature: Portage::Ucp.configuration.require_mandate_signature) ⇒ Dispatcher
constructor
A new instance of Dispatcher.
Constructor Details
#initialize(adapter:, registry: CapabilityRegistry.default, logger: Portage::Ucp.configuration.logger, shop: nil, transaction_log: Support::TransactionLog.new, policy: Policy.load, confirmer: Confirmer::Terminal.new, order_ledger: Support::OrderLedger.new, journal: nil, mandate_trust_keys: Portage::Ucp.configuration.mandate_trusted_keys, require_mandate_signature: Portage::Ucp.configuration.require_mandate_signature) ⇒ Dispatcher
Returns a new instance of Dispatcher.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/portage/ucp/dispatcher.rb', line 53 def initialize(adapter:, registry: CapabilityRegistry.default, logger: Portage::Ucp.configuration.logger, shop: nil, transaction_log: Support::TransactionLog.new, policy: Policy.load, confirmer: Confirmer::Terminal.new, order_ledger: Support::OrderLedger.new, journal: nil, mandate_trust_keys: Portage::Ucp.configuration.mandate_trusted_keys, require_mandate_signature: Portage::Ucp.configuration.require_mandate_signature) @adapter = adapter @registry = registry @logger = logger @shop = shop @transaction_log = transaction_log @policy = policy @confirmer = confirmer @order_ledger = order_ledger @journal = journal @mandate_trust_keys = mandate_trust_keys @require_mandate_signature = require_mandate_signature end |
Instance Method Details
#call(capability:, action:, arguments: {}, correlation_id: nil, agent_profile: nil) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/portage/ucp/dispatcher.rb', line 85 def call(capability:, action:, arguments: {}, correlation_id: nil, agent_profile: nil) capability_definition = @registry.find(capability) raise UnknownCapabilityError, capability if capability_definition.nil? raise CapabilityNotAdvertisedError, capability unless capability_definition.advertised_for?(@adapter) method_name = capability_definition.actions[action] raise UnknownActionError, action if method_name.nil? validate_inbound_boundaries!(arguments) result = if action == PAYMENT_COMPLETING_ACTION call_and_log_transaction(method_name, arguments, correlation_id) else call_adapter(method_name, arguments, correlation_id) end validate_outbound_boundaries!(result) wrap(capability, result) end |