Documentation
¶
Index ¶
- Constants
- type Engine
- func (e *Engine) AdaptToPricingFunc() func(toolName string) (string, bool)
- func (e *Engine) AdaptToPricingFuncWithPeer(peerDID string) func(toolName string) (string, bool)
- func (e *Engine) AddRule(rule PricingRule)
- func (e *Engine) Quote(ctx context.Context, toolName, peerDID string) (*Quote, error)
- func (e *Engine) RemoveRule(name string)
- func (e *Engine) Rules() []PricingRule
- func (e *Engine) SetBasePrice(toolName string, price *big.Int)
- func (e *Engine) SetBasePriceFromString(toolName, price string) error
- func (e *Engine) SetReputation(fn ReputationQuerier)
- type MapToolPricer
- type PriceModifier
- type PriceModifierType
- type PricingRule
- type Quote
- type ReputationQuerier
- type RuleCondition
- type RuleSet
Constants ¶
const DefaultQuoteExpiry = 5 * time.Minute
DefaultQuoteExpiry is how long a price quote remains valid.
const USDCDecimals = 6
USDCDecimals is the number of decimal places for USDC.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine computes dynamic prices using rule-based evaluation.
func New ¶
func New(cfg config.DynamicPricingConfig) (*Engine, error)
New creates a pricing engine from config.
func (*Engine) AdaptToPricingFunc ¶
AdaptToPricingFunc returns a function compatible with paygate.PricingFunc. Signature: func(toolName string) (price string, isFree bool) Uses a background context and empty peerDID for anonymous pricing lookups.
func (*Engine) AdaptToPricingFuncWithPeer ¶
AdaptToPricingFuncWithPeer returns a paygate-compatible PricingFunc that includes peer identity for trust-based pricing.
func (*Engine) AddRule ¶
func (e *Engine) AddRule(rule PricingRule)
AddRule adds a pricing rule to the engine.
func (*Engine) RemoveRule ¶
RemoveRule removes a pricing rule by name.
func (*Engine) Rules ¶
func (e *Engine) Rules() []PricingRule
Rules returns a snapshot of the current pricing rules.
func (*Engine) SetBasePrice ¶
SetBasePrice sets the base price for a tool in smallest USDC units.
func (*Engine) SetBasePriceFromString ¶
SetBasePriceFromString parses a USDC decimal string and sets the base price.
func (*Engine) SetReputation ¶
func (e *Engine) SetReputation(fn ReputationQuerier)
SetReputation sets the reputation querier for trust-based discounts.
type MapToolPricer ¶
type MapToolPricer struct {
// contains filtered or unexported fields
}
MapToolPricer provides a simple way to set base prices from a map during engine construction. Call SetBasePrice on the engine directly for runtime updates.
func NewMapToolPricer ¶
NewMapToolPricer creates a MapToolPricer backed by a map. Tools not in the map use the default price. If defaultPrice is nil, unlisted tools have no price.
func (*MapToolPricer) LoadInto ¶
func (m *MapToolPricer) LoadInto(e *Engine)
LoadInto sets all prices from this pricer into the engine.
type PriceModifier ¶
type PriceModifier struct {
Type PriceModifierType `json:"type"`
Description string `json:"description"`
Factor float64 `json:"factor"` // multiplier: 0.9 = 10% discount, 1.2 = 20% surge
}
PriceModifier represents an adjustment to a base price.
type PriceModifierType ¶
type PriceModifierType string
PriceModifierType identifies the type of price modification.
const ( ModifierTrustDiscount PriceModifierType = "trust_discount" ModifierVolumeDiscount PriceModifierType = "volume_discount" ModifierSurge PriceModifierType = "surge" ModifierCustom PriceModifierType = "custom" )
type PricingRule ¶
type PricingRule struct {
Name string `json:"name"`
Priority int `json:"priority"` // lower = higher priority
Condition RuleCondition `json:"condition"`
Modifier PriceModifier `json:"modifier"`
Enabled bool `json:"enabled"`
}
PricingRule defines a pricing rule with condition and modifier.
type Quote ¶
type Quote struct {
ToolName string `json:"toolName"`
BasePrice *big.Int `json:"basePrice"` // in smallest USDC units
FinalPrice *big.Int `json:"finalPrice"`
Currency string `json:"currency"` // "USDC"
Modifiers []PriceModifier `json:"modifiers"`
IsFree bool `json:"isFree"`
ValidUntil time.Time `json:"validUntil"`
PeerDID string `json:"peerDid,omitempty"`
}
Quote represents a computed price for a tool invocation.
type ReputationQuerier ¶
ReputationQuerier queries peer trust scores. Defined locally to avoid import cycles.
type RuleCondition ¶
type RuleCondition struct {
ToolPattern string `json:"toolPattern,omitempty"` // glob pattern for tool name
MinTrustScore float64 `json:"minTrustScore,omitempty"`
MaxTrustScore float64 `json:"maxTrustScore,omitempty"`
PeerDID string `json:"peerDid,omitempty"` // specific peer
}
RuleCondition defines when a pricing rule applies.
type RuleSet ¶
type RuleSet struct {
// contains filtered or unexported fields
}
RuleSet holds an ordered collection of pricing rules.
func (*RuleSet) Add ¶
func (rs *RuleSet) Add(rule PricingRule)
Add inserts a rule and keeps the list sorted by priority.
func (*RuleSet) Evaluate ¶
func (rs *RuleSet) Evaluate(toolName string, trustScore float64, peerDID string, basePrice *big.Int) (*big.Int, []PriceModifier)
Evaluate walks rules in priority order, applies matching modifiers, and returns the final price and the list of applied modifiers.
func (*RuleSet) Rules ¶
func (rs *RuleSet) Rules() []PricingRule
Rules returns a copy of all rules sorted by priority.