operation_setting

package
v0.2.0-beta.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	QuotaDisplayTypeUSD    = "USD"
	QuotaDisplayTypeCNY    = "CNY"
	QuotaDisplayTypeTokens = "TOKENS"
	QuotaDisplayTypeCustom = "CUSTOM"
)

额度展示类型

View Source
const (
	ChannelTestModeScheduledAll    = "scheduled_all"
	ChannelTestModeAutoBanOnly     = "auto_ban_only"
	ChannelTestModePassiveRecovery = "passive_recovery"

	ChannelTestConcurrencyOptionKey = "monitor_setting.channel_test_concurrency"
	DefaultChannelTestConcurrency   = 1
	MaxChannelTestConcurrency       = 32
)
View Source
const (
	Gemini25FlashPreviewInputAudioPrice     = 1.00
	Gemini25FlashProductionInputAudioPrice  = 1.00
	Gemini25FlashLitePreviewInputAudioPrice = 0.50
	Gemini25FlashNativeAudioInputAudioPrice = 3.00
	Gemini20FlashInputAudioPrice            = 0.70
	GeminiRoboticsER15InputAudioPrice       = 1.00
)
View Source
const CurrentComplianceTermsVersion = "v1"
View Source
const ToolPriceOptionKey = "tool_price_setting.prices"

Variables

View Source
var AutomaticDisableKeywords = []string{
	"Your credit balance is too low",
	"This organization has been disabled.",
	"You exceeded your current quota",
	"Permission denied",
	"The security token included in the request is invalid",
	"Operation not allowed",
	"Your account is not authorized",
}
View Source
var AutomaticDisableStatusCodeRanges = []StatusCodeRange{{Start: 401, End: 401}}
View Source
var AutomaticRetryStatusCodeRanges = []StatusCodeRange{
	{Start: 100, End: 199},
	{Start: 300, End: 399},
	{Start: 401, End: 407},
	{Start: 409, End: 499},
	{Start: 500, End: 503},
	{Start: 505, End: 523},
	{Start: 525, End: 599},
}

Default behavior matches legacy hardcoded retry rules in controller/relay.go shouldRetry: retry for 1xx, 3xx, 4xx(except 400/408), 5xx(except 504/524), and no retry for 2xx.

View Source
var CustomCallbackAddress = ""
View Source
var DemoSiteEnabled = false
View Source
var EpayId = ""
View Source
var EpayKey = ""
View Source
var MinTopUp = 1
View Source
var PayAddress = ""
View Source
var PayMethods = []map[string]string{
	{
		"name": "支付宝",
		"icon": "SiAlipay",
		"type": "alipay",
	},
	{
		"name": "微信",
		"icon": "SiWechat",
		"type": "wxpay",
	},
	{
		"name":      "自定义1",
		"icon":      "LuCreditCard",
		"type":      "custom1",
		"min_topup": "50",
	},
}
View Source
var Price = 7.3
View Source
var SelfUseModeEnabled = false
View Source
var USDExchangeRate = 7.3

Functions

func AutomaticDisableKeywordsFromString

func AutomaticDisableKeywordsFromString(s string)

func AutomaticDisableKeywordsToString

func AutomaticDisableKeywordsToString() string

func AutomaticDisableStatusCodesFromString

func AutomaticDisableStatusCodesFromString(s string) error

func AutomaticDisableStatusCodesToString

func AutomaticDisableStatusCodesToString() string

func AutomaticRetryStatusCodesFromString

func AutomaticRetryStatusCodesFromString(s string) error

func AutomaticRetryStatusCodesToString

func AutomaticRetryStatusCodesToString() string

func CaptureToolPricesForModel

func CaptureToolPricesForModel(modelName string) map[string]float64

CaptureToolPricesForModel resolves every configured/built-in tool from one immutable generation, including explicit zero overrides. New tool settings published later must not change a request already priced with this map.

func ContainsPayMethod

func ContainsPayMethod(method string) bool

func DeleteToolPriceForTest

func DeleteToolPriceForTest(name string)

DeleteToolPriceForTest removes an injected tool price and rebuilds the index. Tests only.

func GetCheckinQuotaRange

func GetCheckinQuotaRange() (min, max int)

GetCheckinQuotaRange 获取签到额度范围

func GetCurrencySymbol

func GetCurrencySymbol() string

GetCurrencySymbol 返回当前展示类型对应符号

func GetGeminiInputAudioPricePerMillionTokens

func GetGeminiInputAudioPricePerMillionTokens(modelName string) float64

func GetMaxUserTokens

func GetMaxUserTokens() int

GetMaxUserTokens 获取每用户最大令牌数量

func GetPayMethods

func GetPayMethods() []map[string]string

func GetQuotaDisplayType

