feat: sync deployed v1.0.0-rc.38-custom.42

Sync production source including routing, billing, Astra detection and public uptime. Update custom build instructions and license packaging.
This commit is contained in:
cneicy committed 2026-09-26 04:49:11 +08:00
1 parent aa6c3f50f4
commit ceddfd3d6b
828 files changed
+122253 -13702

No files matched your search

+68 -5
View File
@@ -99,6 +99,11 @@ type RelayInfo struct {
UsePrice bool
RelayMode int
OriginModelName string
ResponseModel *ResponseModel
ResponseGuard *ResponseModelGuard
AstraDetectionDisabled bool
AstraAutoSwitch bool
UpstreamRequests int
// BillingModelName is the pricing identity for this request. It is kept
// separate from OriginModelName and UpstreamModelName so virtual pricing
@@ -138,7 +143,11 @@ type RelayInfo struct {
ForcePreConsume bool
// Billing 是计费会话,封装了预扣费/结算/退款的统一生命周期。
// 初始免费组可为 nil;若 auto 重试切换到付费组,会在发送前创建。
Billing BillingSettler
Billing BillingSettler
DurableAttemptBilling bool
DurableAttemptID int64
AttemptDetached bool
GuardDeadline time.Time
// BillingSource indicates whether this request is billed from wallet quota or subscription.
// "" or "wallet" => wallet; "subscription" => subscription
BillingSource string
@@ -176,6 +185,11 @@ type RelayInfo struct {
// and again before settlement. Non-nil only when billing mode is "tiered_expr".
TieredBillingSnapshot *billingexpr.BillingSnapshot
BillingRequestInput *billingexpr.RequestInput
BillingImageCount *int
// ImageRequestCount is the effective quantity sent on the current attempt;
// ImageQuotaBeforeGroup is the frozen legacy estimate before request ratios.
ImageRequestCount int
ImageQuotaBeforeGroup float64
Request dto.Request
@@ -187,6 +201,10 @@ type RelayInfo struct {
FinalRequestRelayFormat types.RelayFormat
StreamStatus *StreamStatus
// PerformanceOutputTokens is captured by settlement and sampled once at
// the request boundary, independently of billing success or failure.
PerformanceOutputTokens int64
PerformanceBusinessRejection bool
// convOptions caches the converter settings snapshot (see ConvOptions).
convOptions *convmeta.Options
@@ -204,7 +222,36 @@ type RelayInfo struct {
*TaskRelayInfo
}
// UpdateImageCount replaces the billable quantity without changing the frozen
// request parameters or multiplying the legacy and expression prices together.
func (info *RelayInfo) UpdateImageCount(count int64) {
if info == nil || count <= 0 || count > int64(dto.MaxImageN) {
return
}
if info.PriceData.UsePrice {
info.PriceData.AddOtherRatio("n", float64(count))
}
if info.TieredBillingSnapshot != nil && info.TieredBillingSnapshot.EstimatedImageCount != nil {
n := int(count)
info.BillingImageCount = &n
}
}
func (info *RelayInfo) RequestedImageCount() int {
if info.ImageRequestCount > 0 {
return info.ImageRequestCount
}
if info.TieredBillingSnapshot != nil && info.TieredBillingSnapshot.EstimatedImageCount != nil {
return *info.TieredBillingSnapshot.EstimatedImageCount
}
if count, ok := info.PriceData.OtherRatios()["n"]; ok && count >= 1 && count <= dto.MaxImageN {
return int(count)
}
return 1
}
func (info *RelayInfo) InitChannelMeta(c *gin.Context) {
info.ResponseModel = nil
info.FinalRequestRelayFormat = ""
info.RequestConversionChain = nil
info.InitRequestConversionChain()
@@ -252,6 +299,15 @@ func (info *RelayInfo) InitChannelMeta(c *gin.Context) {
channelMeta.ChannelOtherSettings = channelOtherSettings
}
if channelType == constant.ChannelTypeAdvancedCustom &&
!channelMeta.ChannelSetting.PassThroughBodyEnabled &&
c.Request != nil && c.Request.URL != nil {
route, matched := channelMeta.ChannelOtherSettings.AdvancedCustom.MatchPathForModel(c.Request.URL.Path, info.OriginModelName)
if matched && route.PassThroughBodyEnabled {
channelMeta.ChannelSetting.PassThroughBodyEnabled = true
}
}
if streamSupportedChannels[channelMeta.ChannelType] {
channelMeta.SupportStreamOptions = true
}
@@ -377,6 +433,8 @@ var streamSupportedChannels = map[int]bool{
constant.ChannelTypeAdvancedCustom: true,
constant.ChannelTypeSub2API: true,
constant.ChannelTypeNewAPI: true,
constant.ChannelTypeVLLM: true,
constant.ChannelTypeSGLang: true,
constant.ChannelTypeTencent: true,
}
@@ -498,6 +556,9 @@ func reasoningEffortFromRequest(request dto.Request) string {
if req != nil && req.GenerationConfig.ThinkingConfig != nil {
config := req.GenerationConfig.ThinkingConfig
effort = config.ThinkingLevel
if canonical, err := kitreasoning.ParseEffort(effort); err == nil {
effort = string(canonical)
}
if effort == "" && config.ThinkingBudget != nil {
effort = string(kitreasoning.EffortFromBudget(*config.ThinkingBudget))
}
@@ -551,10 +612,12 @@ func genBaseRelayInfo(c *gin.Context, request dto.Request) *RelayInfo {
OriginModelName: originModelName,
TokenId: common.GetContextKeyInt(c, constant.ContextKeyTokenId),
TokenKey: common.GetContextKeyString(c, constant.ContextKeyTokenKey),
TokenUnlimited: common.GetContextKeyBool(c, constant.ContextKeyTokenUnlimited),
TokenGroup: tokenGroup,
TokenId: common.GetContextKeyInt(c, constant.ContextKeyTokenId),
TokenKey: common.GetContextKeyString(c, constant.ContextKeyTokenKey),
TokenUnlimited: common.GetContextKeyBool(c, constant.ContextKeyTokenUnlimited),
TokenGroup: tokenGroup,
AstraAutoSwitch: common.GetContextKeyBool(c, constant.ContextKeyTokenAstraAutoSwitch),
AstraDetectionDisabled: common.GetContextKeyBool(c, constant.ContextKeyTokenAstraDetectionDisabled),
isFirstResponse: true,
RelayMode: relayconstant.Path2RelayMode(c.Request.URL.Path),