feat: configurable tool pricing, Sub2API channel, and alpha search billing

Add admin-configurable tool-call prices with cross-provider surcharge
settlement, Sub2API channel support, /v1/alpha/search relay, and usage-log
surcharge UI.
This commit is contained in:
CaIon
2026-07-26 20:05:15 +08:00
parent 3e1e728279
commit 2d23cdf291
65 changed files with 3210 additions and 431 deletions
+20 -2
View File
@@ -204,7 +204,17 @@ func SyncOptions(frequency int) {
}
}
func validateOptionValue(key string, value string) error {
if key == operation_setting.ToolPriceOptionKey {
return operation_setting.ValidateToolPricesJSON(value)
}
return nil
}
func UpdateOption(key string, value string) error {
if err := validateOptionValue(key, value); err != nil {
return err
}
// Save to database first
option := Option{
Key: key,
@@ -229,6 +239,11 @@ func UpdateOptionsBulk(values map[string]string) error {
if len(values) == 0 {
return nil
}
for key, value := range values {
if err := validateOptionValue(key, value); err != nil {
return err
}
}
err := DB.Transaction(func(tx *gorm.DB) error {
for k, v := range values {
option := Option{Key: k}
@@ -584,6 +599,11 @@ func updateOptionMap(key string, value string) (err error) {
// handleConfigUpdate 处理分层配置更新,返回是否已处理
func handleConfigUpdate(key, value string) bool {
if key == operation_setting.ToolPriceOptionKey {
operation_setting.LoadToolPricesFromJSONString(value)
return true
}
parts := strings.SplitN(key, ".", 2)
if len(parts) != 2 {
return false // 不是分层配置
@@ -607,8 +627,6 @@ func handleConfigUpdate(key, value string) bool {
// 特定配置的后处理
if configName == "performance_setting" {
performance_setting.UpdateAndSync()
} else if configName == "tool_price_setting" {
operation_setting.RebuildToolPriceIndex()
} else if configName == "billing_setting" {
InvalidatePricingCache()
ratio_setting.InvalidateExposedDataCache()