func GetQuotaDisplayType() string

GetQuotaDisplayType 返回额度展示类型

func GetToolPrice

func GetToolPrice(toolName string) float64

GetToolPrice is a convenience wrapper when no model name is needed.

func GetToolPriceForModel

func GetToolPriceForModel(toolName, modelName string) float64

GetToolPriceForModel returns the price ($/1K calls) for a tool given a model name. Lookup: longest prefix match → tool default → 0.

func GetUsdToCurrencyRate

func GetUsdToCurrencyRate(usdToCny float64) float64

GetUsdToCurrencyRate 返回 1 USD = X <currency> 的 X(TOKENS 不适用)

func IsAlwaysSkipRetryCode

func IsAlwaysSkipRetryCode(errorCode types.ErrorCode) bool

func IsAlwaysSkipRetryStatusCode

func IsAlwaysSkipRetryStatusCode(code int) bool

func IsCNYDisplay

func IsCNYDisplay() bool

IsCNYDisplay 是否以人民币展示

func IsCheckinEnabled

func IsCheckinEnabled() bool

IsCheckinEnabled 是否启用签到功能

func IsCurrencyDisplay

func IsCurrencyDisplay() bool

IsCurrencyDisplay 是否以货币形式展示(美元或人民币)

func IsPaymentComplianceConfirmed

func IsPaymentComplianceConfirmed() bool

func LoadToolPricesFromJSONString

func LoadToolPricesFromJSONString(value string)

LoadToolPricesFromJSONString replaces the complete operator price map. Invalid legacy entries are ignored individually so valid sibling overrides survive, while missing built-in keys continue to use hardcoded fallbacks.

func NormalizeChannelTestConcurrency

func NormalizeChannelTestConcurrency(concurrency int) int

func PayMethods2JsonString

func PayMethods2JsonString() string

func PublishUserFundingSnapshot

func PublishUserFundingSnapshot(mode UserFundingMode, epoch uint64) error

func RebuildToolPriceIndex

func RebuildToolPriceIndex()

RebuildToolPriceIndex republishes the current immutable overrides together with a freshly derived index. It is not used on the billing hot path.

func SetToolPriceForTest

func SetToolPriceForTest(name string, price float64)

SetToolPriceForTest injects a tool price and rebuilds the lookup index. Tests only.

func SetUserFundingMode

func SetUserFundingMode(mode UserFundingMode) error

func ShouldDisableByStatusCode

func ShouldDisableByStatusCode(code int) bool

func ShouldRetryByStatusCode

func ShouldRetryByStatusCode(code int) bool

func UpdatePayMethodsByJsonString

func UpdatePayMethodsByJsonString(jsonString string) error

func ValidateChannelTestConcurrency

func ValidateChannelTestConcurrency(value string) error

func ValidatePayMethodsJSON

func ValidatePayMethodsJSON(value string) error

func ValidateToolPricesJSON

func ValidateToolPricesJSON(value string) error

ValidateToolPricesJSON validates an operator-supplied complete price map. A numeric zero is valid and intentionally disables the matching rule.

Types

type ChannelAffinityKeySource

type ChannelAffinityKeySource struct {
	Type string `json:"type"` // context_int, context_string, request_header, gjson
	Key  string `json:"key,omitempty"`
	Path string `json:"path,omitempty"`
}

type ChannelAffinityRule

type ChannelAffinityRule struct {
	Name             string                     `json:"name"`
	ModelRegex       []string                   `json:"model_regex"`
	PathRegex        []string                   `json:"path_regex"`
	UserAgentInclude []string                   `json:"user_agent_include,omitempty"`
	KeySources       []ChannelAffinityKeySource `json:"key_sources"`

	ValueRegex string `json:"value_regex"`
	TTLSeconds int    `json:"ttl_seconds"`

	ParamOverrideTemplate map[string]interface{} `json:"param_override_template,omitempty"`

	SkipRetryOnFailure bool `json:"skip_retry_on_failure"`

	IncludeUsingGroup bool `json:"include_using_group"`
	IncludeModelName  bool `json:"include_model_name"`
	IncludeRuleName   bool `json:"include_rule_name"`
}

type ChannelAffinitySetting

type ChannelAffinitySetting struct {
	Enabled               bool                  `json:"enabled"`
	SwitchOnSuccess       bool                  `json:"switch_on_success"`
	KeepOnChannelDisabled bool                  `json:"keep_on_channel_disabled"`
	MaxEntries            int                   `json:"max_entries"`
	DefaultTTLSeconds     int                   `json:"default_ttl_seconds"`
	Rules                 []ChannelAffinityRule `json:"rules"`
}

func GetChannelAffinitySetting

func GetChannelAffinitySetting() *ChannelAffinitySetting

GetChannelAffinitySetting 获取渠道亲和设置的分离快照。 返回值是当代配置的深拷贝;调用方修改它不会影响运行时状态。

生效语义(D14/D15 合同):Enabled/Rules 等匹配字段保存后即对新请求生效; MaxEntries/DefaultTTLSeconds 只更新配置代——运行中的亲和缓存容量/TTL 在 显式维护重建(POST /api/option/channel_affinity_cache/rebuild)或重启后 才按新代参数重建。

type CheckinSetting

type CheckinSetting struct {
	Enabled  bool `json:"enabled"`   // 是否启用签到功能
	MinQuota int  `json:"min_quota"` // 签到最小额度奖励
	MaxQuota int  `json:"max_quota"` // 签到最大额度奖励
}

CheckinSetting 签到功能配置

func GetCheckinSetting

func GetCheckinSetting() *CheckinSetting

GetCheckinSetting 获取签到配置

type GeneralSetting

type GeneralSetting struct {
	DocsLink            string `json:"docs_link"`
	PingIntervalEnabled bool   `json:"ping_interval_enabled"`
	PingIntervalSeconds int    `json:"ping_interval_seconds"`
	// 当前站点额度展示类型:USD / CNY / TOKENS
	QuotaDisplayType string `json:"quota_display_type"`
	// 自定义货币符号,用于 CUSTOM 展示类型
	CustomCurrencySymbol string `json:"custom_currency_symbol"`
	// 自定义货币与美元汇率(1 USD = X Custom)
	CustomCurrencyExchangeRate float64 `json:"custom_currency_exchange_rate"`
}

func GetGeneralSetting

func GetGeneralSetting() *GeneralSetting

type MonitorSetting

type MonitorSetting struct {
	AutoTestChannelEnabled bool    `json:"auto_test_channel_enabled"`
	AutoTestChannelMinutes float64 `json:"auto_test_channel_minutes"`
	ChannelTestMode        string  `json:"channel_test_mode"`
	ChannelTestConcurrency int     `json:"channel_test_concurrency"`
}

func GetMonitorSetting

func GetMonitorSetting() *MonitorSetting

type PaymentSetting

type PaymentSetting struct {
	AmountOptions  []int           `json:"amount_options"`
	AmountDiscount map[int]float64 `json:"amount_discount"` // 充值金额对应的折扣,例如 100 元 0.9 表示 100 元充值享受 9 折优惠

	ComplianceConfirmed    bool   `json:"compliance_confirmed"`
	ComplianceTermsVersion string `json:"compliance_terms_version"`
	ComplianceConfirmedAt  int64  `json:"compliance_confirmed_at"`
	ComplianceConfirmedBy  int    `json:"compliance_confirmed_by"`
	ComplianceConfirmedIP  string `json:"compliance_confirmed_ip"`
}

func GetPaymentSetting

func GetPaymentSetting() *PaymentSetting

type QuotaSetting

type QuotaSetting struct {
	EnableFreeModelPreConsume bool `json:"enable_free_model_pre_consume"` // 是否对免费模型启用预消耗
}

func GetQuotaSetting

func GetQuotaSetting() *QuotaSetting

type StatusCodeRange

type StatusCodeRange struct {
	Start int
	End   int
}

func ParseHTTPStatusCodeRanges

func ParseHTTPStatusCodeRanges(input string) ([]StatusCodeRange, error)

type TokenSetting

type TokenSetting struct {
	MaxUserTokens int `json:"max_user_tokens"` // 每用户最大令牌数量
}

TokenSetting 令牌相关配置

func GetTokenSetting

func GetTokenSetting() *TokenSetting

GetTokenSetting 获取令牌配置

type ToolPriceSetting

type ToolPriceSetting struct {
	Prices map[string]float64 `json:"prices"`
}

ToolPriceSetting is the public serialization DTO retained for callers that construct or decode tool-price configuration values.

type UserFundingMode

type UserFundingMode string
const (
	UserFundingModeEnabled    UserFundingMode = "enabled"
	UserFundingModeRetirement UserFundingMode = "retirement"
	UserFundingModeDisabled   UserFundingMode = "disabled"

	UserFundingModeOptionKey  = "user_funding_setting.mode"
	UserFundingEpochOptionKey = "user_funding_setting.epoch"
)

func GetUserFundingMode

func GetUserFundingMode() UserFundingMode

func NormalizeUserFundingMode

func NormalizeUserFundingMode(mode UserFundingMode) (UserFundingMode, error)

type UserFundingSetting

type UserFundingSetting struct {
	Mode  UserFundingMode `json:"mode"`
	Epoch uint64          `json:"epoch"`
}

func GetUserFundingSetting

func GetUserFundingSetting() UserFundingSetting

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL