Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
ff8b1b4a
Unverified
Commit
ff8b1b4a
authored
Feb 03, 2026
by
Wesley Liddick
Committed by
GitHub
Feb 03, 2026
Browse files
Merge pull request #467 from slovx2/main
Antigravity 相关BUG修复及调度优化
parents
c0c9c984
4cce21b1
Changes
62
Hide whitespace changes
Inline
Side-by-side
backend/ent/group.go
View file @
ff8b1b4a
...
@@ -56,10 +56,16 @@ type Group struct {
...
@@ -56,10 +56,16 @@ type Group struct {
ClaudeCodeOnly
bool
`json:"claude_code_only,omitempty"`
ClaudeCodeOnly
bool
`json:"claude_code_only,omitempty"`
// 非 Claude Code 请求降级使用的分组 ID
// 非 Claude Code 请求降级使用的分组 ID
FallbackGroupID
*
int64
`json:"fallback_group_id,omitempty"`
FallbackGroupID
*
int64
`json:"fallback_group_id,omitempty"`
// 无效请求兜底使用的分组 ID
FallbackGroupIDOnInvalidRequest
*
int64
`json:"fallback_group_id_on_invalid_request,omitempty"`
// 模型路由配置:模型模式 -> 优先账号ID列表
// 模型路由配置:模型模式 -> 优先账号ID列表
ModelRouting
map
[
string
][]
int64
`json:"model_routing,omitempty"`
ModelRouting
map
[
string
][]
int64
`json:"model_routing,omitempty"`
// 是否启用模型路由配置
// 是否启用模型路由配置
ModelRoutingEnabled
bool
`json:"model_routing_enabled,omitempty"`
ModelRoutingEnabled
bool
`json:"model_routing_enabled,omitempty"`
// 是否注入 MCP XML 调用协议提示词(仅 antigravity 平台)
McpXMLInject
bool
`json:"mcp_xml_inject,omitempty"`
// 支持的模型系列:claude, gemini_text, gemini_image
SupportedModelScopes
[]
string
`json:"supported_model_scopes,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the GroupQuery when eager-loading is set.
// The values are being populated by the GroupQuery when eager-loading is set.
Edges
GroupEdges
`json:"edges"`
Edges
GroupEdges
`json:"edges"`
...
@@ -166,13 +172,13 @@ func (*Group) scanValues(columns []string) ([]any, error) {
...
@@ -166,13 +172,13 @@ func (*Group) scanValues(columns []string) ([]any, error) {
values
:=
make
([]
any
,
len
(
columns
))
values
:=
make
([]
any
,
len
(
columns
))
for
i
:=
range
columns
{
for
i
:=
range
columns
{
switch
columns
[
i
]
{
switch
columns
[
i
]
{
case
group
.
FieldModelRouting
:
case
group
.
FieldModelRouting
,
group
.
FieldSupportedModelScopes
:
values
[
i
]
=
new
([]
byte
)
values
[
i
]
=
new
([]
byte
)
case
group
.
FieldIsExclusive
,
group
.
FieldClaudeCodeOnly
,
group
.
FieldModelRoutingEnabled
:
case
group
.
FieldIsExclusive
,
group
.
FieldClaudeCodeOnly
,
group
.
FieldModelRoutingEnabled
,
group
.
FieldMcpXMLInject
:
values
[
i
]
=
new
(
sql
.
NullBool
)
values
[
i
]
=
new
(
sql
.
NullBool
)
case
group
.
FieldRateMultiplier
,
group
.
FieldDailyLimitUsd
,
group
.
FieldWeeklyLimitUsd
,
group
.
FieldMonthlyLimitUsd
,
group
.
FieldImagePrice1k
,
group
.
FieldImagePrice2k
,
group
.
FieldImagePrice4k
:
case
group
.
FieldRateMultiplier
,
group
.
FieldDailyLimitUsd
,
group
.
FieldWeeklyLimitUsd
,
group
.
FieldMonthlyLimitUsd
,
group
.
FieldImagePrice1k
,
group
.
FieldImagePrice2k
,
group
.
FieldImagePrice4k
:
values
[
i
]
=
new
(
sql
.
NullFloat64
)
values
[
i
]
=
new
(
sql
.
NullFloat64
)
case
group
.
FieldID
,
group
.
FieldDefaultValidityDays
,
group
.
FieldFallbackGroupID
:
case
group
.
FieldID
,
group
.
FieldDefaultValidityDays
,
group
.
FieldFallbackGroupID
,
group
.
FieldFallbackGroupIDOnInvalidRequest
:
values
[
i
]
=
new
(
sql
.
NullInt64
)
values
[
i
]
=
new
(
sql
.
NullInt64
)
case
group
.
FieldName
,
group
.
FieldDescription
,
group
.
FieldStatus
,
group
.
FieldPlatform
,
group
.
FieldSubscriptionType
:
case
group
.
FieldName
,
group
.
FieldDescription
,
group
.
FieldStatus
,
group
.
FieldPlatform
,
group
.
FieldSubscriptionType
:
values
[
i
]
=
new
(
sql
.
NullString
)
values
[
i
]
=
new
(
sql
.
NullString
)
...
@@ -322,6 +328,13 @@ func (_m *Group) assignValues(columns []string, values []any) error {
...
@@ -322,6 +328,13 @@ func (_m *Group) assignValues(columns []string, values []any) error {
_m
.
FallbackGroupID
=
new
(
int64
)
_m
.
FallbackGroupID
=
new
(
int64
)
*
_m
.
FallbackGroupID
=
value
.
Int64
*
_m
.
FallbackGroupID
=
value
.
Int64
}
}
case
group
.
FieldFallbackGroupIDOnInvalidRequest
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullInt64
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field fallback_group_id_on_invalid_request"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
FallbackGroupIDOnInvalidRequest
=
new
(
int64
)
*
_m
.
FallbackGroupIDOnInvalidRequest
=
value
.
Int64
}
case
group
.
FieldModelRouting
:
case
group
.
FieldModelRouting
:
if
value
,
ok
:=
values
[
i
]
.
(
*
[]
byte
);
!
ok
{
if
value
,
ok
:=
values
[
i
]
.
(
*
[]
byte
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field model_routing"
,
values
[
i
])
return
fmt
.
Errorf
(
"unexpected type %T for field model_routing"
,
values
[
i
])
...
@@ -336,6 +349,20 @@ func (_m *Group) assignValues(columns []string, values []any) error {
...
@@ -336,6 +349,20 @@ func (_m *Group) assignValues(columns []string, values []any) error {
}
else
if
value
.
Valid
{
}
else
if
value
.
Valid
{
_m
.
ModelRoutingEnabled
=
value
.
Bool
_m
.
ModelRoutingEnabled
=
value
.
Bool
}
}
case
group
.
FieldMcpXMLInject
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullBool
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field mcp_xml_inject"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
McpXMLInject
=
value
.
Bool
}
case
group
.
FieldSupportedModelScopes
:
if
value
,
ok
:=
values
[
i
]
.
(
*
[]
byte
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field supported_model_scopes"
,
values
[
i
])
}
else
if
value
!=
nil
&&
len
(
*
value
)
>
0
{
if
err
:=
json
.
Unmarshal
(
*
value
,
&
_m
.
SupportedModelScopes
);
err
!=
nil
{
return
fmt
.
Errorf
(
"unmarshal field supported_model_scopes: %w"
,
err
)
}
}
default
:
default
:
_m
.
selectValues
.
Set
(
columns
[
i
],
values
[
i
])
_m
.
selectValues
.
Set
(
columns
[
i
],
values
[
i
])
}
}
...
@@ -487,11 +514,22 @@ func (_m *Group) String() string {
...
@@ -487,11 +514,22 @@ func (_m *Group) String() string {
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
*
v
))
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
*
v
))
}
}
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
FallbackGroupIDOnInvalidRequest
;
v
!=
nil
{
builder
.
WriteString
(
"fallback_group_id_on_invalid_request="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
*
v
))
}
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"model_routing="
)
builder
.
WriteString
(
"model_routing="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
ModelRouting
))
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
ModelRouting
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"model_routing_enabled="
)
builder
.
WriteString
(
"model_routing_enabled="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
ModelRoutingEnabled
))
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
ModelRoutingEnabled
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"mcp_xml_inject="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
McpXMLInject
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"supported_model_scopes="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
SupportedModelScopes
))
builder
.
WriteByte
(
')'
)
builder
.
WriteByte
(
')'
)
return
builder
.
String
()
return
builder
.
String
()
}
}
...
...
backend/ent/group/group.go
View file @
ff8b1b4a
...
@@ -53,10 +53,16 @@ const (
...
@@ -53,10 +53,16 @@ const (
FieldClaudeCodeOnly
=
"claude_code_only"
FieldClaudeCodeOnly
=
"claude_code_only"
// FieldFallbackGroupID holds the string denoting the fallback_group_id field in the database.
// FieldFallbackGroupID holds the string denoting the fallback_group_id field in the database.
FieldFallbackGroupID
=
"fallback_group_id"
FieldFallbackGroupID
=
"fallback_group_id"
// FieldFallbackGroupIDOnInvalidRequest holds the string denoting the fallback_group_id_on_invalid_request field in the database.
FieldFallbackGroupIDOnInvalidRequest
=
"fallback_group_id_on_invalid_request"
// FieldModelRouting holds the string denoting the model_routing field in the database.
// FieldModelRouting holds the string denoting the model_routing field in the database.
FieldModelRouting
=
"model_routing"
FieldModelRouting
=
"model_routing"
// FieldModelRoutingEnabled holds the string denoting the model_routing_enabled field in the database.
// FieldModelRoutingEnabled holds the string denoting the model_routing_enabled field in the database.
FieldModelRoutingEnabled
=
"model_routing_enabled"
FieldModelRoutingEnabled
=
"model_routing_enabled"
// FieldMcpXMLInject holds the string denoting the mcp_xml_inject field in the database.
FieldMcpXMLInject
=
"mcp_xml_inject"
// FieldSupportedModelScopes holds the string denoting the supported_model_scopes field in the database.
FieldSupportedModelScopes
=
"supported_model_scopes"
// EdgeAPIKeys holds the string denoting the api_keys edge name in mutations.
// EdgeAPIKeys holds the string denoting the api_keys edge name in mutations.
EdgeAPIKeys
=
"api_keys"
EdgeAPIKeys
=
"api_keys"
// EdgeRedeemCodes holds the string denoting the redeem_codes edge name in mutations.
// EdgeRedeemCodes holds the string denoting the redeem_codes edge name in mutations.
...
@@ -151,8 +157,11 @@ var Columns = []string{
...
@@ -151,8 +157,11 @@ var Columns = []string{
FieldImagePrice4k
,
FieldImagePrice4k
,
FieldClaudeCodeOnly
,
FieldClaudeCodeOnly
,
FieldFallbackGroupID
,
FieldFallbackGroupID
,
FieldFallbackGroupIDOnInvalidRequest
,
FieldModelRouting
,
FieldModelRouting
,
FieldModelRoutingEnabled
,
FieldModelRoutingEnabled
,
FieldMcpXMLInject
,
FieldSupportedModelScopes
,
}
}
var
(
var
(
...
@@ -212,6 +221,10 @@ var (
...
@@ -212,6 +221,10 @@ var (
DefaultClaudeCodeOnly
bool
DefaultClaudeCodeOnly
bool
// DefaultModelRoutingEnabled holds the default value on creation for the "model_routing_enabled" field.
// DefaultModelRoutingEnabled holds the default value on creation for the "model_routing_enabled" field.
DefaultModelRoutingEnabled
bool
DefaultModelRoutingEnabled
bool
// DefaultMcpXMLInject holds the default value on creation for the "mcp_xml_inject" field.
DefaultMcpXMLInject
bool
// DefaultSupportedModelScopes holds the default value on creation for the "supported_model_scopes" field.
DefaultSupportedModelScopes
[]
string
)
)
// OrderOption defines the ordering options for the Group queries.
// OrderOption defines the ordering options for the Group queries.
...
@@ -317,11 +330,21 @@ func ByFallbackGroupID(opts ...sql.OrderTermOption) OrderOption {
...
@@ -317,11 +330,21 @@ func ByFallbackGroupID(opts ...sql.OrderTermOption) OrderOption {
return
sql
.
OrderByField
(
FieldFallbackGroupID
,
opts
...
)
.
ToFunc
()
return
sql
.
OrderByField
(
FieldFallbackGroupID
,
opts
...
)
.
ToFunc
()
}
}
// ByFallbackGroupIDOnInvalidRequest orders the results by the fallback_group_id_on_invalid_request field.
func
ByFallbackGroupIDOnInvalidRequest
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldFallbackGroupIDOnInvalidRequest
,
opts
...
)
.
ToFunc
()
}
// ByModelRoutingEnabled orders the results by the model_routing_enabled field.
// ByModelRoutingEnabled orders the results by the model_routing_enabled field.
func
ByModelRoutingEnabled
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
func
ByModelRoutingEnabled
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldModelRoutingEnabled
,
opts
...
)
.
ToFunc
()
return
sql
.
OrderByField
(
FieldModelRoutingEnabled
,
opts
...
)
.
ToFunc
()
}
}
// ByMcpXMLInject orders the results by the mcp_xml_inject field.
func
ByMcpXMLInject
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldMcpXMLInject
,
opts
...
)
.
ToFunc
()
}
// ByAPIKeysCount orders the results by api_keys count.
// ByAPIKeysCount orders the results by api_keys count.
func
ByAPIKeysCount
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
func
ByAPIKeysCount
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
func
(
s
*
sql
.
Selector
)
{
return
func
(
s
*
sql
.
Selector
)
{
...
...
backend/ent/group/where.go
View file @
ff8b1b4a
...
@@ -150,11 +150,21 @@ func FallbackGroupID(v int64) predicate.Group {
...
@@ -150,11 +150,21 @@ func FallbackGroupID(v int64) predicate.Group {
return
predicate
.
Group
(
sql
.
FieldEQ
(
FieldFallbackGroupID
,
v
))
return
predicate
.
Group
(
sql
.
FieldEQ
(
FieldFallbackGroupID
,
v
))
}
}
// FallbackGroupIDOnInvalidRequest applies equality check predicate on the "fallback_group_id_on_invalid_request" field. It's identical to FallbackGroupIDOnInvalidRequestEQ.
func
FallbackGroupIDOnInvalidRequest
(
v
int64
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldEQ
(
FieldFallbackGroupIDOnInvalidRequest
,
v
))
}
// ModelRoutingEnabled applies equality check predicate on the "model_routing_enabled" field. It's identical to ModelRoutingEnabledEQ.
// ModelRoutingEnabled applies equality check predicate on the "model_routing_enabled" field. It's identical to ModelRoutingEnabledEQ.
func
ModelRoutingEnabled
(
v
bool
)
predicate
.
Group
{
func
ModelRoutingEnabled
(
v
bool
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldEQ
(
FieldModelRoutingEnabled
,
v
))
return
predicate
.
Group
(
sql
.
FieldEQ
(
FieldModelRoutingEnabled
,
v
))
}
}
// McpXMLInject applies equality check predicate on the "mcp_xml_inject" field. It's identical to McpXMLInjectEQ.
func
McpXMLInject
(
v
bool
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldEQ
(
FieldMcpXMLInject
,
v
))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func
CreatedAtEQ
(
v
time
.
Time
)
predicate
.
Group
{
func
CreatedAtEQ
(
v
time
.
Time
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldEQ
(
FieldCreatedAt
,
v
))
return
predicate
.
Group
(
sql
.
FieldEQ
(
FieldCreatedAt
,
v
))
...
@@ -1070,6 +1080,56 @@ func FallbackGroupIDNotNil() predicate.Group {
...
@@ -1070,6 +1080,56 @@ func FallbackGroupIDNotNil() predicate.Group {
return
predicate
.
Group
(
sql
.
FieldNotNull
(
FieldFallbackGroupID
))
return
predicate
.
Group
(
sql
.
FieldNotNull
(
FieldFallbackGroupID
))
}
}
// FallbackGroupIDOnInvalidRequestEQ applies the EQ predicate on the "fallback_group_id_on_invalid_request" field.
func
FallbackGroupIDOnInvalidRequestEQ
(
v
int64
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldEQ
(
FieldFallbackGroupIDOnInvalidRequest
,
v
))
}
// FallbackGroupIDOnInvalidRequestNEQ applies the NEQ predicate on the "fallback_group_id_on_invalid_request" field.
func
FallbackGroupIDOnInvalidRequestNEQ
(
v
int64
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldNEQ
(
FieldFallbackGroupIDOnInvalidRequest
,
v
))
}
// FallbackGroupIDOnInvalidRequestIn applies the In predicate on the "fallback_group_id_on_invalid_request" field.
func
FallbackGroupIDOnInvalidRequestIn
(
vs
...
int64
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldIn
(
FieldFallbackGroupIDOnInvalidRequest
,
vs
...
))
}
// FallbackGroupIDOnInvalidRequestNotIn applies the NotIn predicate on the "fallback_group_id_on_invalid_request" field.
func
FallbackGroupIDOnInvalidRequestNotIn
(
vs
...
int64
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldNotIn
(
FieldFallbackGroupIDOnInvalidRequest
,
vs
...
))
}
// FallbackGroupIDOnInvalidRequestGT applies the GT predicate on the "fallback_group_id_on_invalid_request" field.
func
FallbackGroupIDOnInvalidRequestGT
(
v
int64
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldGT
(
FieldFallbackGroupIDOnInvalidRequest
,
v
))
}
// FallbackGroupIDOnInvalidRequestGTE applies the GTE predicate on the "fallback_group_id_on_invalid_request" field.
func
FallbackGroupIDOnInvalidRequestGTE
(
v
int64
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldGTE
(
FieldFallbackGroupIDOnInvalidRequest
,
v
))
}
// FallbackGroupIDOnInvalidRequestLT applies the LT predicate on the "fallback_group_id_on_invalid_request" field.
func
FallbackGroupIDOnInvalidRequestLT
(
v
int64
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldLT
(
FieldFallbackGroupIDOnInvalidRequest
,
v
))
}
// FallbackGroupIDOnInvalidRequestLTE applies the LTE predicate on the "fallback_group_id_on_invalid_request" field.
func
FallbackGroupIDOnInvalidRequestLTE
(
v
int64
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldLTE
(
FieldFallbackGroupIDOnInvalidRequest
,
v
))
}
// FallbackGroupIDOnInvalidRequestIsNil applies the IsNil predicate on the "fallback_group_id_on_invalid_request" field.
func
FallbackGroupIDOnInvalidRequestIsNil
()
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldIsNull
(
FieldFallbackGroupIDOnInvalidRequest
))
}
// FallbackGroupIDOnInvalidRequestNotNil applies the NotNil predicate on the "fallback_group_id_on_invalid_request" field.
func
FallbackGroupIDOnInvalidRequestNotNil
()
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldNotNull
(
FieldFallbackGroupIDOnInvalidRequest
))
}
// ModelRoutingIsNil applies the IsNil predicate on the "model_routing" field.
// ModelRoutingIsNil applies the IsNil predicate on the "model_routing" field.
func
ModelRoutingIsNil
()
predicate
.
Group
{
func
ModelRoutingIsNil
()
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldIsNull
(
FieldModelRouting
))
return
predicate
.
Group
(
sql
.
FieldIsNull
(
FieldModelRouting
))
...
@@ -1090,6 +1150,16 @@ func ModelRoutingEnabledNEQ(v bool) predicate.Group {
...
@@ -1090,6 +1150,16 @@ func ModelRoutingEnabledNEQ(v bool) predicate.Group {
return
predicate
.
Group
(
sql
.
FieldNEQ
(
FieldModelRoutingEnabled
,
v
))
return
predicate
.
Group
(
sql
.
FieldNEQ
(
FieldModelRoutingEnabled
,
v
))
}
}
// McpXMLInjectEQ applies the EQ predicate on the "mcp_xml_inject" field.
func
McpXMLInjectEQ
(
v
bool
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldEQ
(
FieldMcpXMLInject
,
v
))
}
// McpXMLInjectNEQ applies the NEQ predicate on the "mcp_xml_inject" field.
func
McpXMLInjectNEQ
(
v
bool
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldNEQ
(
FieldMcpXMLInject
,
v
))
}
// HasAPIKeys applies the HasEdge predicate on the "api_keys" edge.
// HasAPIKeys applies the HasEdge predicate on the "api_keys" edge.
func
HasAPIKeys
()
predicate
.
Group
{
func
HasAPIKeys
()
predicate
.
Group
{
return
predicate
.
Group
(
func
(
s
*
sql
.
Selector
)
{
return
predicate
.
Group
(
func
(
s
*
sql
.
Selector
)
{
...
...
backend/ent/group_create.go
View file @
ff8b1b4a
...
@@ -286,6 +286,20 @@ func (_c *GroupCreate) SetNillableFallbackGroupID(v *int64) *GroupCreate {
...
@@ -286,6 +286,20 @@ func (_c *GroupCreate) SetNillableFallbackGroupID(v *int64) *GroupCreate {
return
_c
return
_c
}
}
// SetFallbackGroupIDOnInvalidRequest sets the "fallback_group_id_on_invalid_request" field.
func
(
_c
*
GroupCreate
)
SetFallbackGroupIDOnInvalidRequest
(
v
int64
)
*
GroupCreate
{
_c
.
mutation
.
SetFallbackGroupIDOnInvalidRequest
(
v
)
return
_c
}
// SetNillableFallbackGroupIDOnInvalidRequest sets the "fallback_group_id_on_invalid_request" field if the given value is not nil.
func
(
_c
*
GroupCreate
)
SetNillableFallbackGroupIDOnInvalidRequest
(
v
*
int64
)
*
GroupCreate
{
if
v
!=
nil
{
_c
.
SetFallbackGroupIDOnInvalidRequest
(
*
v
)
}
return
_c
}
// SetModelRouting sets the "model_routing" field.
// SetModelRouting sets the "model_routing" field.
func
(
_c
*
GroupCreate
)
SetModelRouting
(
v
map
[
string
][]
int64
)
*
GroupCreate
{
func
(
_c
*
GroupCreate
)
SetModelRouting
(
v
map
[
string
][]
int64
)
*
GroupCreate
{
_c
.
mutation
.
SetModelRouting
(
v
)
_c
.
mutation
.
SetModelRouting
(
v
)
...
@@ -306,6 +320,26 @@ func (_c *GroupCreate) SetNillableModelRoutingEnabled(v *bool) *GroupCreate {
...
@@ -306,6 +320,26 @@ func (_c *GroupCreate) SetNillableModelRoutingEnabled(v *bool) *GroupCreate {
return
_c
return
_c
}
}
// SetMcpXMLInject sets the "mcp_xml_inject" field.
func
(
_c
*
GroupCreate
)
SetMcpXMLInject
(
v
bool
)
*
GroupCreate
{
_c
.
mutation
.
SetMcpXMLInject
(
v
)
return
_c
}
// SetNillableMcpXMLInject sets the "mcp_xml_inject" field if the given value is not nil.
func
(
_c
*
GroupCreate
)
SetNillableMcpXMLInject
(
v
*
bool
)
*
GroupCreate
{
if
v
!=
nil
{
_c
.
SetMcpXMLInject
(
*
v
)
}
return
_c
}
// SetSupportedModelScopes sets the "supported_model_scopes" field.
func
(
_c
*
GroupCreate
)
SetSupportedModelScopes
(
v
[]
string
)
*
GroupCreate
{
_c
.
mutation
.
SetSupportedModelScopes
(
v
)
return
_c
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func
(
_c
*
GroupCreate
)
AddAPIKeyIDs
(
ids
...
int64
)
*
GroupCreate
{
func
(
_c
*
GroupCreate
)
AddAPIKeyIDs
(
ids
...
int64
)
*
GroupCreate
{
_c
.
mutation
.
AddAPIKeyIDs
(
ids
...
)
_c
.
mutation
.
AddAPIKeyIDs
(
ids
...
)
...
@@ -479,6 +513,14 @@ func (_c *GroupCreate) defaults() error {
...
@@ -479,6 +513,14 @@ func (_c *GroupCreate) defaults() error {
v
:=
group
.
DefaultModelRoutingEnabled
v
:=
group
.
DefaultModelRoutingEnabled
_c
.
mutation
.
SetModelRoutingEnabled
(
v
)
_c
.
mutation
.
SetModelRoutingEnabled
(
v
)
}
}
if
_
,
ok
:=
_c
.
mutation
.
McpXMLInject
();
!
ok
{
v
:=
group
.
DefaultMcpXMLInject
_c
.
mutation
.
SetMcpXMLInject
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
SupportedModelScopes
();
!
ok
{
v
:=
group
.
DefaultSupportedModelScopes
_c
.
mutation
.
SetSupportedModelScopes
(
v
)
}
return
nil
return
nil
}
}
...
@@ -537,6 +579,12 @@ func (_c *GroupCreate) check() error {
...
@@ -537,6 +579,12 @@ func (_c *GroupCreate) check() error {
if
_
,
ok
:=
_c
.
mutation
.
ModelRoutingEnabled
();
!
ok
{
if
_
,
ok
:=
_c
.
mutation
.
ModelRoutingEnabled
();
!
ok
{
return
&
ValidationError
{
Name
:
"model_routing_enabled"
,
err
:
errors
.
New
(
`ent: missing required field "Group.model_routing_enabled"`
)}
return
&
ValidationError
{
Name
:
"model_routing_enabled"
,
err
:
errors
.
New
(
`ent: missing required field "Group.model_routing_enabled"`
)}
}
}
if
_
,
ok
:=
_c
.
mutation
.
McpXMLInject
();
!
ok
{
return
&
ValidationError
{
Name
:
"mcp_xml_inject"
,
err
:
errors
.
New
(
`ent: missing required field "Group.mcp_xml_inject"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
SupportedModelScopes
();
!
ok
{
return
&
ValidationError
{
Name
:
"supported_model_scopes"
,
err
:
errors
.
New
(
`ent: missing required field "Group.supported_model_scopes"`
)}
}
return
nil
return
nil
}
}
...
@@ -640,6 +688,10 @@ func (_c *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) {
...
@@ -640,6 +688,10 @@ func (_c *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) {
_spec
.
SetField
(
group
.
FieldFallbackGroupID
,
field
.
TypeInt64
,
value
)
_spec
.
SetField
(
group
.
FieldFallbackGroupID
,
field
.
TypeInt64
,
value
)
_node
.
FallbackGroupID
=
&
value
_node
.
FallbackGroupID
=
&
value
}
}
if
value
,
ok
:=
_c
.
mutation
.
FallbackGroupIDOnInvalidRequest
();
ok
{
_spec
.
SetField
(
group
.
FieldFallbackGroupIDOnInvalidRequest
,
field
.
TypeInt64
,
value
)
_node
.
FallbackGroupIDOnInvalidRequest
=
&
value
}
if
value
,
ok
:=
_c
.
mutation
.
ModelRouting
();
ok
{
if
value
,
ok
:=
_c
.
mutation
.
ModelRouting
();
ok
{
_spec
.
SetField
(
group
.
FieldModelRouting
,
field
.
TypeJSON
,
value
)
_spec
.
SetField
(
group
.
FieldModelRouting
,
field
.
TypeJSON
,
value
)
_node
.
ModelRouting
=
value
_node
.
ModelRouting
=
value
...
@@ -648,6 +700,14 @@ func (_c *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) {
...
@@ -648,6 +700,14 @@ func (_c *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) {
_spec
.
SetField
(
group
.
FieldModelRoutingEnabled
,
field
.
TypeBool
,
value
)
_spec
.
SetField
(
group
.
FieldModelRoutingEnabled
,
field
.
TypeBool
,
value
)
_node
.
ModelRoutingEnabled
=
value
_node
.
ModelRoutingEnabled
=
value
}
}
if
value
,
ok
:=
_c
.
mutation
.
McpXMLInject
();
ok
{
_spec
.
SetField
(
group
.
FieldMcpXMLInject
,
field
.
TypeBool
,
value
)
_node
.
McpXMLInject
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
SupportedModelScopes
();
ok
{
_spec
.
SetField
(
group
.
FieldSupportedModelScopes
,
field
.
TypeJSON
,
value
)
_node
.
SupportedModelScopes
=
value
}
if
nodes
:=
_c
.
mutation
.
APIKeysIDs
();
len
(
nodes
)
>
0
{
if
nodes
:=
_c
.
mutation
.
APIKeysIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Rel
:
sqlgraph
.
O2M
,
...
@@ -1128,6 +1188,30 @@ func (u *GroupUpsert) ClearFallbackGroupID() *GroupUpsert {
...
@@ -1128,6 +1188,30 @@ func (u *GroupUpsert) ClearFallbackGroupID() *GroupUpsert {
return
u
return
u
}
}
// SetFallbackGroupIDOnInvalidRequest sets the "fallback_group_id_on_invalid_request" field.
func
(
u
*
GroupUpsert
)
SetFallbackGroupIDOnInvalidRequest
(
v
int64
)
*
GroupUpsert
{
u
.
Set
(
group
.
FieldFallbackGroupIDOnInvalidRequest
,
v
)
return
u
}
// UpdateFallbackGroupIDOnInvalidRequest sets the "fallback_group_id_on_invalid_request" field to the value that was provided on create.
func
(
u
*
GroupUpsert
)
UpdateFallbackGroupIDOnInvalidRequest
()
*
GroupUpsert
{
u
.
SetExcluded
(
group
.
FieldFallbackGroupIDOnInvalidRequest
)
return
u
}
// AddFallbackGroupIDOnInvalidRequest adds v to the "fallback_group_id_on_invalid_request" field.
func
(
u
*
GroupUpsert
)
AddFallbackGroupIDOnInvalidRequest
(
v
int64
)
*
GroupUpsert
{
u
.
Add
(
group
.
FieldFallbackGroupIDOnInvalidRequest
,
v
)
return
u
}
// ClearFallbackGroupIDOnInvalidRequest clears the value of the "fallback_group_id_on_invalid_request" field.
func
(
u
*
GroupUpsert
)
ClearFallbackGroupIDOnInvalidRequest
()
*
GroupUpsert
{
u
.
SetNull
(
group
.
FieldFallbackGroupIDOnInvalidRequest
)
return
u
}
// SetModelRouting sets the "model_routing" field.
// SetModelRouting sets the "model_routing" field.
func
(
u
*
GroupUpsert
)
SetModelRouting
(
v
map
[
string
][]
int64
)
*
GroupUpsert
{
func
(
u
*
GroupUpsert
)
SetModelRouting
(
v
map
[
string
][]
int64
)
*
GroupUpsert
{
u
.
Set
(
group
.
FieldModelRouting
,
v
)
u
.
Set
(
group
.
FieldModelRouting
,
v
)
...
@@ -1158,6 +1242,30 @@ func (u *GroupUpsert) UpdateModelRoutingEnabled() *GroupUpsert {
...
@@ -1158,6 +1242,30 @@ func (u *GroupUpsert) UpdateModelRoutingEnabled() *GroupUpsert {
return
u
return
u
}
}
// SetMcpXMLInject sets the "mcp_xml_inject" field.
func
(
u
*
GroupUpsert
)
SetMcpXMLInject
(
v
bool
)
*
GroupUpsert
{
u
.
Set
(
group
.
FieldMcpXMLInject
,
v
)
return
u
}
// UpdateMcpXMLInject sets the "mcp_xml_inject" field to the value that was provided on create.
func
(
u
*
GroupUpsert
)
UpdateMcpXMLInject
()
*
GroupUpsert
{
u
.
SetExcluded
(
group
.
FieldMcpXMLInject
)
return
u
}
// SetSupportedModelScopes sets the "supported_model_scopes" field.
func
(
u
*
GroupUpsert
)
SetSupportedModelScopes
(
v
[]
string
)
*
GroupUpsert
{
u
.
Set
(
group
.
FieldSupportedModelScopes
,
v
)
return
u
}
// UpdateSupportedModelScopes sets the "supported_model_scopes" field to the value that was provided on create.
func
(
u
*
GroupUpsert
)
UpdateSupportedModelScopes
()
*
GroupUpsert
{
u
.
SetExcluded
(
group
.
FieldSupportedModelScopes
)
return
u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
// Using this option is equivalent to using:
//
//
...
@@ -1581,6 +1689,34 @@ func (u *GroupUpsertOne) ClearFallbackGroupID() *GroupUpsertOne {
...
@@ -1581,6 +1689,34 @@ func (u *GroupUpsertOne) ClearFallbackGroupID() *GroupUpsertOne {
})
})
}
}
// SetFallbackGroupIDOnInvalidRequest sets the "fallback_group_id_on_invalid_request" field.
func
(
u
*
GroupUpsertOne
)
SetFallbackGroupIDOnInvalidRequest
(
v
int64
)
*
GroupUpsertOne
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
SetFallbackGroupIDOnInvalidRequest
(
v
)
})
}
// AddFallbackGroupIDOnInvalidRequest adds v to the "fallback_group_id_on_invalid_request" field.
func
(
u
*
GroupUpsertOne
)
AddFallbackGroupIDOnInvalidRequest
(
v
int64
)
*
GroupUpsertOne
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
AddFallbackGroupIDOnInvalidRequest
(
v
)
})
}
// UpdateFallbackGroupIDOnInvalidRequest sets the "fallback_group_id_on_invalid_request" field to the value that was provided on create.
func
(
u
*
GroupUpsertOne
)
UpdateFallbackGroupIDOnInvalidRequest
()
*
GroupUpsertOne
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
UpdateFallbackGroupIDOnInvalidRequest
()
})
}
// ClearFallbackGroupIDOnInvalidRequest clears the value of the "fallback_group_id_on_invalid_request" field.
func
(
u
*
GroupUpsertOne
)
ClearFallbackGroupIDOnInvalidRequest
()
*
GroupUpsertOne
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
ClearFallbackGroupIDOnInvalidRequest
()
})
}
// SetModelRouting sets the "model_routing" field.
// SetModelRouting sets the "model_routing" field.
func
(
u
*
GroupUpsertOne
)
SetModelRouting
(
v
map
[
string
][]
int64
)
*
GroupUpsertOne
{
func
(
u
*
GroupUpsertOne
)
SetModelRouting
(
v
map
[
string
][]
int64
)
*
GroupUpsertOne
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
...
@@ -1616,6 +1752,34 @@ func (u *GroupUpsertOne) UpdateModelRoutingEnabled() *GroupUpsertOne {
...
@@ -1616,6 +1752,34 @@ func (u *GroupUpsertOne) UpdateModelRoutingEnabled() *GroupUpsertOne {
})
})
}
}
// SetMcpXMLInject sets the "mcp_xml_inject" field.
func
(
u
*
GroupUpsertOne
)
SetMcpXMLInject
(
v
bool
)
*
GroupUpsertOne
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
SetMcpXMLInject
(
v
)
})
}
// UpdateMcpXMLInject sets the "mcp_xml_inject" field to the value that was provided on create.
func
(
u
*
GroupUpsertOne
)
UpdateMcpXMLInject
()
*
GroupUpsertOne
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
UpdateMcpXMLInject
()
})
}
// SetSupportedModelScopes sets the "supported_model_scopes" field.
func
(
u
*
GroupUpsertOne
)
SetSupportedModelScopes
(
v
[]
string
)
*
GroupUpsertOne
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
SetSupportedModelScopes
(
v
)
})
}
// UpdateSupportedModelScopes sets the "supported_model_scopes" field to the value that was provided on create.
func
(
u
*
GroupUpsertOne
)
UpdateSupportedModelScopes
()
*
GroupUpsertOne
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
UpdateSupportedModelScopes
()
})
}
// Exec executes the query.
// Exec executes the query.
func
(
u
*
GroupUpsertOne
)
Exec
(
ctx
context
.
Context
)
error
{
func
(
u
*
GroupUpsertOne
)
Exec
(
ctx
context
.
Context
)
error
{
if
len
(
u
.
create
.
conflict
)
==
0
{
if
len
(
u
.
create
.
conflict
)
==
0
{
...
@@ -2205,6 +2369,34 @@ func (u *GroupUpsertBulk) ClearFallbackGroupID() *GroupUpsertBulk {
...
@@ -2205,6 +2369,34 @@ func (u *GroupUpsertBulk) ClearFallbackGroupID() *GroupUpsertBulk {
})
})
}
}
// SetFallbackGroupIDOnInvalidRequest sets the "fallback_group_id_on_invalid_request" field.
func
(
u
*
GroupUpsertBulk
)
SetFallbackGroupIDOnInvalidRequest
(
v
int64
)
*
GroupUpsertBulk
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
SetFallbackGroupIDOnInvalidRequest
(
v
)
})
}
// AddFallbackGroupIDOnInvalidRequest adds v to the "fallback_group_id_on_invalid_request" field.
func
(
u
*
GroupUpsertBulk
)
AddFallbackGroupIDOnInvalidRequest
(
v
int64
)
*
GroupUpsertBulk
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
AddFallbackGroupIDOnInvalidRequest
(
v
)
})
}
// UpdateFallbackGroupIDOnInvalidRequest sets the "fallback_group_id_on_invalid_request" field to the value that was provided on create.
func
(
u
*
GroupUpsertBulk
)
UpdateFallbackGroupIDOnInvalidRequest
()
*
GroupUpsertBulk
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
UpdateFallbackGroupIDOnInvalidRequest
()
})
}
// ClearFallbackGroupIDOnInvalidRequest clears the value of the "fallback_group_id_on_invalid_request" field.
func
(
u
*
GroupUpsertBulk
)
ClearFallbackGroupIDOnInvalidRequest
()
*
GroupUpsertBulk
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
ClearFallbackGroupIDOnInvalidRequest
()
})
}
// SetModelRouting sets the "model_routing" field.
// SetModelRouting sets the "model_routing" field.
func
(
u
*
GroupUpsertBulk
)
SetModelRouting
(
v
map
[
string
][]
int64
)
*
GroupUpsertBulk
{
func
(
u
*
GroupUpsertBulk
)
SetModelRouting
(
v
map
[
string
][]
int64
)
*
GroupUpsertBulk
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
...
@@ -2240,6 +2432,34 @@ func (u *GroupUpsertBulk) UpdateModelRoutingEnabled() *GroupUpsertBulk {
...
@@ -2240,6 +2432,34 @@ func (u *GroupUpsertBulk) UpdateModelRoutingEnabled() *GroupUpsertBulk {
})
})
}
}
// SetMcpXMLInject sets the "mcp_xml_inject" field.
func
(
u
*
GroupUpsertBulk
)
SetMcpXMLInject
(
v
bool
)
*
GroupUpsertBulk
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
SetMcpXMLInject
(
v
)
})
}
// UpdateMcpXMLInject sets the "mcp_xml_inject" field to the value that was provided on create.
func
(
u
*
GroupUpsertBulk
)
UpdateMcpXMLInject
()
*
GroupUpsertBulk
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
UpdateMcpXMLInject
()
})
}
// SetSupportedModelScopes sets the "supported_model_scopes" field.
func
(
u
*
GroupUpsertBulk
)
SetSupportedModelScopes
(
v
[]
string
)
*
GroupUpsertBulk
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
SetSupportedModelScopes
(
v
)
})
}
// UpdateSupportedModelScopes sets the "supported_model_scopes" field to the value that was provided on create.
func
(
u
*
GroupUpsertBulk
)
UpdateSupportedModelScopes
()
*
GroupUpsertBulk
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
UpdateSupportedModelScopes
()
})
}
// Exec executes the query.
// Exec executes the query.
func
(
u
*
GroupUpsertBulk
)
Exec
(
ctx
context
.
Context
)
error
{
func
(
u
*
GroupUpsertBulk
)
Exec
(
ctx
context
.
Context
)
error
{
if
u
.
create
.
err
!=
nil
{
if
u
.
create
.
err
!=
nil
{
...
...
backend/ent/group_update.go
View file @
ff8b1b4a
...
@@ -10,6 +10,7 @@ import (
...
@@ -10,6 +10,7 @@ import (
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/dialect/sql/sqljson"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/account"
"github.com/Wei-Shaw/sub2api/ent/account"
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/apikey"
...
@@ -395,6 +396,33 @@ func (_u *GroupUpdate) ClearFallbackGroupID() *GroupUpdate {
...
@@ -395,6 +396,33 @@ func (_u *GroupUpdate) ClearFallbackGroupID() *GroupUpdate {
return
_u
return
_u
}
}
// SetFallbackGroupIDOnInvalidRequest sets the "fallback_group_id_on_invalid_request" field.
func
(
_u
*
GroupUpdate
)
SetFallbackGroupIDOnInvalidRequest
(
v
int64
)
*
GroupUpdate
{
_u
.
mutation
.
ResetFallbackGroupIDOnInvalidRequest
()
_u
.
mutation
.
SetFallbackGroupIDOnInvalidRequest
(
v
)
return
_u
}
// SetNillableFallbackGroupIDOnInvalidRequest sets the "fallback_group_id_on_invalid_request" field if the given value is not nil.
func
(
_u
*
GroupUpdate
)
SetNillableFallbackGroupIDOnInvalidRequest
(
v
*
int64
)
*
GroupUpdate
{
if
v
!=
nil
{
_u
.
SetFallbackGroupIDOnInvalidRequest
(
*
v
)
}
return
_u
}
// AddFallbackGroupIDOnInvalidRequest adds value to the "fallback_group_id_on_invalid_request" field.
func
(
_u
*
GroupUpdate
)
AddFallbackGroupIDOnInvalidRequest
(
v
int64
)
*
GroupUpdate
{
_u
.
mutation
.
AddFallbackGroupIDOnInvalidRequest
(
v
)
return
_u
}
// ClearFallbackGroupIDOnInvalidRequest clears the value of the "fallback_group_id_on_invalid_request" field.
func
(
_u
*
GroupUpdate
)
ClearFallbackGroupIDOnInvalidRequest
()
*
GroupUpdate
{
_u
.
mutation
.
ClearFallbackGroupIDOnInvalidRequest
()
return
_u
}
// SetModelRouting sets the "model_routing" field.
// SetModelRouting sets the "model_routing" field.
func
(
_u
*
GroupUpdate
)
SetModelRouting
(
v
map
[
string
][]
int64
)
*
GroupUpdate
{
func
(
_u
*
GroupUpdate
)
SetModelRouting
(
v
map
[
string
][]
int64
)
*
GroupUpdate
{
_u
.
mutation
.
SetModelRouting
(
v
)
_u
.
mutation
.
SetModelRouting
(
v
)
...
@@ -421,6 +449,32 @@ func (_u *GroupUpdate) SetNillableModelRoutingEnabled(v *bool) *GroupUpdate {
...
@@ -421,6 +449,32 @@ func (_u *GroupUpdate) SetNillableModelRoutingEnabled(v *bool) *GroupUpdate {
return
_u
return
_u
}
}
// SetMcpXMLInject sets the "mcp_xml_inject" field.
func
(
_u
*
GroupUpdate
)
SetMcpXMLInject
(
v
bool
)
*
GroupUpdate
{
_u
.
mutation
.
SetMcpXMLInject
(
v
)
return
_u
}
// SetNillableMcpXMLInject sets the "mcp_xml_inject" field if the given value is not nil.
func
(
_u
*
GroupUpdate
)
SetNillableMcpXMLInject
(
v
*
bool
)
*
GroupUpdate
{
if
v
!=
nil
{
_u
.
SetMcpXMLInject
(
*
v
)
}
return
_u
}
// SetSupportedModelScopes sets the "supported_model_scopes" field.
func
(
_u
*
GroupUpdate
)
SetSupportedModelScopes
(
v
[]
string
)
*
GroupUpdate
{
_u
.
mutation
.
SetSupportedModelScopes
(
v
)
return
_u
}
// AppendSupportedModelScopes appends value to the "supported_model_scopes" field.
func
(
_u
*
GroupUpdate
)
AppendSupportedModelScopes
(
v
[]
string
)
*
GroupUpdate
{
_u
.
mutation
.
AppendSupportedModelScopes
(
v
)
return
_u
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func
(
_u
*
GroupUpdate
)
AddAPIKeyIDs
(
ids
...
int64
)
*
GroupUpdate
{
func
(
_u
*
GroupUpdate
)
AddAPIKeyIDs
(
ids
...
int64
)
*
GroupUpdate
{
_u
.
mutation
.
AddAPIKeyIDs
(
ids
...
)
_u
.
mutation
.
AddAPIKeyIDs
(
ids
...
)
...
@@ -829,6 +883,15 @@ func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) {
...
@@ -829,6 +883,15 @@ func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if
_u
.
mutation
.
FallbackGroupIDCleared
()
{
if
_u
.
mutation
.
FallbackGroupIDCleared
()
{
_spec
.
ClearField
(
group
.
FieldFallbackGroupID
,
field
.
TypeInt64
)
_spec
.
ClearField
(
group
.
FieldFallbackGroupID
,
field
.
TypeInt64
)
}
}
if
value
,
ok
:=
_u
.
mutation
.
FallbackGroupIDOnInvalidRequest
();
ok
{
_spec
.
SetField
(
group
.
FieldFallbackGroupIDOnInvalidRequest
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedFallbackGroupIDOnInvalidRequest
();
ok
{
_spec
.
AddField
(
group
.
FieldFallbackGroupIDOnInvalidRequest
,
field
.
TypeInt64
,
value
)
}
if
_u
.
mutation
.
FallbackGroupIDOnInvalidRequestCleared
()
{
_spec
.
ClearField
(
group
.
FieldFallbackGroupIDOnInvalidRequest
,
field
.
TypeInt64
)
}
if
value
,
ok
:=
_u
.
mutation
.
ModelRouting
();
ok
{
if
value
,
ok
:=
_u
.
mutation
.
ModelRouting
();
ok
{
_spec
.
SetField
(
group
.
FieldModelRouting
,
field
.
TypeJSON
,
value
)
_spec
.
SetField
(
group
.
FieldModelRouting
,
field
.
TypeJSON
,
value
)
}
}
...
@@ -838,6 +901,17 @@ func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) {
...
@@ -838,6 +901,17 @@ func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if
value
,
ok
:=
_u
.
mutation
.
ModelRoutingEnabled
();
ok
{
if
value
,
ok
:=
_u
.
mutation
.
ModelRoutingEnabled
();
ok
{
_spec
.
SetField
(
group
.
FieldModelRoutingEnabled
,
field
.
TypeBool
,
value
)
_spec
.
SetField
(
group
.
FieldModelRoutingEnabled
,
field
.
TypeBool
,
value
)
}
}
if
value
,
ok
:=
_u
.
mutation
.
McpXMLInject
();
ok
{
_spec
.
SetField
(
group
.
FieldMcpXMLInject
,
field
.
TypeBool
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
SupportedModelScopes
();
ok
{
_spec
.
SetField
(
group
.
FieldSupportedModelScopes
,
field
.
TypeJSON
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AppendedSupportedModelScopes
();
ok
{
_spec
.
AddModifier
(
func
(
u
*
sql
.
UpdateBuilder
)
{
sqljson
.
Append
(
u
,
group
.
FieldSupportedModelScopes
,
value
)
})
}
if
_u
.
mutation
.
APIKeysCleared
()
{
if
_u
.
mutation
.
APIKeysCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Rel
:
sqlgraph
.
O2M
,
...
@@ -1513,6 +1587,33 @@ func (_u *GroupUpdateOne) ClearFallbackGroupID() *GroupUpdateOne {
...
@@ -1513,6 +1587,33 @@ func (_u *GroupUpdateOne) ClearFallbackGroupID() *GroupUpdateOne {
return
_u
return
_u
}
}
// SetFallbackGroupIDOnInvalidRequest sets the "fallback_group_id_on_invalid_request" field.
func
(
_u
*
GroupUpdateOne
)
SetFallbackGroupIDOnInvalidRequest
(
v
int64
)
*
GroupUpdateOne
{
_u
.
mutation
.
ResetFallbackGroupIDOnInvalidRequest
()
_u
.
mutation
.
SetFallbackGroupIDOnInvalidRequest
(
v
)
return
_u
}
// SetNillableFallbackGroupIDOnInvalidRequest sets the "fallback_group_id_on_invalid_request" field if the given value is not nil.
func
(
_u
*
GroupUpdateOne
)
SetNillableFallbackGroupIDOnInvalidRequest
(
v
*
int64
)
*
GroupUpdateOne
{
if
v
!=
nil
{
_u
.
SetFallbackGroupIDOnInvalidRequest
(
*
v
)
}
return
_u
}
// AddFallbackGroupIDOnInvalidRequest adds value to the "fallback_group_id_on_invalid_request" field.
func
(
_u
*
GroupUpdateOne
)
AddFallbackGroupIDOnInvalidRequest
(
v
int64
)
*
GroupUpdateOne
{
_u
.
mutation
.
AddFallbackGroupIDOnInvalidRequest
(
v
)
return
_u
}
// ClearFallbackGroupIDOnInvalidRequest clears the value of the "fallback_group_id_on_invalid_request" field.
func
(
_u
*
GroupUpdateOne
)
ClearFallbackGroupIDOnInvalidRequest
()
*
GroupUpdateOne
{
_u
.
mutation
.
ClearFallbackGroupIDOnInvalidRequest
()
return
_u
}
// SetModelRouting sets the "model_routing" field.
// SetModelRouting sets the "model_routing" field.
func
(
_u
*
GroupUpdateOne
)
SetModelRouting
(
v
map
[
string
][]
int64
)
*
GroupUpdateOne
{
func
(
_u
*
GroupUpdateOne
)
SetModelRouting
(
v
map
[
string
][]
int64
)
*
GroupUpdateOne
{
_u
.
mutation
.
SetModelRouting
(
v
)
_u
.
mutation
.
SetModelRouting
(
v
)
...
@@ -1539,6 +1640,32 @@ func (_u *GroupUpdateOne) SetNillableModelRoutingEnabled(v *bool) *GroupUpdateOn
...
@@ -1539,6 +1640,32 @@ func (_u *GroupUpdateOne) SetNillableModelRoutingEnabled(v *bool) *GroupUpdateOn
return
_u
return
_u
}
}
// SetMcpXMLInject sets the "mcp_xml_inject" field.
func
(
_u
*
GroupUpdateOne
)
SetMcpXMLInject
(
v
bool
)
*
GroupUpdateOne
{
_u
.
mutation
.
SetMcpXMLInject
(
v
)
return
_u
}
// SetNillableMcpXMLInject sets the "mcp_xml_inject" field if the given value is not nil.
func
(
_u
*
GroupUpdateOne
)
SetNillableMcpXMLInject
(
v
*
bool
)
*
GroupUpdateOne
{
if
v
!=
nil
{
_u
.
SetMcpXMLInject
(
*
v
)
}
return
_u
}
// SetSupportedModelScopes sets the "supported_model_scopes" field.
func
(
_u
*
GroupUpdateOne
)
SetSupportedModelScopes
(
v
[]
string
)
*
GroupUpdateOne
{
_u
.
mutation
.
SetSupportedModelScopes
(
v
)
return
_u
}
// AppendSupportedModelScopes appends value to the "supported_model_scopes" field.
func
(
_u
*
GroupUpdateOne
)
AppendSupportedModelScopes
(
v
[]
string
)
*
GroupUpdateOne
{
_u
.
mutation
.
AppendSupportedModelScopes
(
v
)
return
_u
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func
(
_u
*
GroupUpdateOne
)
AddAPIKeyIDs
(
ids
...
int64
)
*
GroupUpdateOne
{
func
(
_u
*
GroupUpdateOne
)
AddAPIKeyIDs
(
ids
...
int64
)
*
GroupUpdateOne
{
_u
.
mutation
.
AddAPIKeyIDs
(
ids
...
)
_u
.
mutation
.
AddAPIKeyIDs
(
ids
...
)
...
@@ -1977,6 +2104,15 @@ func (_u *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error)
...
@@ -1977,6 +2104,15 @@ func (_u *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error)
if
_u
.
mutation
.
FallbackGroupIDCleared
()
{
if
_u
.
mutation
.
FallbackGroupIDCleared
()
{
_spec
.
ClearField
(
group
.
FieldFallbackGroupID
,
field
.
TypeInt64
)
_spec
.
ClearField
(
group
.
FieldFallbackGroupID
,
field
.
TypeInt64
)
}
}
if
value
,
ok
:=
_u
.
mutation
.
FallbackGroupIDOnInvalidRequest
();
ok
{
_spec
.
SetField
(
group
.
FieldFallbackGroupIDOnInvalidRequest
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedFallbackGroupIDOnInvalidRequest
();
ok
{
_spec
.
AddField
(
group
.
FieldFallbackGroupIDOnInvalidRequest
,
field
.
TypeInt64
,
value
)
}
if
_u
.
mutation
.
FallbackGroupIDOnInvalidRequestCleared
()
{
_spec
.
ClearField
(
group
.
FieldFallbackGroupIDOnInvalidRequest
,
field
.
TypeInt64
)
}
if
value
,
ok
:=
_u
.
mutation
.
ModelRouting
();
ok
{
if
value
,
ok
:=
_u
.
mutation
.
ModelRouting
();
ok
{
_spec
.
SetField
(
group
.
FieldModelRouting
,
field
.
TypeJSON
,
value
)
_spec
.
SetField
(
group
.
FieldModelRouting
,
field
.
TypeJSON
,
value
)
}
}
...
@@ -1986,6 +2122,17 @@ func (_u *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error)
...
@@ -1986,6 +2122,17 @@ func (_u *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error)
if
value
,
ok
:=
_u
.
mutation
.
ModelRoutingEnabled
();
ok
{
if
value
,
ok
:=
_u
.
mutation
.
ModelRoutingEnabled
();
ok
{
_spec
.
SetField
(
group
.
FieldModelRoutingEnabled
,
field
.
TypeBool
,
value
)
_spec
.
SetField
(
group
.
FieldModelRoutingEnabled
,
field
.
TypeBool
,
value
)
}
}
if
value
,
ok
:=
_u
.
mutation
.
McpXMLInject
();
ok
{
_spec
.
SetField
(
group
.
FieldMcpXMLInject
,
field
.
TypeBool
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
SupportedModelScopes
();
ok
{
_spec
.
SetField
(
group
.
FieldSupportedModelScopes
,
field
.
TypeJSON
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AppendedSupportedModelScopes
();
ok
{
_spec
.
AddModifier
(
func
(
u
*
sql
.
UpdateBuilder
)
{
sqljson
.
Append
(
u
,
group
.
FieldSupportedModelScopes
,
value
)
})
}
if
_u
.
mutation
.
APIKeysCleared
()
{
if
_u
.
mutation
.
APIKeysCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Rel
:
sqlgraph
.
O2M
,
...
...
backend/ent/migrate/schema.go
View file @
ff8b1b4a
...
@@ -331,8 +331,11 @@ var (
...
@@ -331,8 +331,11 @@ var (
{
Name
:
"image_price_4k"
,
Type
:
field
.
TypeFloat64
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"decimal(20,8)"
}},
{
Name
:
"image_price_4k"
,
Type
:
field
.
TypeFloat64
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"decimal(20,8)"
}},
{
Name
:
"claude_code_only"
,
Type
:
field
.
TypeBool
,
Default
:
false
},
{
Name
:
"claude_code_only"
,
Type
:
field
.
TypeBool
,
Default
:
false
},
{
Name
:
"fallback_group_id"
,
Type
:
field
.
TypeInt64
,
Nullable
:
true
},
{
Name
:
"fallback_group_id"
,
Type
:
field
.
TypeInt64
,
Nullable
:
true
},
{
Name
:
"fallback_group_id_on_invalid_request"
,
Type
:
field
.
TypeInt64
,
Nullable
:
true
},
{
Name
:
"model_routing"
,
Type
:
field
.
TypeJSON
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"jsonb"
}},
{
Name
:
"model_routing"
,
Type
:
field
.
TypeJSON
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"jsonb"
}},
{
Name
:
"model_routing_enabled"
,
Type
:
field
.
TypeBool
,
Default
:
false
},
{
Name
:
"model_routing_enabled"
,
Type
:
field
.
TypeBool
,
Default
:
false
},
{
Name
:
"mcp_xml_inject"
,
Type
:
field
.
TypeBool
,
Default
:
true
},
{
Name
:
"supported_model_scopes"
,
Type
:
field
.
TypeJSON
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"jsonb"
}},
}
}
// GroupsTable holds the schema information for the "groups" table.
// GroupsTable holds the schema information for the "groups" table.
GroupsTable
=
&
schema
.
Table
{
GroupsTable
=
&
schema
.
Table
{
...
...
backend/ent/mutation.go
View file @
ff8b1b4a
...
@@ -5753,61 +5753,66 @@ func (m *AnnouncementReadMutation) ResetEdge(name string) error {
...
@@ -5753,61 +5753,66 @@ func (m *AnnouncementReadMutation) ResetEdge(name string) error {
// GroupMutation represents an operation that mutates the Group nodes in the graph.
// GroupMutation represents an operation that mutates the Group nodes in the graph.
type GroupMutation struct {
type GroupMutation struct {
config
config
op Op
op Op
typ string
typ string
id *int64
id *int64
created_at *time.Time
created_at *time.Time
updated_at *time.Time
updated_at *time.Time
deleted_at *time.Time
deleted_at *time.Time
name *string
name *string
description *string
description *string
rate_multiplier *float64
rate_multiplier *float64
addrate_multiplier *float64
addrate_multiplier *float64
is_exclusive *bool
is_exclusive *bool
status *string
status *string
platform *string
platform *string
subscription_type *string
subscription_type *string
daily_limit_usd *float64
daily_limit_usd *float64
adddaily_limit_usd *float64
adddaily_limit_usd *float64
weekly_limit_usd *float64
weekly_limit_usd *float64
addweekly_limit_usd *float64
addweekly_limit_usd *float64
monthly_limit_usd *float64
monthly_limit_usd *float64
addmonthly_limit_usd *float64
addmonthly_limit_usd *float64
default_validity_days *int
default_validity_days *int
adddefault_validity_days *int
adddefault_validity_days *int
image_price_1k *float64
image_price_1k *float64
addimage_price_1k *float64
addimage_price_1k *float64
image_price_2k *float64
image_price_2k *float64
addimage_price_2k *float64
addimage_price_2k *float64
image_price_4k *float64
image_price_4k *float64
addimage_price_4k *float64
addimage_price_4k *float64
claude_code_only *bool
claude_code_only *bool
fallback_group_id *int64
fallback_group_id *int64
addfallback_group_id *int64
addfallback_group_id *int64
model_routing *map[string][]int64
fallback_group_id_on_invalid_request *int64
model_routing_enabled *bool
addfallback_group_id_on_invalid_request *int64
clearedFields map[string]struct{}
model_routing *map[string][]int64
api_keys map[int64]struct{}
model_routing_enabled *bool
removedapi_keys map[int64]struct{}
mcp_xml_inject *bool
clearedapi_keys bool
supported_model_scopes *[]string
redeem_codes map[int64]struct{}
appendsupported_model_scopes []string
removedredeem_codes map[int64]struct{}
clearedFields map[string]struct{}
clearedredeem_codes bool
api_keys map[int64]struct{}
subscriptions map[int64]struct{}
removedapi_keys map[int64]struct{}
removedsubscriptions map[int64]struct{}
clearedapi_keys bool
clearedsubscriptions bool
redeem_codes map[int64]struct{}
usage_logs map[int64]struct{}
removedredeem_codes map[int64]struct{}
removedusage_logs map[int64]struct{}
clearedredeem_codes bool
clearedusage_logs bool
subscriptions map[int64]struct{}
accounts map[int64]struct{}
removedsubscriptions map[int64]struct{}
removedaccounts map[int64]struct{}
clearedsubscriptions bool
clearedaccounts bool
usage_logs map[int64]struct{}
allowed_users map[int64]struct{}
removedusage_logs map[int64]struct{}
removedallowed_users map[int64]struct{}
clearedusage_logs bool
clearedallowed_users bool
accounts map[int64]struct{}
done bool
removedaccounts map[int64]struct{}
oldValue func(context.Context) (*Group, error)
clearedaccounts bool
predicates []predicate.Group
allowed_users map[int64]struct{}
removedallowed_users map[int64]struct{}
clearedallowed_users bool
done bool
oldValue func(context.Context) (*Group, error)
predicates []predicate.Group
}
}
var _ ent.Mutation = (*GroupMutation)(nil)
var _ ent.Mutation = (*GroupMutation)(nil)
...
@@ -6896,6 +6901,76 @@ func (m *GroupMutation) ResetFallbackGroupID() {
...
@@ -6896,6 +6901,76 @@ func (m *GroupMutation) ResetFallbackGroupID() {
delete(m.clearedFields, group.FieldFallbackGroupID)
delete(m.clearedFields, group.FieldFallbackGroupID)
}
}
// SetFallbackGroupIDOnInvalidRequest sets the "fallback_group_id_on_invalid_request" field.
func (m *GroupMutation) SetFallbackGroupIDOnInvalidRequest(i int64) {
m.fallback_group_id_on_invalid_request = &i
m.addfallback_group_id_on_invalid_request = nil
}
// FallbackGroupIDOnInvalidRequest returns the value of the "fallback_group_id_on_invalid_request" field in the mutation.
func (m *GroupMutation) FallbackGroupIDOnInvalidRequest() (r int64, exists bool) {
v := m.fallback_group_id_on_invalid_request
if v == nil {
return
}
return *v, true
}
// OldFallbackGroupIDOnInvalidRequest returns the old "fallback_group_id_on_invalid_request" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldFallbackGroupIDOnInvalidRequest(ctx context.Context) (v *int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldFallbackGroupIDOnInvalidRequest is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldFallbackGroupIDOnInvalidRequest requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldFallbackGroupIDOnInvalidRequest: %w", err)
}
return oldValue.FallbackGroupIDOnInvalidRequest, nil
}
// AddFallbackGroupIDOnInvalidRequest adds i to the "fallback_group_id_on_invalid_request" field.
func (m *GroupMutation) AddFallbackGroupIDOnInvalidRequest(i int64) {
if m.addfallback_group_id_on_invalid_request != nil {
*m.addfallback_group_id_on_invalid_request += i
} else {
m.addfallback_group_id_on_invalid_request = &i
}
}
// AddedFallbackGroupIDOnInvalidRequest returns the value that was added to the "fallback_group_id_on_invalid_request" field in this mutation.
func (m *GroupMutation) AddedFallbackGroupIDOnInvalidRequest() (r int64, exists bool) {
v := m.addfallback_group_id_on_invalid_request
if v == nil {
return
}
return *v, true
}
// ClearFallbackGroupIDOnInvalidRequest clears the value of the "fallback_group_id_on_invalid_request" field.
func (m *GroupMutation) ClearFallbackGroupIDOnInvalidRequest() {
m.fallback_group_id_on_invalid_request = nil
m.addfallback_group_id_on_invalid_request = nil
m.clearedFields[group.FieldFallbackGroupIDOnInvalidRequest] = struct{}{}
}
// FallbackGroupIDOnInvalidRequestCleared returns if the "fallback_group_id_on_invalid_request" field was cleared in this mutation.
func (m *GroupMutation) FallbackGroupIDOnInvalidRequestCleared() bool {
_, ok := m.clearedFields[group.FieldFallbackGroupIDOnInvalidRequest]
return ok
}
// ResetFallbackGroupIDOnInvalidRequest resets all changes to the "fallback_group_id_on_invalid_request" field.
func (m *GroupMutation) ResetFallbackGroupIDOnInvalidRequest() {
m.fallback_group_id_on_invalid_request = nil
m.addfallback_group_id_on_invalid_request = nil
delete(m.clearedFields, group.FieldFallbackGroupIDOnInvalidRequest)
}
// SetModelRouting sets the "model_routing" field.
// SetModelRouting sets the "model_routing" field.
func (m *GroupMutation) SetModelRouting(value map[string][]int64) {
func (m *GroupMutation) SetModelRouting(value map[string][]int64) {
m.model_routing = &value
m.model_routing = &value
...
@@ -6981,6 +7056,93 @@ func (m *GroupMutation) ResetModelRoutingEnabled() {
...
@@ -6981,6 +7056,93 @@ func (m *GroupMutation) ResetModelRoutingEnabled() {
m.model_routing_enabled = nil
m.model_routing_enabled = nil
}
}
// SetMcpXMLInject sets the "mcp_xml_inject" field.
func (m *GroupMutation) SetMcpXMLInject(b bool) {
m.mcp_xml_inject = &b
}
// McpXMLInject returns the value of the "mcp_xml_inject" field in the mutation.
func (m *GroupMutation) McpXMLInject() (r bool, exists bool) {
v := m.mcp_xml_inject
if v == nil {
return
}
return *v, true
}
// OldMcpXMLInject returns the old "mcp_xml_inject" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldMcpXMLInject(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldMcpXMLInject is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldMcpXMLInject requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldMcpXMLInject: %w", err)
}
return oldValue.McpXMLInject, nil
}
// ResetMcpXMLInject resets all changes to the "mcp_xml_inject" field.
func (m *GroupMutation) ResetMcpXMLInject() {
m.mcp_xml_inject = nil
}
// SetSupportedModelScopes sets the "supported_model_scopes" field.
func (m *GroupMutation) SetSupportedModelScopes(s []string) {
m.supported_model_scopes = &s
m.appendsupported_model_scopes = nil
}
// SupportedModelScopes returns the value of the "supported_model_scopes" field in the mutation.
func (m *GroupMutation) SupportedModelScopes() (r []string, exists bool) {
v := m.supported_model_scopes
if v == nil {
return
}
return *v, true
}
// OldSupportedModelScopes returns the old "supported_model_scopes" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldSupportedModelScopes(ctx context.Context) (v []string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldSupportedModelScopes is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldSupportedModelScopes requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldSupportedModelScopes: %w", err)
}
return oldValue.SupportedModelScopes, nil
}
// AppendSupportedModelScopes adds s to the "supported_model_scopes" field.
func (m *GroupMutation) AppendSupportedModelScopes(s []string) {
m.appendsupported_model_scopes = append(m.appendsupported_model_scopes, s...)
}
// AppendedSupportedModelScopes returns the list of values that were appended to the "supported_model_scopes" field in this mutation.
func (m *GroupMutation) AppendedSupportedModelScopes() ([]string, bool) {
if len(m.appendsupported_model_scopes) == 0 {
return nil, false
}
return m.appendsupported_model_scopes, true
}
// ResetSupportedModelScopes resets all changes to the "supported_model_scopes" field.
func (m *GroupMutation) ResetSupportedModelScopes() {
m.supported_model_scopes = nil
m.appendsupported_model_scopes = nil
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by ids.
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by ids.
func (m *GroupMutation) AddAPIKeyIDs(ids ...int64) {
func (m *GroupMutation) AddAPIKeyIDs(ids ...int64) {
if m.api_keys == nil {
if m.api_keys == nil {
...
@@ -7339,7 +7501,7 @@ func (m *GroupMutation) Type() string {
...
@@ -7339,7 +7501,7 @@ func (m *GroupMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
// AddedFields().
func (m *GroupMutation) Fields() []string {
func (m *GroupMutation) Fields() []string {
fields := make([]string, 0, 2
1
)
fields := make([]string, 0, 2
4
)
if m.created_at != nil {
if m.created_at != nil {
fields = append(fields, group.FieldCreatedAt)
fields = append(fields, group.FieldCreatedAt)
}
}
...
@@ -7397,12 +7559,21 @@ func (m *GroupMutation) Fields() []string {
...
@@ -7397,12 +7559,21 @@ func (m *GroupMutation) Fields() []string {
if m.fallback_group_id != nil {
if m.fallback_group_id != nil {
fields = append(fields, group.FieldFallbackGroupID)
fields = append(fields, group.FieldFallbackGroupID)
}
}
if m.fallback_group_id_on_invalid_request != nil {
fields = append(fields, group.FieldFallbackGroupIDOnInvalidRequest)
}
if m.model_routing != nil {
if m.model_routing != nil {
fields = append(fields, group.FieldModelRouting)
fields = append(fields, group.FieldModelRouting)
}
}
if m.model_routing_enabled != nil {
if m.model_routing_enabled != nil {
fields = append(fields, group.FieldModelRoutingEnabled)
fields = append(fields, group.FieldModelRoutingEnabled)
}
}
if m.mcp_xml_inject != nil {
fields = append(fields, group.FieldMcpXMLInject)
}
if m.supported_model_scopes != nil {
fields = append(fields, group.FieldSupportedModelScopes)
}
return fields
return fields
}
}
...
@@ -7449,10 +7620,16 @@ func (m *GroupMutation) Field(name string) (ent.Value, bool) {
...
@@ -7449,10 +7620,16 @@ func (m *GroupMutation) Field(name string) (ent.Value, bool) {
return m.ClaudeCodeOnly()
return m.ClaudeCodeOnly()
case group.FieldFallbackGroupID:
case group.FieldFallbackGroupID:
return m.FallbackGroupID()
return m.FallbackGroupID()
case group.FieldFallbackGroupIDOnInvalidRequest:
return m.FallbackGroupIDOnInvalidRequest()
case group.FieldModelRouting:
case group.FieldModelRouting:
return m.ModelRouting()
return m.ModelRouting()
case group.FieldModelRoutingEnabled:
case group.FieldModelRoutingEnabled:
return m.ModelRoutingEnabled()
return m.ModelRoutingEnabled()
case group.FieldMcpXMLInject:
return m.McpXMLInject()
case group.FieldSupportedModelScopes:
return m.SupportedModelScopes()
}
}
return nil, false
return nil, false
}
}
...
@@ -7500,10 +7677,16 @@ func (m *GroupMutation) OldField(ctx context.Context, name string) (ent.Value, e
...
@@ -7500,10 +7677,16 @@ func (m *GroupMutation) OldField(ctx context.Context, name string) (ent.Value, e
return m.OldClaudeCodeOnly(ctx)
return m.OldClaudeCodeOnly(ctx)
case group.FieldFallbackGroupID:
case group.FieldFallbackGroupID:
return m.OldFallbackGroupID(ctx)
return m.OldFallbackGroupID(ctx)
case group.FieldFallbackGroupIDOnInvalidRequest:
return m.OldFallbackGroupIDOnInvalidRequest(ctx)
case group.FieldModelRouting:
case group.FieldModelRouting:
return m.OldModelRouting(ctx)
return m.OldModelRouting(ctx)
case group.FieldModelRoutingEnabled:
case group.FieldModelRoutingEnabled:
return m.OldModelRoutingEnabled(ctx)
return m.OldModelRoutingEnabled(ctx)
case group.FieldMcpXMLInject:
return m.OldMcpXMLInject(ctx)
case group.FieldSupportedModelScopes:
return m.OldSupportedModelScopes(ctx)
}
}
return nil, fmt.Errorf("unknown Group field %s", name)
return nil, fmt.Errorf("unknown Group field %s", name)
}
}
...
@@ -7646,6 +7829,13 @@ func (m *GroupMutation) SetField(name string, value ent.Value) error {
...
@@ -7646,6 +7829,13 @@ func (m *GroupMutation) SetField(name string, value ent.Value) error {
}
}
m.SetFallbackGroupID(v)
m.SetFallbackGroupID(v)
return nil
return nil
case group.FieldFallbackGroupIDOnInvalidRequest:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetFallbackGroupIDOnInvalidRequest(v)
return nil
case group.FieldModelRouting:
case group.FieldModelRouting:
v, ok := value.(map[string][]int64)
v, ok := value.(map[string][]int64)
if !ok {
if !ok {
...
@@ -7660,6 +7850,20 @@ func (m *GroupMutation) SetField(name string, value ent.Value) error {
...
@@ -7660,6 +7850,20 @@ func (m *GroupMutation) SetField(name string, value ent.Value) error {
}
}
m.SetModelRoutingEnabled(v)
m.SetModelRoutingEnabled(v)
return nil
return nil
case group.FieldMcpXMLInject:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetMcpXMLInject(v)
return nil
case group.FieldSupportedModelScopes:
v, ok := value.([]string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetSupportedModelScopes(v)
return nil
}
}
return fmt.Errorf("unknown Group field %s", name)
return fmt.Errorf("unknown Group field %s", name)
}
}
...
@@ -7695,6 +7899,9 @@ func (m *GroupMutation) AddedFields() []string {
...
@@ -7695,6 +7899,9 @@ func (m *GroupMutation) AddedFields() []string {
if m.addfallback_group_id != nil {
if m.addfallback_group_id != nil {
fields = append(fields, group.FieldFallbackGroupID)
fields = append(fields, group.FieldFallbackGroupID)
}
}
if m.addfallback_group_id_on_invalid_request != nil {
fields = append(fields, group.FieldFallbackGroupIDOnInvalidRequest)
}
return fields
return fields
}
}
...
@@ -7721,6 +7928,8 @@ func (m *GroupMutation) AddedField(name string) (ent.Value, bool) {
...
@@ -7721,6 +7928,8 @@ func (m *GroupMutation) AddedField(name string) (ent.Value, bool) {
return m.AddedImagePrice4k()
return m.AddedImagePrice4k()
case group.FieldFallbackGroupID:
case group.FieldFallbackGroupID:
return m.AddedFallbackGroupID()
return m.AddedFallbackGroupID()
case group.FieldFallbackGroupIDOnInvalidRequest:
return m.AddedFallbackGroupIDOnInvalidRequest()
}
}
return nil, false
return nil, false
}
}
...
@@ -7793,6 +8002,13 @@ func (m *GroupMutation) AddField(name string, value ent.Value) error {
...
@@ -7793,6 +8002,13 @@ func (m *GroupMutation) AddField(name string, value ent.Value) error {
}
}
m.AddFallbackGroupID(v)
m.AddFallbackGroupID(v)
return nil
return nil
case group.FieldFallbackGroupIDOnInvalidRequest:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddFallbackGroupIDOnInvalidRequest(v)
return nil
}
}
return fmt.Errorf("unknown Group numeric field %s", name)
return fmt.Errorf("unknown Group numeric field %s", name)
}
}
...
@@ -7828,6 +8044,9 @@ func (m *GroupMutation) ClearedFields() []string {
...
@@ -7828,6 +8044,9 @@ func (m *GroupMutation) ClearedFields() []string {
if m.FieldCleared(group.FieldFallbackGroupID) {
if m.FieldCleared(group.FieldFallbackGroupID) {
fields = append(fields, group.FieldFallbackGroupID)
fields = append(fields, group.FieldFallbackGroupID)
}
}
if m.FieldCleared(group.FieldFallbackGroupIDOnInvalidRequest) {
fields = append(fields, group.FieldFallbackGroupIDOnInvalidRequest)
}
if m.FieldCleared(group.FieldModelRouting) {
if m.FieldCleared(group.FieldModelRouting) {
fields = append(fields, group.FieldModelRouting)
fields = append(fields, group.FieldModelRouting)
}
}
...
@@ -7872,6 +8091,9 @@ func (m *GroupMutation) ClearField(name string) error {
...
@@ -7872,6 +8091,9 @@ func (m *GroupMutation) ClearField(name string) error {
case group.FieldFallbackGroupID:
case group.FieldFallbackGroupID:
m.ClearFallbackGroupID()
m.ClearFallbackGroupID()
return nil
return nil
case group.FieldFallbackGroupIDOnInvalidRequest:
m.ClearFallbackGroupIDOnInvalidRequest()
return nil
case group.FieldModelRouting:
case group.FieldModelRouting:
m.ClearModelRouting()
m.ClearModelRouting()
return nil
return nil
...
@@ -7940,12 +8162,21 @@ func (m *GroupMutation) ResetField(name string) error {
...
@@ -7940,12 +8162,21 @@ func (m *GroupMutation) ResetField(name string) error {
case group.FieldFallbackGroupID:
case group.FieldFallbackGroupID:
m.ResetFallbackGroupID()
m.ResetFallbackGroupID()
return nil
return nil
case group.FieldFallbackGroupIDOnInvalidRequest:
m.ResetFallbackGroupIDOnInvalidRequest()
return nil
case group.FieldModelRouting:
case group.FieldModelRouting:
m.ResetModelRouting()
m.ResetModelRouting()
return nil
return nil
case group.FieldModelRoutingEnabled:
case group.FieldModelRoutingEnabled:
m.ResetModelRoutingEnabled()
m.ResetModelRoutingEnabled()
return nil
return nil
case group.FieldMcpXMLInject:
m.ResetMcpXMLInject()
return nil
case group.FieldSupportedModelScopes:
m.ResetSupportedModelScopes()
return nil
}
}
return fmt.Errorf("unknown Group field %s", name)
return fmt.Errorf("unknown Group field %s", name)
}
}
...
...
backend/ent/runtime/runtime.go
View file @
ff8b1b4a
...
@@ -342,9 +342,17 @@ func init() {
...
@@ -342,9 +342,17 @@ func init() {
// group.DefaultClaudeCodeOnly holds the default value on creation for the claude_code_only field.
// group.DefaultClaudeCodeOnly holds the default value on creation for the claude_code_only field.
group
.
DefaultClaudeCodeOnly
=
groupDescClaudeCodeOnly
.
Default
.
(
bool
)
group
.
DefaultClaudeCodeOnly
=
groupDescClaudeCodeOnly
.
Default
.
(
bool
)
// groupDescModelRoutingEnabled is the schema descriptor for model_routing_enabled field.
// groupDescModelRoutingEnabled is the schema descriptor for model_routing_enabled field.
groupDescModelRoutingEnabled
:=
groupFields
[
1
7
]
.
Descriptor
()
groupDescModelRoutingEnabled
:=
groupFields
[
1
8
]
.
Descriptor
()
// group.DefaultModelRoutingEnabled holds the default value on creation for the model_routing_enabled field.
// group.DefaultModelRoutingEnabled holds the default value on creation for the model_routing_enabled field.
group
.
DefaultModelRoutingEnabled
=
groupDescModelRoutingEnabled
.
Default
.
(
bool
)
group
.
DefaultModelRoutingEnabled
=
groupDescModelRoutingEnabled
.
Default
.
(
bool
)
// groupDescMcpXMLInject is the schema descriptor for mcp_xml_inject field.
groupDescMcpXMLInject
:=
groupFields
[
19
]
.
Descriptor
()
// group.DefaultMcpXMLInject holds the default value on creation for the mcp_xml_inject field.
group
.
DefaultMcpXMLInject
=
groupDescMcpXMLInject
.
Default
.
(
bool
)
// groupDescSupportedModelScopes is the schema descriptor for supported_model_scopes field.
groupDescSupportedModelScopes
:=
groupFields
[
20
]
.
Descriptor
()
// group.DefaultSupportedModelScopes holds the default value on creation for the supported_model_scopes field.
group
.
DefaultSupportedModelScopes
=
groupDescSupportedModelScopes
.
Default
.
([]
string
)
promocodeFields
:=
schema
.
PromoCode
{}
.
Fields
()
promocodeFields
:=
schema
.
PromoCode
{}
.
Fields
()
_
=
promocodeFields
_
=
promocodeFields
// promocodeDescCode is the schema descriptor for code field.
// promocodeDescCode is the schema descriptor for code field.
...
...
backend/ent/schema/group.go
View file @
ff8b1b4a
...
@@ -95,6 +95,10 @@ func (Group) Fields() []ent.Field {
...
@@ -95,6 +95,10 @@ func (Group) Fields() []ent.Field {
Optional
()
.
Optional
()
.
Nillable
()
.
Nillable
()
.
Comment
(
"非 Claude Code 请求降级使用的分组 ID"
),
Comment
(
"非 Claude Code 请求降级使用的分组 ID"
),
field
.
Int64
(
"fallback_group_id_on_invalid_request"
)
.
Optional
()
.
Nillable
()
.
Comment
(
"无效请求兜底使用的分组 ID"
),
// 模型路由配置 (added by migration 040)
// 模型路由配置 (added by migration 040)
field
.
JSON
(
"model_routing"
,
map
[
string
][]
int64
{})
.
field
.
JSON
(
"model_routing"
,
map
[
string
][]
int64
{})
.
...
@@ -106,6 +110,17 @@ func (Group) Fields() []ent.Field {
...
@@ -106,6 +110,17 @@ func (Group) Fields() []ent.Field {
field
.
Bool
(
"model_routing_enabled"
)
.
field
.
Bool
(
"model_routing_enabled"
)
.
Default
(
false
)
.
Default
(
false
)
.
Comment
(
"是否启用模型路由配置"
),
Comment
(
"是否启用模型路由配置"
),
// MCP XML 协议注入开关 (added by migration 042)
field
.
Bool
(
"mcp_xml_inject"
)
.
Default
(
true
)
.
Comment
(
"是否注入 MCP XML 调用协议提示词(仅 antigravity 平台)"
),
// 支持的模型系列 (added by migration 046)
field
.
JSON
(
"supported_model_scopes"
,
[]
string
{})
.
Default
([]
string
{
"claude"
,
"gemini_text"
,
"gemini_image"
})
.
SchemaType
(
map
[
string
]
string
{
dialect
.
Postgres
:
"jsonb"
})
.
Comment
(
"支持的模型系列:claude, gemini_text, gemini_image"
),
}
}
}
}
...
...
backend/go.mod
View file @
ff8b1b4a
...
@@ -4,6 +4,8 @@ go 1.25.6
...
@@ -4,6 +4,8 @@ go 1.25.6
require (
require (
entgo.io/ent v0.14.5
entgo.io/ent v0.14.5
github.com/DATA-DOG/go-sqlmock v1.5.2
github.com/dgraph-io/ristretto v0.2.0
github.com/gin-gonic/gin v1.9.1
github.com/gin-gonic/gin v1.9.1
github.com/golang-jwt/jwt/v5 v5.2.2
github.com/golang-jwt/jwt/v5 v5.2.2
github.com/google/uuid v1.6.0
github.com/google/uuid v1.6.0
...
@@ -11,7 +13,10 @@ require (
...
@@ -11,7 +13,10 @@ require (
github.com/gorilla/websocket v1.5.3
github.com/gorilla/websocket v1.5.3
github.com/imroc/req/v3 v3.57.0
github.com/imroc/req/v3 v3.57.0
github.com/lib/pq v1.10.9
github.com/lib/pq v1.10.9
github.com/pquerna/otp v1.5.0
github.com/redis/go-redis/v9 v9.17.2
github.com/redis/go-redis/v9 v9.17.2
github.com/refraction-networking/utls v1.8.1
github.com/robfig/cron/v3 v3.0.1
github.com/shirou/gopsutil/v4 v4.25.6
github.com/shirou/gopsutil/v4 v4.25.6
github.com/spf13/viper v1.18.2
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.11.1
github.com/stretchr/testify v1.11.1
...
@@ -25,13 +30,13 @@ require (
...
@@ -25,13 +30,13 @@ require (
golang.org/x/sync v0.19.0
golang.org/x/sync v0.19.0
golang.org/x/term v0.38.0
golang.org/x/term v0.38.0
gopkg.in/yaml.v3 v3.0.1
gopkg.in/yaml.v3 v3.0.1
modernc.org/sqlite v1.44.3
)
)
require (
require (
ariga.io/atlas v0.32.1-0.20250325101103-175b25e1c1b9 // indirect
ariga.io/atlas v0.32.1-0.20250325101103-175b25e1c1b9 // indirect
dario.cat/mergo v1.0.2 // indirect
dario.cat/mergo v1.0.2 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/DATA-DOG/go-sqlmock v1.5.2 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/andybalholm/brotli v1.2.0 // indirect
github.com/andybalholm/brotli v1.2.0 // indirect
...
@@ -48,7 +53,6 @@ require (
...
@@ -48,7 +53,6 @@ require (
github.com/containerd/platforms v0.2.1 // indirect
github.com/containerd/platforms v0.2.1 // indirect
github.com/cpuguy83/dockercfg v0.3.2 // indirect
github.com/cpuguy83/dockercfg v0.3.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dgraph-io/ristretto v0.2.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/docker v28.5.1+incompatible // indirect
github.com/docker/docker v28.5.1+incompatible // indirect
...
@@ -107,13 +111,10 @@ require (
...
@@ -107,13 +111,10 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/pquerna/otp v1.5.0 // indirect
github.com/quic-go/qpack v0.6.0 // indirect
github.com/quic-go/qpack v0.6.0 // indirect
github.com/quic-go/quic-go v0.57.1 // indirect
github.com/quic-go/quic-go v0.57.1 // indirect
github.com/refraction-networking/utls v1.8.1 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
...
@@ -149,12 +150,10 @@ require (
...
@@ -149,12 +150,10 @@ require (
golang.org/x/sys v0.39.0 // indirect
golang.org/x/sys v0.39.0 // indirect
golang.org/x/text v0.32.0 // indirect
golang.org/x/text v0.32.0 // indirect
golang.org/x/tools v0.39.0 // indirect
golang.org/x/tools v0.39.0 // indirect
golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated // indirect
google.golang.org/grpc v1.75.1 // indirect
google.golang.org/grpc v1.75.1 // indirect
google.golang.org/protobuf v1.36.10 // indirect
google.golang.org/protobuf v1.36.10 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
modernc.org/libc v1.67.6 // indirect
modernc.org/libc v1.67.6 // indirect
modernc.org/mathutil v1.7.1 // indirect
modernc.org/mathutil v1.7.1 // indirect
modernc.org/memory v1.11.0 // indirect
modernc.org/memory v1.11.0 // indirect
modernc.org/sqlite v1.44.1 // indirect
)
)
backend/go.sum
View file @
ff8b1b4a
...
@@ -55,6 +55,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
...
@@ -55,6 +55,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgraph-io/ristretto v0.2.0 h1:XAfl+7cmoUDWW/2Lx8TGZQjjxIQ2Ley9DSf52dru4WE=
github.com/dgraph-io/ristretto v0.2.0 h1:XAfl+7cmoUDWW/2Lx8TGZQjjxIQ2Ley9DSf52dru4WE=
github.com/dgraph-io/ristretto v0.2.0/go.mod h1:8uBHCU/PBV4Ag0CJrP47b9Ofby5dqWNh4FicAdoqFNU=
github.com/dgraph-io/ristretto v0.2.0/go.mod h1:8uBHCU/PBV4Ag0CJrP47b9Ofby5dqWNh4FicAdoqFNU=
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y=
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
...
@@ -113,6 +115,8 @@ github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX
...
@@ -113,6 +115,8 @@ github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
github.com/google/subcommands v1.2.0 h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN9oE=
github.com/google/subcommands v1.2.0 h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN9oE=
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
...
@@ -123,6 +127,9 @@ github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aN
...
@@ -123,6 +127,9 @@ github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aN
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 h1:NmZ1PKzSTQbuGHw9DGPFomqkkLWMC+vZCkfs+FHv1Vg=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 h1:NmZ1PKzSTQbuGHw9DGPFomqkkLWMC+vZCkfs+FHv1Vg=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3/go.mod h1:zQrxl1YP88HQlA6i9c63DSVPFklWpGX4OWAc9bFuaH4=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3/go.mod h1:zQrxl1YP88HQlA6i9c63DSVPFklWpGX4OWAc9bFuaH4=
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hashicorp/hcl/v2 v2.18.1 h1:6nxnOJFku1EuSawSD81fuviYUV8DxFr3fp2dUi3ZYSo=
github.com/hashicorp/hcl/v2 v2.18.1 h1:6nxnOJFku1EuSawSD81fuviYUV8DxFr3fp2dUi3ZYSo=
...
@@ -345,8 +352,6 @@ golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
...
@@ -345,8 +352,6 @@ golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU=
golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU=
golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0=
golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 h1:mgKeJMpvi0yx/sU5GsxQ7p6s2wtOnGAHZWCHUM4KGzY=
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 h1:mgKeJMpvi0yx/sU5GsxQ7p6s2wtOnGAHZWCHUM4KGzY=
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70=
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70=
golang.org/x/mod v0.30.0 h1:fDEXFVZ/fmCKProc/yAXXUijritrDzahmwwefnjoPFk=
golang.org/x/mod v0.30.0 h1:fDEXFVZ/fmCKProc/yAXXUijritrDzahmwwefnjoPFk=
...
@@ -374,9 +379,8 @@ golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
...
@@ -374,9 +379,8 @@ golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
golang.org/x/tools v0.39.0 h1:ik4ho21kwuQln40uelmciQPp9SipgNDdrafrYA4TmQQ=
golang.org/x/tools v0.39.0 h1:ik4ho21kwuQln40uelmciQPp9SipgNDdrafrYA4TmQQ=
golang.org/x/tools v0.39.0/go.mod h1:JnefbkDPyD8UU2kI5fuf8ZX4/yUeh9W877ZeBONxUqQ=
golang.org/x/tools v0.39.0/go.mod h1:JnefbkDPyD8UU2kI5fuf8ZX4/yUeh9W877ZeBONxUqQ=
golang.org/x/tools/go/expect v0.1.0-deprecated h1:jY2C5HGYR5lqex3gEniOQL0r7Dq5+VGVgY1nudX5lXY=
golang.org/x/tools/go/expect v0.1.0-deprecated/go.mod h1:eihoPOH+FgIqa3FpoTwguz/bVUSGBlGQU67vpBeOrBY=
golang.org/x/tools/go/expect v0.1.1-deprecated h1:jpBZDwmgPhXsKZC6WhL20P4b/wmnpsEAGHaNy0n/rJM=
golang.org/x/tools/go/expect v0.1.1-deprecated h1:jpBZDwmgPhXsKZC6WhL20P4b/wmnpsEAGHaNy0n/rJM=
golang.org/x/tools/go/expect v0.1.1-deprecated/go.mod h1:eihoPOH+FgIqa3FpoTwguz/bVUSGBlGQU67vpBeOrBY=
golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated h1:1h2MnaIAIXISqTFKdENegdpAgUXz6NrPEsbIeWaBRvM=
golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated h1:1h2MnaIAIXISqTFKdENegdpAgUXz6NrPEsbIeWaBRvM=
golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated/go.mod h1:RVAQXBGNv1ib0J382/DPCRS/BPnsGebyM1Gj5VSDpG8=
golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated/go.mod h1:RVAQXBGNv1ib0J382/DPCRS/BPnsGebyM1Gj5VSDpG8=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
...
@@ -399,12 +403,32 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
...
@@ -399,12 +403,32 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
modernc.org/cc/v4 v4.27.1 h1:9W30zRlYrefrDV2JE2O8VDtJ1yPGownxciz5rrbQZis=
modernc.org/cc/v4 v4.27.1/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0=
modernc.org/ccgo/v4 v4.30.1 h1:4r4U1J6Fhj98NKfSjnPUN7Ze2c6MnAdL0hWw6+LrJpc=
modernc.org/ccgo/v4 v4.30.1/go.mod h1:bIOeI1JL54Utlxn+LwrFyjCx2n2RDiYEaJVSrgdrRfM=
modernc.org/fileutil v1.3.40 h1:ZGMswMNc9JOCrcrakF1HrvmergNLAmxOPjizirpfqBA=
modernc.org/fileutil v1.3.40/go.mod h1:HxmghZSZVAz/LXcMNwZPA/DRrQZEVP9VX0V4LQGQFOc=
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
modernc.org/gc/v3 v3.1.1 h1:k8T3gkXWY9sEiytKhcgyiZ2L0DTyCQ/nvX+LoCljoRE=
modernc.org/gc/v3 v3.1.1/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY=
modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks=
modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI=
modernc.org/libc v1.67.6 h1:eVOQvpModVLKOdT+LvBPjdQqfrZq+pC39BygcT+E7OI=
modernc.org/libc v1.67.6 h1:eVOQvpModVLKOdT+LvBPjdQqfrZq+pC39BygcT+E7OI=
modernc.org/libc v1.67.6/go.mod h1:JAhxUVlolfYDErnwiqaLvUqc8nfb2r6S6slAgZOnaiE=
modernc.org/libc v1.67.6/go.mod h1:JAhxUVlolfYDErnwiqaLvUqc8nfb2r6S6slAgZOnaiE=
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
modernc.org/sqlite v1.44.1 h1:qybx/rNpfQipX/t47OxbHmkkJuv2JWifCMH8SVUiDas=
modernc.org/opt v0.1.4 h1:2kNGMRiUjrp4LcaPuLY2PzUfqM/w9N23quVwhKt5Qm8=
modernc.org/sqlite v1.44.1/go.mod h1:CzbrU2lSB1DKUusvwGz7rqEKIq+NUd8GWuBBZDs9/nA=
modernc.org/opt v0.1.4/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
modernc.org/sqlite v1.44.3 h1:+39JvV/HWMcYslAwRxHb8067w+2zowvFOUrOWIy9PjY=
modernc.org/sqlite v1.44.3/go.mod h1:CzbrU2lSB1DKUusvwGz7rqEKIq+NUd8GWuBBZDs9/nA=
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
backend/internal/domain/constants.go
View file @
ff8b1b4a
...
@@ -29,6 +29,7 @@ const (
...
@@ -29,6 +29,7 @@ const (
AccountTypeOAuth
=
"oauth"
// OAuth类型账号(full scope: profile + inference)
AccountTypeOAuth
=
"oauth"
// OAuth类型账号(full scope: profile + inference)
AccountTypeSetupToken
=
"setup-token"
// Setup Token类型账号(inference only scope)
AccountTypeSetupToken
=
"setup-token"
// Setup Token类型账号(inference only scope)
AccountTypeAPIKey
=
"apikey"
// API Key类型账号
AccountTypeAPIKey
=
"apikey"
// API Key类型账号
AccountTypeUpstream
=
"upstream"
// 上游透传类型账号(通过 Base URL + API Key 连接上游)
)
)
// Redeem type constants
// Redeem type constants
...
...
backend/internal/handler/admin/account_handler.go
View file @
ff8b1b4a
...
@@ -84,7 +84,7 @@ type CreateAccountRequest struct {
...
@@ -84,7 +84,7 @@ type CreateAccountRequest struct {
Name
string
`json:"name" binding:"required"`
Name
string
`json:"name" binding:"required"`
Notes
*
string
`json:"notes"`
Notes
*
string
`json:"notes"`
Platform
string
`json:"platform" binding:"required"`
Platform
string
`json:"platform" binding:"required"`
Type
string
`json:"type" binding:"required,oneof=oauth setup-token apikey"`
Type
string
`json:"type" binding:"required,oneof=oauth setup-token apikey
upstream
"`
Credentials
map
[
string
]
any
`json:"credentials" binding:"required"`
Credentials
map
[
string
]
any
`json:"credentials" binding:"required"`
Extra
map
[
string
]
any
`json:"extra"`
Extra
map
[
string
]
any
`json:"extra"`
ProxyID
*
int64
`json:"proxy_id"`
ProxyID
*
int64
`json:"proxy_id"`
...
@@ -102,7 +102,7 @@ type CreateAccountRequest struct {
...
@@ -102,7 +102,7 @@ type CreateAccountRequest struct {
type
UpdateAccountRequest
struct
{
type
UpdateAccountRequest
struct
{
Name
string
`json:"name"`
Name
string
`json:"name"`
Notes
*
string
`json:"notes"`
Notes
*
string
`json:"notes"`
Type
string
`json:"type" binding:"omitempty,oneof=oauth setup-token apikey"`
Type
string
`json:"type" binding:"omitempty,oneof=oauth setup-token apikey
upstream
"`
Credentials
map
[
string
]
any
`json:"credentials"`
Credentials
map
[
string
]
any
`json:"credentials"`
Extra
map
[
string
]
any
`json:"extra"`
Extra
map
[
string
]
any
`json:"extra"`
ProxyID
*
int64
`json:"proxy_id"`
ProxyID
*
int64
`json:"proxy_id"`
...
...
backend/internal/handler/admin/group_handler.go
View file @
ff8b1b4a
...
@@ -35,14 +35,18 @@ type CreateGroupRequest struct {
...
@@ -35,14 +35,18 @@ type CreateGroupRequest struct {
WeeklyLimitUSD
*
float64
`json:"weekly_limit_usd"`
WeeklyLimitUSD
*
float64
`json:"weekly_limit_usd"`
MonthlyLimitUSD
*
float64
`json:"monthly_limit_usd"`
MonthlyLimitUSD
*
float64
`json:"monthly_limit_usd"`
// 图片生成计费配置(antigravity 和 gemini 平台使用,负数表示清除配置)
// 图片生成计费配置(antigravity 和 gemini 平台使用,负数表示清除配置)
ImagePrice1K
*
float64
`json:"image_price_1k"`
ImagePrice1K
*
float64
`json:"image_price_1k"`
ImagePrice2K
*
float64
`json:"image_price_2k"`
ImagePrice2K
*
float64
`json:"image_price_2k"`
ImagePrice4K
*
float64
`json:"image_price_4k"`
ImagePrice4K
*
float64
`json:"image_price_4k"`
ClaudeCodeOnly
bool
`json:"claude_code_only"`
ClaudeCodeOnly
bool
`json:"claude_code_only"`
FallbackGroupID
*
int64
`json:"fallback_group_id"`
FallbackGroupID
*
int64
`json:"fallback_group_id"`
FallbackGroupIDOnInvalidRequest
*
int64
`json:"fallback_group_id_on_invalid_request"`
// 模型路由配置(仅 anthropic 平台使用)
// 模型路由配置(仅 anthropic 平台使用)
ModelRouting
map
[
string
][]
int64
`json:"model_routing"`
ModelRouting
map
[
string
][]
int64
`json:"model_routing"`
ModelRoutingEnabled
bool
`json:"model_routing_enabled"`
ModelRoutingEnabled
bool
`json:"model_routing_enabled"`
MCPXMLInject
*
bool
`json:"mcp_xml_inject"`
// 支持的模型系列(仅 antigravity 平台使用)
SupportedModelScopes
[]
string
`json:"supported_model_scopes"`
// 从指定分组复制账号(创建后自动绑定)
// 从指定分组复制账号(创建后自动绑定)
CopyAccountsFromGroupIDs
[]
int64
`json:"copy_accounts_from_group_ids"`
CopyAccountsFromGroupIDs
[]
int64
`json:"copy_accounts_from_group_ids"`
}
}
...
@@ -60,14 +64,18 @@ type UpdateGroupRequest struct {
...
@@ -60,14 +64,18 @@ type UpdateGroupRequest struct {
WeeklyLimitUSD
*
float64
`json:"weekly_limit_usd"`
WeeklyLimitUSD
*
float64
`json:"weekly_limit_usd"`
MonthlyLimitUSD
*
float64
`json:"monthly_limit_usd"`
MonthlyLimitUSD
*
float64
`json:"monthly_limit_usd"`
// 图片生成计费配置(antigravity 和 gemini 平台使用,负数表示清除配置)
// 图片生成计费配置(antigravity 和 gemini 平台使用,负数表示清除配置)
ImagePrice1K
*
float64
`json:"image_price_1k"`
ImagePrice1K
*
float64
`json:"image_price_1k"`
ImagePrice2K
*
float64
`json:"image_price_2k"`
ImagePrice2K
*
float64
`json:"image_price_2k"`
ImagePrice4K
*
float64
`json:"image_price_4k"`
ImagePrice4K
*
float64
`json:"image_price_4k"`
ClaudeCodeOnly
*
bool
`json:"claude_code_only"`
ClaudeCodeOnly
*
bool
`json:"claude_code_only"`
FallbackGroupID
*
int64
`json:"fallback_group_id"`
FallbackGroupID
*
int64
`json:"fallback_group_id"`
FallbackGroupIDOnInvalidRequest
*
int64
`json:"fallback_group_id_on_invalid_request"`
// 模型路由配置(仅 anthropic 平台使用)
// 模型路由配置(仅 anthropic 平台使用)
ModelRouting
map
[
string
][]
int64
`json:"model_routing"`
ModelRouting
map
[
string
][]
int64
`json:"model_routing"`
ModelRoutingEnabled
*
bool
`json:"model_routing_enabled"`
ModelRoutingEnabled
*
bool
`json:"model_routing_enabled"`
MCPXMLInject
*
bool
`json:"mcp_xml_inject"`
// 支持的模型系列(仅 antigravity 平台使用)
SupportedModelScopes
*
[]
string
`json:"supported_model_scopes"`
// 从指定分组复制账号(同步操作:先清空当前分组的账号绑定,再绑定源分组的账号)
// 从指定分组复制账号(同步操作:先清空当前分组的账号绑定,再绑定源分组的账号)
CopyAccountsFromGroupIDs
[]
int64
`json:"copy_accounts_from_group_ids"`
CopyAccountsFromGroupIDs
[]
int64
`json:"copy_accounts_from_group_ids"`
}
}
...
@@ -159,23 +167,26 @@ func (h *GroupHandler) Create(c *gin.Context) {
...
@@ -159,23 +167,26 @@ func (h *GroupHandler) Create(c *gin.Context) {
}
}
group
,
err
:=
h
.
adminService
.
CreateGroup
(
c
.
Request
.
Context
(),
&
service
.
CreateGroupInput
{
group
,
err
:=
h
.
adminService
.
CreateGroup
(
c
.
Request
.
Context
(),
&
service
.
CreateGroupInput
{
Name
:
req
.
Name
,
Name
:
req
.
Name
,
Description
:
req
.
Description
,
Description
:
req
.
Description
,
Platform
:
req
.
Platform
,
Platform
:
req
.
Platform
,
RateMultiplier
:
req
.
RateMultiplier
,
RateMultiplier
:
req
.
RateMultiplier
,
IsExclusive
:
req
.
IsExclusive
,
IsExclusive
:
req
.
IsExclusive
,
SubscriptionType
:
req
.
SubscriptionType
,
SubscriptionType
:
req
.
SubscriptionType
,
DailyLimitUSD
:
req
.
DailyLimitUSD
,
DailyLimitUSD
:
req
.
DailyLimitUSD
,
WeeklyLimitUSD
:
req
.
WeeklyLimitUSD
,
WeeklyLimitUSD
:
req
.
WeeklyLimitUSD
,
MonthlyLimitUSD
:
req
.
MonthlyLimitUSD
,
MonthlyLimitUSD
:
req
.
MonthlyLimitUSD
,
ImagePrice1K
:
req
.
ImagePrice1K
,
ImagePrice1K
:
req
.
ImagePrice1K
,
ImagePrice2K
:
req
.
ImagePrice2K
,
ImagePrice2K
:
req
.
ImagePrice2K
,
ImagePrice4K
:
req
.
ImagePrice4K
,
ImagePrice4K
:
req
.
ImagePrice4K
,
ClaudeCodeOnly
:
req
.
ClaudeCodeOnly
,
ClaudeCodeOnly
:
req
.
ClaudeCodeOnly
,
FallbackGroupID
:
req
.
FallbackGroupID
,
FallbackGroupID
:
req
.
FallbackGroupID
,
ModelRouting
:
req
.
ModelRouting
,
FallbackGroupIDOnInvalidRequest
:
req
.
FallbackGroupIDOnInvalidRequest
,
ModelRoutingEnabled
:
req
.
ModelRoutingEnabled
,
ModelRouting
:
req
.
ModelRouting
,
CopyAccountsFromGroupIDs
:
req
.
CopyAccountsFromGroupIDs
,
ModelRoutingEnabled
:
req
.
ModelRoutingEnabled
,
MCPXMLInject
:
req
.
MCPXMLInject
,
SupportedModelScopes
:
req
.
SupportedModelScopes
,
CopyAccountsFromGroupIDs
:
req
.
CopyAccountsFromGroupIDs
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
response
.
ErrorFrom
(
c
,
err
)
...
@@ -201,24 +212,27 @@ func (h *GroupHandler) Update(c *gin.Context) {
...
@@ -201,24 +212,27 @@ func (h *GroupHandler) Update(c *gin.Context) {
}
}
group
,
err
:=
h
.
adminService
.
UpdateGroup
(
c
.
Request
.
Context
(),
groupID
,
&
service
.
UpdateGroupInput
{
group
,
err
:=
h
.
adminService
.
UpdateGroup
(
c
.
Request
.
Context
(),
groupID
,
&
service
.
UpdateGroupInput
{
Name
:
req
.
Name
,
Name
:
req
.
Name
,
Description
:
req
.
Description
,
Description
:
req
.
Description
,
Platform
:
req
.
Platform
,
Platform
:
req
.
Platform
,
RateMultiplier
:
req
.
RateMultiplier
,
RateMultiplier
:
req
.
RateMultiplier
,
IsExclusive
:
req
.
IsExclusive
,
IsExclusive
:
req
.
IsExclusive
,
Status
:
req
.
Status
,
Status
:
req
.
Status
,
SubscriptionType
:
req
.
SubscriptionType
,
SubscriptionType
:
req
.
SubscriptionType
,
DailyLimitUSD
:
req
.
DailyLimitUSD
,
DailyLimitUSD
:
req
.
DailyLimitUSD
,
WeeklyLimitUSD
:
req
.
WeeklyLimitUSD
,
WeeklyLimitUSD
:
req
.
WeeklyLimitUSD
,
MonthlyLimitUSD
:
req
.
MonthlyLimitUSD
,
MonthlyLimitUSD
:
req
.
MonthlyLimitUSD
,
ImagePrice1K
:
req
.
ImagePrice1K
,
ImagePrice1K
:
req
.
ImagePrice1K
,
ImagePrice2K
:
req
.
ImagePrice2K
,
ImagePrice2K
:
req
.
ImagePrice2K
,
ImagePrice4K
:
req
.
ImagePrice4K
,
ImagePrice4K
:
req
.
ImagePrice4K
,
ClaudeCodeOnly
:
req
.
ClaudeCodeOnly
,
ClaudeCodeOnly
:
req
.
ClaudeCodeOnly
,
FallbackGroupID
:
req
.
FallbackGroupID
,
FallbackGroupID
:
req
.
FallbackGroupID
,
ModelRouting
:
req
.
ModelRouting
,
FallbackGroupIDOnInvalidRequest
:
req
.
FallbackGroupIDOnInvalidRequest
,
ModelRoutingEnabled
:
req
.
ModelRoutingEnabled
,
ModelRouting
:
req
.
ModelRouting
,
CopyAccountsFromGroupIDs
:
req
.
CopyAccountsFromGroupIDs
,
ModelRoutingEnabled
:
req
.
ModelRoutingEnabled
,
MCPXMLInject
:
req
.
MCPXMLInject
,
SupportedModelScopes
:
req
.
SupportedModelScopes
,
CopyAccountsFromGroupIDs
:
req
.
CopyAccountsFromGroupIDs
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
response
.
ErrorFrom
(
c
,
err
)
...
...
backend/internal/handler/dto/mappers.go
View file @
ff8b1b4a
...
@@ -108,10 +108,12 @@ func GroupFromServiceAdmin(g *service.Group) *AdminGroup {
...
@@ -108,10 +108,12 @@ func GroupFromServiceAdmin(g *service.Group) *AdminGroup {
return
nil
return
nil
}
}
out
:=
&
AdminGroup
{
out
:=
&
AdminGroup
{
Group
:
groupFromServiceBase
(
g
),
Group
:
groupFromServiceBase
(
g
),
ModelRouting
:
g
.
ModelRouting
,
ModelRouting
:
g
.
ModelRouting
,
ModelRoutingEnabled
:
g
.
ModelRoutingEnabled
,
ModelRoutingEnabled
:
g
.
ModelRoutingEnabled
,
AccountCount
:
g
.
AccountCount
,
MCPXMLInject
:
g
.
MCPXMLInject
,
SupportedModelScopes
:
g
.
SupportedModelScopes
,
AccountCount
:
g
.
AccountCount
,
}
}
if
len
(
g
.
AccountGroups
)
>
0
{
if
len
(
g
.
AccountGroups
)
>
0
{
out
.
AccountGroups
=
make
([]
AccountGroup
,
0
,
len
(
g
.
AccountGroups
))
out
.
AccountGroups
=
make
([]
AccountGroup
,
0
,
len
(
g
.
AccountGroups
))
...
@@ -141,8 +143,10 @@ func groupFromServiceBase(g *service.Group) Group {
...
@@ -141,8 +143,10 @@ func groupFromServiceBase(g *service.Group) Group {
ImagePrice4K
:
g
.
ImagePrice4K
,
ImagePrice4K
:
g
.
ImagePrice4K
,
ClaudeCodeOnly
:
g
.
ClaudeCodeOnly
,
ClaudeCodeOnly
:
g
.
ClaudeCodeOnly
,
FallbackGroupID
:
g
.
FallbackGroupID
,
FallbackGroupID
:
g
.
FallbackGroupID
,
CreatedAt
:
g
.
CreatedAt
,
// 无效请求兜底分组
UpdatedAt
:
g
.
UpdatedAt
,
FallbackGroupIDOnInvalidRequest
:
g
.
FallbackGroupIDOnInvalidRequest
,
CreatedAt
:
g
.
CreatedAt
,
UpdatedAt
:
g
.
UpdatedAt
,
}
}
}
}
...
...
backend/internal/handler/dto/types.go
View file @
ff8b1b4a
...
@@ -72,6 +72,8 @@ type Group struct {
...
@@ -72,6 +72,8 @@ type Group struct {
// Claude Code 客户端限制
// Claude Code 客户端限制
ClaudeCodeOnly
bool
`json:"claude_code_only"`
ClaudeCodeOnly
bool
`json:"claude_code_only"`
FallbackGroupID
*
int64
`json:"fallback_group_id"`
FallbackGroupID
*
int64
`json:"fallback_group_id"`
// 无效请求兜底分组
FallbackGroupIDOnInvalidRequest
*
int64
`json:"fallback_group_id_on_invalid_request"`
CreatedAt
time
.
Time
`json:"created_at"`
CreatedAt
time
.
Time
`json:"created_at"`
UpdatedAt
time
.
Time
`json:"updated_at"`
UpdatedAt
time
.
Time
`json:"updated_at"`
...
@@ -86,8 +88,13 @@ type AdminGroup struct {
...
@@ -86,8 +88,13 @@ type AdminGroup struct {
ModelRouting
map
[
string
][]
int64
`json:"model_routing"`
ModelRouting
map
[
string
][]
int64
`json:"model_routing"`
ModelRoutingEnabled
bool
`json:"model_routing_enabled"`
ModelRoutingEnabled
bool
`json:"model_routing_enabled"`
AccountGroups
[]
AccountGroup
`json:"account_groups,omitempty"`
// MCP XML 协议注入(仅 antigravity 平台使用)
AccountCount
int64
`json:"account_count,omitempty"`
MCPXMLInject
bool
`json:"mcp_xml_inject"`
// 支持的模型系列(仅 antigravity 平台使用)
SupportedModelScopes
[]
string
`json:"supported_model_scopes"`
AccountGroups
[]
AccountGroup
`json:"account_groups,omitempty"`
AccountCount
int64
`json:"account_count,omitempty"`
}
}
type
Account
struct
{
type
Account
struct
{
...
...
backend/internal/handler/gateway_handler.go
View file @
ff8b1b4a
...
@@ -14,6 +14,7 @@ import (
...
@@ -14,6 +14,7 @@ import (
"github.com/Wei-Shaw/sub2api/internal/config"
"github.com/Wei-Shaw/sub2api/internal/config"
"github.com/Wei-Shaw/sub2api/internal/pkg/antigravity"
"github.com/Wei-Shaw/sub2api/internal/pkg/antigravity"
"github.com/Wei-Shaw/sub2api/internal/pkg/claude"
"github.com/Wei-Shaw/sub2api/internal/pkg/claude"
"github.com/Wei-Shaw/sub2api/internal/pkg/ctxkey"
pkgerrors
"github.com/Wei-Shaw/sub2api/internal/pkg/errors"
pkgerrors
"github.com/Wei-Shaw/sub2api/internal/pkg/errors"
"github.com/Wei-Shaw/sub2api/internal/pkg/ip"
"github.com/Wei-Shaw/sub2api/internal/pkg/ip"
"github.com/Wei-Shaw/sub2api/internal/pkg/openai"
"github.com/Wei-Shaw/sub2api/internal/pkg/openai"
...
@@ -284,10 +285,14 @@ func (h *GatewayHandler) Messages(c *gin.Context) {
...
@@ -284,10 +285,14 @@ func (h *GatewayHandler) Messages(c *gin.Context) {
// 转发请求 - 根据账号平台分流
// 转发请求 - 根据账号平台分流
var
result
*
service
.
ForwardResult
var
result
*
service
.
ForwardResult
requestCtx
:=
c
.
Request
.
Context
()
if
switchCount
>
0
{
requestCtx
=
context
.
WithValue
(
requestCtx
,
ctxkey
.
AccountSwitchCount
,
switchCount
)
}
if
account
.
Platform
==
service
.
PlatformAntigravity
{
if
account
.
Platform
==
service
.
PlatformAntigravity
{
result
,
err
=
h
.
antigravityGatewayService
.
ForwardGemini
(
c
.
R
equest
.
Context
()
,
c
,
account
,
reqModel
,
"generateContent"
,
reqStream
,
body
)
result
,
err
=
h
.
antigravityGatewayService
.
ForwardGemini
(
r
equest
Ctx
,
c
,
account
,
reqModel
,
"generateContent"
,
reqStream
,
body
)
}
else
{
}
else
{
result
,
err
=
h
.
geminiCompatService
.
Forward
(
c
.
R
equest
.
Context
()
,
c
,
account
,
body
)
result
,
err
=
h
.
geminiCompatService
.
Forward
(
r
equest
Ctx
,
c
,
account
,
body
)
}
}
if
accountReleaseFunc
!=
nil
{
if
accountReleaseFunc
!=
nil
{
accountReleaseFunc
()
accountReleaseFunc
()
...
@@ -335,140 +340,193 @@ func (h *GatewayHandler) Messages(c *gin.Context) {
...
@@ -335,140 +340,193 @@ func (h *GatewayHandler) Messages(c *gin.Context) {
}
}
}
}
maxAccountSwitches
:=
h
.
maxAccountSwitches
currentAPIKey
:=
apiKey
switchCount
:=
0
currentSubscription
:=
subscription
failedAccountIDs
:=
make
(
map
[
int64
]
struct
{})
var
fallbackGroupID
*
int64
lastFailoverStatus
:=
0
if
apiKey
.
Group
!=
nil
{
fallbackGroupID
=
apiKey
.
Group
.
FallbackGroupIDOnInvalidRequest
}
fallbackUsed
:=
false
for
{
for
{
// 选择支持该模型的账号
maxAccountSwitches
:=
h
.
maxAccountSwitches
selection
,
err
:=
h
.
gatewayService
.
SelectAccountWithLoadAwareness
(
c
.
Request
.
Context
(),
apiKey
.
GroupID
,
sessionKey
,
reqModel
,
failedAccountIDs
,
parsedReq
.
MetadataUserID
)
switchCount
:=
0
if
err
!=
nil
{
failedAccountIDs
:=
make
(
map
[
int64
]
struct
{})
if
len
(
failedAccountIDs
)
==
0
{
lastFailoverStatus
:=
0
h
.
handleStreamingAwareError
(
c
,
http
.
StatusServiceUnavailable
,
"api_error"
,
"No available accounts: "
+
err
.
Error
(),
streamStarted
)
retryWithFallback
:=
false
return
}
h
.
handleFailoverExhausted
(
c
,
lastFailoverStatus
,
streamStarted
)
return
}
account
:=
selection
.
Account
setOpsSelectedAccount
(
c
,
account
.
ID
)
// 检查请求拦截(预热请求、SUGGESTION MODE等)
if
account
.
IsInterceptWarmupEnabled
()
{
interceptType
:=
detectInterceptType
(
body
)
if
interceptType
!=
InterceptTypeNone
{
if
selection
.
Acquired
&&
selection
.
ReleaseFunc
!=
nil
{
selection
.
ReleaseFunc
()
}
if
reqStream
{
sendMockInterceptStream
(
c
,
reqModel
,
interceptType
)
}
else
{
sendMockInterceptResponse
(
c
,
reqModel
,
interceptType
)
}
return
}
}
// 3. 获取账号并发槽位
for
{
accountReleaseFunc
:=
selection
.
ReleaseFunc
// 选择支持该模型的账号
if
!
selection
.
Acquired
{
selection
,
err
:=
h
.
gatewayService
.
SelectAccountWithLoadAwareness
(
c
.
Request
.
Context
(),
currentAPIKey
.
GroupID
,
sessionKey
,
reqModel
,
failedAccountIDs
,
parsedReq
.
MetadataUserID
)
if
selection
.
WaitPlan
==
nil
{
h
.
handleStreamingAwareError
(
c
,
http
.
StatusServiceUnavailable
,
"api_error"
,
"No available accounts"
,
streamStarted
)
return
}
accountWaitCounted
:=
false
canWait
,
err
:=
h
.
concurrencyHelper
.
IncrementAccountWaitCount
(
c
.
Request
.
Context
(),
account
.
ID
,
selection
.
WaitPlan
.
MaxWaiting
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Printf
(
"Increment account wait count failed: %v"
,
err
)
if
len
(
failedAccountIDs
)
==
0
{
}
else
if
!
canWait
{
h
.
handleStreamingAwareError
(
c
,
http
.
StatusServiceUnavailable
,
"api_error"
,
"No available accounts: "
+
err
.
Error
(),
streamStarted
)
log
.
Printf
(
"Account wait queue full: account=%d"
,
account
.
ID
)
return
h
.
handleStreamingAwareError
(
c
,
http
.
StatusTooManyRequests
,
"rate_limit_error"
,
"Too many pending requests, please retry later"
,
streamStarted
)
}
h
.
handleFailoverExhausted
(
c
,
lastFailoverStatus
,
streamStarted
)
return
return
}
}
if
err
==
nil
&&
canWait
{
account
:=
selection
.
Account
accountWaitCounted
=
true
setOpsSelectedAccount
(
c
,
account
.
ID
)
// 检查请求拦截(预热请求、SUGGESTION MODE等)
if
account
.
IsInterceptWarmupEnabled
()
{
interceptType
:=
detectInterceptType
(
body
)
if
interceptType
!=
InterceptTypeNone
{
if
selection
.
Acquired
&&
selection
.
ReleaseFunc
!=
nil
{
selection
.
ReleaseFunc
()
}
if
reqStream
{
sendMockInterceptStream
(
c
,
reqModel
,
interceptType
)
}
else
{
sendMockInterceptResponse
(
c
,
reqModel
,
interceptType
)
}
return
}
}
}
defer
func
()
{
// 3. 获取账号并发槽位
accountReleaseFunc
:=
selection
.
ReleaseFunc
if
!
selection
.
Acquired
{
if
selection
.
WaitPlan
==
nil
{
h
.
handleStreamingAwareError
(
c
,
http
.
StatusServiceUnavailable
,
"api_error"
,
"No available accounts"
,
streamStarted
)
return
}
accountWaitCounted
:=
false
canWait
,
err
:=
h
.
concurrencyHelper
.
IncrementAccountWaitCount
(
c
.
Request
.
Context
(),
account
.
ID
,
selection
.
WaitPlan
.
MaxWaiting
)
if
err
!=
nil
{
log
.
Printf
(
"Increment account wait count failed: %v"
,
err
)
}
else
if
!
canWait
{
log
.
Printf
(
"Account wait queue full: account=%d"
,
account
.
ID
)
h
.
handleStreamingAwareError
(
c
,
http
.
StatusTooManyRequests
,
"rate_limit_error"
,
"Too many pending requests, please retry later"
,
streamStarted
)
return
}
if
err
==
nil
&&
canWait
{
accountWaitCounted
=
true
}
defer
func
()
{
if
accountWaitCounted
{
h
.
concurrencyHelper
.
DecrementAccountWaitCount
(
c
.
Request
.
Context
(),
account
.
ID
)
}
}()
accountReleaseFunc
,
err
=
h
.
concurrencyHelper
.
AcquireAccountSlotWithWaitTimeout
(
c
,
account
.
ID
,
selection
.
WaitPlan
.
MaxConcurrency
,
selection
.
WaitPlan
.
Timeout
,
reqStream
,
&
streamStarted
,
)
if
err
!=
nil
{
log
.
Printf
(
"Account concurrency acquire failed: %v"
,
err
)
h
.
handleConcurrencyError
(
c
,
err
,
"account"
,
streamStarted
)
return
}
if
accountWaitCounted
{
if
accountWaitCounted
{
h
.
concurrencyHelper
.
DecrementAccountWaitCount
(
c
.
Request
.
Context
(),
account
.
ID
)
h
.
concurrencyHelper
.
DecrementAccountWaitCount
(
c
.
Request
.
Context
(),
account
.
ID
)
accountWaitCounted
=
false
}
}
}()
if
err
:=
h
.
gatewayService
.
BindStickySession
(
c
.
Request
.
Context
(),
currentAPIKey
.
GroupID
,
sessionKey
,
account
.
ID
);
err
!=
nil
{
log
.
Printf
(
"Bind sticky session failed: %v"
,
err
)
accountReleaseFunc
,
err
=
h
.
concurrencyHelper
.
AcquireAccountSlotWithWaitTimeout
(
}
c
,
}
account
.
ID
,
// 账号槽位/等待计数需要在超时或断开时安全回收
selection
.
WaitPlan
.
MaxConcurrency
,
accountReleaseFunc
=
wrapReleaseOnDone
(
c
.
Request
.
Context
(),
accountReleaseFunc
)
selection
.
WaitPlan
.
Timeout
,
reqStream
,
// 转发请求 - 根据账号平台分流
&
streamStarted
,
var
result
*
service
.
ForwardResult
)
requestCtx
:=
c
.
Request
.
Context
()
if
err
!=
nil
{
if
switchCount
>
0
{
log
.
Printf
(
"Account concurrency acquire failed: %v"
,
err
)
requestCtx
=
context
.
WithValue
(
requestCtx
,
ctxkey
.
AccountSwitchCount
,
switchCount
)
h
.
handleConcurrencyError
(
c
,
err
,
"account"
,
streamStarted
)
return
}
}
if
accountWaitCounted
{
if
account
.
Platform
==
service
.
PlatformAntigravity
{
h
.
concurrencyHelper
.
DecrementAccountWaitCount
(
c
.
Request
.
Context
(),
account
.
ID
)
result
,
err
=
h
.
antigravityGatewayService
.
Forward
(
requestCtx
,
c
,
account
,
body
)
accountWaitCounted
=
false
}
else
{
result
,
err
=
h
.
gatewayService
.
Forward
(
requestCtx
,
c
,
account
,
parsedReq
)
}
}
if
err
:=
h
.
gatewayService
.
BindStickySession
(
c
.
Request
.
Context
(),
apiKey
.
GroupID
,
sessionKey
,
account
.
ID
);
err
!=
nil
{
if
accountReleaseFunc
!=
nil
{
log
.
Printf
(
"Bind sticky session failed: %v"
,
err
)
accountReleaseFunc
(
)
}
}
}
if
err
!=
nil
{
// 账号槽位/等待计数需要在超时或断开时安全回收
var
promptTooLongErr
*
service
.
PromptTooLongError
accountReleaseFunc
=
wrapReleaseOnDone
(
c
.
Request
.
Context
(),
accountReleaseFunc
)
if
errors
.
As
(
err
,
&
promptTooLongErr
)
{
log
.
Printf
(
"Prompt too long from antigravity: group=%d fallback_group_id=%v fallback_used=%v"
,
currentAPIKey
.
GroupID
,
fallbackGroupID
,
fallbackUsed
)
// 转发请求 - 根据账号平台分流
if
!
fallbackUsed
&&
fallbackGroupID
!=
nil
&&
*
fallbackGroupID
>
0
{
var
result
*
service
.
ForwardResult
fallbackGroup
,
err
:=
h
.
gatewayService
.
ResolveGroupByID
(
c
.
Request
.
Context
(),
*
fallbackGroupID
)
if
account
.
Platform
==
service
.
PlatformAntigravity
{
if
err
!=
nil
{
result
,
err
=
h
.
antigravityGatewayService
.
Forward
(
c
.
Request
.
Context
(),
c
,
account
,
body
)
log
.
Printf
(
"Resolve fallback group failed: %v"
,
err
)
}
else
{
_
=
h
.
antigravityGatewayService
.
WriteMappedClaudeError
(
c
,
account
,
promptTooLongErr
.
StatusCode
,
promptTooLongErr
.
RequestID
,
promptTooLongErr
.
Body
)
result
,
err
=
h
.
gatewayService
.
Forward
(
c
.
Request
.
Context
(),
c
,
account
,
parsedReq
)
return
}
}
if
accountReleaseFunc
!=
nil
{
if
fallbackGroup
.
Platform
!=
service
.
PlatformAnthropic
||
accountReleaseFunc
()
fallbackGroup
.
SubscriptionType
==
service
.
SubscriptionTypeSubscription
||
}
fallbackGroup
.
FallbackGroupIDOnInvalidRequest
!=
nil
{
if
err
!=
nil
{
log
.
Printf
(
"Fallback group invalid: group=%d platform=%s subscription=%s"
,
fallbackGroup
.
ID
,
fallbackGroup
.
Platform
,
fallbackGroup
.
SubscriptionType
)
var
failoverErr
*
service
.
UpstreamFailoverError
_
=
h
.
antigravityGatewayService
.
WriteMappedClaudeError
(
c
,
account
,
promptTooLongErr
.
StatusCode
,
promptTooLongErr
.
RequestID
,
promptTooLongErr
.
Body
)
if
errors
.
As
(
err
,
&
failoverErr
)
{
return
failedAccountIDs
[
account
.
ID
]
=
struct
{}{}
}
lastFailoverStatus
=
failoverErr
.
StatusCode
fallbackAPIKey
:=
cloneAPIKeyWithGroup
(
apiKey
,
fallbackGroup
)
if
switchCount
>=
maxAccountSwitches
{
if
err
:=
h
.
billingCacheService
.
CheckBillingEligibility
(
c
.
Request
.
Context
(),
fallbackAPIKey
.
User
,
fallbackAPIKey
,
fallbackGroup
,
nil
);
err
!=
nil
{
h
.
handleFailoverExhausted
(
c
,
lastFailoverStatus
,
streamStarted
)
status
,
code
,
message
:=
billingErrorDetails
(
err
)
h
.
handleStreamingAwareError
(
c
,
status
,
code
,
message
,
streamStarted
)
return
}
// 兜底重试按“直接请求兜底分组”处理:清除强制平台,允许按分组平台调度
ctx
:=
context
.
WithValue
(
c
.
Request
.
Context
(),
ctxkey
.
ForcePlatform
,
""
)
c
.
Request
=
c
.
Request
.
WithContext
(
ctx
)
currentAPIKey
=
fallbackAPIKey
currentSubscription
=
nil
fallbackUsed
=
true
retryWithFallback
=
true
break
}
_
=
h
.
antigravityGatewayService
.
WriteMappedClaudeError
(
c
,
account
,
promptTooLongErr
.
StatusCode
,
promptTooLongErr
.
RequestID
,
promptTooLongErr
.
Body
)
return
return
}
}
switchCount
++
var
failoverErr
*
service
.
UpstreamFailoverError
log
.
Printf
(
"Account %d: upstream error %d, switching account %d/%d"
,
account
.
ID
,
failoverErr
.
StatusCode
,
switchCount
,
maxAccountSwitches
)
if
errors
.
As
(
err
,
&
failoverErr
)
{
continue
failedAccountIDs
[
account
.
ID
]
=
struct
{}{}
lastFailoverStatus
=
failoverErr
.
StatusCode
if
switchCount
>=
maxAccountSwitches
{
h
.
handleFailoverExhausted
(
c
,
lastFailoverStatus
,
streamStarted
)
return
}
switchCount
++
log
.
Printf
(
"Account %d: upstream error %d, switching account %d/%d"
,
account
.
ID
,
failoverErr
.
StatusCode
,
switchCount
,
maxAccountSwitches
)
continue
}
// 错误响应已在Forward中处理,这里只记录日志
log
.
Printf
(
"Account %d: Forward request failed: %v"
,
account
.
ID
,
err
)
return
}
}
// 错误响应已在Forward中处理,这里只记录日志
log
.
Printf
(
"Account %d: Forward request failed: %v"
,
account
.
ID
,
err
)
// 捕获请求信息(用于异步记录,避免在 goroutine 中访问 gin.Context)
userAgent
:=
c
.
GetHeader
(
"User-Agent"
)
clientIP
:=
ip
.
GetClientIP
(
c
)
// 异步记录使用量(subscription已在函数开头获取)
go
func
(
result
*
service
.
ForwardResult
,
usedAccount
*
service
.
Account
,
ua
,
clientIP
string
)
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
10
*
time
.
Second
)
defer
cancel
()
if
err
:=
h
.
gatewayService
.
RecordUsage
(
ctx
,
&
service
.
RecordUsageInput
{
Result
:
result
,
APIKey
:
currentAPIKey
,
User
:
currentAPIKey
.
User
,
Account
:
usedAccount
,
Subscription
:
currentSubscription
,
UserAgent
:
ua
,
IPAddress
:
clientIP
,
APIKeyService
:
h
.
apiKeyService
,
});
err
!=
nil
{
log
.
Printf
(
"Record usage failed: %v"
,
err
)
}
}(
result
,
account
,
userAgent
,
clientIP
)
return
}
if
!
retryWithFallback
{
return
return
}
}
// 捕获请求信息(用于异步记录,避免在 goroutine 中访问 gin.Context)
userAgent
:=
c
.
GetHeader
(
"User-Agent"
)
clientIP
:=
ip
.
GetClientIP
(
c
)
// 异步记录使用量(subscription已在函数开头获取)
go
func
(
result
*
service
.
ForwardResult
,
usedAccount
*
service
.
Account
,
ua
,
clientIP
string
)
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
10
*
time
.
Second
)
defer
cancel
()
if
err
:=
h
.
gatewayService
.
RecordUsage
(
ctx
,
&
service
.
RecordUsageInput
{
Result
:
result
,
APIKey
:
apiKey
,
User
:
apiKey
.
User
,
Account
:
usedAccount
,
Subscription
:
subscription
,
UserAgent
:
ua
,
IPAddress
:
clientIP
,
APIKeyService
:
h
.
apiKeyService
,
});
err
!=
nil
{
log
.
Printf
(
"Record usage failed: %v"
,
err
)
}
}(
result
,
account
,
userAgent
,
clientIP
)
return
}
}
}
}
...
@@ -532,6 +590,17 @@ func (h *GatewayHandler) AntigravityModels(c *gin.Context) {
...
@@ -532,6 +590,17 @@ func (h *GatewayHandler) AntigravityModels(c *gin.Context) {
})
})
}
}
func
cloneAPIKeyWithGroup
(
apiKey
*
service
.
APIKey
,
group
*
service
.
Group
)
*
service
.
APIKey
{
if
apiKey
==
nil
||
group
==
nil
{
return
apiKey
}
cloned
:=
*
apiKey
groupID
:=
group
.
ID
cloned
.
GroupID
=
&
groupID
cloned
.
Group
=
group
return
&
cloned
}
// Usage handles getting account balance and usage statistics for CC Switch integration
// Usage handles getting account balance and usage statistics for CC Switch integration
// GET /v1/usage
// GET /v1/usage
func
(
h
*
GatewayHandler
)
Usage
(
c
*
gin
.
Context
)
{
func
(
h
*
GatewayHandler
)
Usage
(
c
*
gin
.
Context
)
{
...
...
backend/internal/handler/gemini_v1beta_handler.go
View file @
ff8b1b4a
...
@@ -14,6 +14,7 @@ import (
...
@@ -14,6 +14,7 @@ import (
"time"
"time"
"github.com/Wei-Shaw/sub2api/internal/pkg/antigravity"
"github.com/Wei-Shaw/sub2api/internal/pkg/antigravity"
"github.com/Wei-Shaw/sub2api/internal/pkg/ctxkey"
"github.com/Wei-Shaw/sub2api/internal/pkg/gemini"
"github.com/Wei-Shaw/sub2api/internal/pkg/gemini"
"github.com/Wei-Shaw/sub2api/internal/pkg/googleapi"
"github.com/Wei-Shaw/sub2api/internal/pkg/googleapi"
"github.com/Wei-Shaw/sub2api/internal/pkg/ip"
"github.com/Wei-Shaw/sub2api/internal/pkg/ip"
...
@@ -335,10 +336,14 @@ func (h *GatewayHandler) GeminiV1BetaModels(c *gin.Context) {
...
@@ -335,10 +336,14 @@ func (h *GatewayHandler) GeminiV1BetaModels(c *gin.Context) {
// 5) forward (根据平台分流)
// 5) forward (根据平台分流)
var
result
*
service
.
ForwardResult
var
result
*
service
.
ForwardResult
requestCtx
:=
c
.
Request
.
Context
()
if
switchCount
>
0
{
requestCtx
=
context
.
WithValue
(
requestCtx
,
ctxkey
.
AccountSwitchCount
,
switchCount
)
}
if
account
.
Platform
==
service
.
PlatformAntigravity
{
if
account
.
Platform
==
service
.
PlatformAntigravity
{
result
,
err
=
h
.
antigravityGatewayService
.
ForwardGemini
(
c
.
R
equest
.
Context
()
,
c
,
account
,
modelName
,
action
,
stream
,
body
)
result
,
err
=
h
.
antigravityGatewayService
.
ForwardGemini
(
r
equest
Ctx
,
c
,
account
,
modelName
,
action
,
stream
,
body
)
}
else
{
}
else
{
result
,
err
=
h
.
geminiCompatService
.
ForwardNative
(
c
.
R
equest
.
Context
()
,
c
,
account
,
modelName
,
action
,
stream
,
body
)
result
,
err
=
h
.
geminiCompatService
.
ForwardNative
(
r
equest
Ctx
,
c
,
account
,
modelName
,
action
,
stream
,
body
)
}
}
if
accountReleaseFunc
!=
nil
{
if
accountReleaseFunc
!=
nil
{
accountReleaseFunc
()
accountReleaseFunc
()
...
...
backend/internal/pkg/antigravity/oauth.go
View file @
ff8b1b4a
...
@@ -40,17 +40,48 @@ const (
...
@@ -40,17 +40,48 @@ const (
// URL 可用性 TTL(不可用 URL 的恢复时间)
// URL 可用性 TTL(不可用 URL 的恢复时间)
URLAvailabilityTTL
=
5
*
time
.
Minute
URLAvailabilityTTL
=
5
*
time
.
Minute
// Antigravity API 端点
antigravityProdBaseURL
=
"https://cloudcode-pa.googleapis.com"
antigravityDailyBaseURL
=
"https://daily-cloudcode-pa.sandbox.googleapis.com"
)
)
// BaseURLs 定义 Antigravity API 端点(与 Antigravity-Manager 保持一致)
// BaseURLs 定义 Antigravity API 端点(与 Antigravity-Manager 保持一致)
var
BaseURLs
=
[]
string
{
var
BaseURLs
=
[]
string
{
"https://cloudcode-pa.googleapis.com"
,
// prod (优先)
antigravityProdBaseURL
,
// prod (优先)
"https://daily-cloudcode-pa.sandbox.googleapis.com"
,
// daily sandbox (备用)
antigravityDailyBaseURL
,
// daily sandbox (备用)
}
}
// BaseURL 默认 URL(保持向后兼容)
// BaseURL 默认 URL(保持向后兼容)
var
BaseURL
=
BaseURLs
[
0
]
var
BaseURL
=
BaseURLs
[
0
]
// ForwardBaseURLs 返回 API 转发用的 URL 顺序(daily 优先)
func
ForwardBaseURLs
()
[]
string
{
if
len
(
BaseURLs
)
==
0
{
return
nil
}
urls
:=
append
([]
string
(
nil
),
BaseURLs
...
)
dailyIndex
:=
-
1
for
i
,
url
:=
range
urls
{
if
url
==
antigravityDailyBaseURL
{
dailyIndex
=
i
break
}
}
if
dailyIndex
<=
0
{
return
urls
}
reordered
:=
make
([]
string
,
0
,
len
(
urls
))
reordered
=
append
(
reordered
,
urls
[
dailyIndex
])
for
i
,
url
:=
range
urls
{
if
i
==
dailyIndex
{
continue
}
reordered
=
append
(
reordered
,
url
)
}
return
reordered
}
// URLAvailability 管理 URL 可用性状态(带 TTL 自动恢复和动态优先级)
// URLAvailability 管理 URL 可用性状态(带 TTL 自动恢复和动态优先级)
type
URLAvailability
struct
{
type
URLAvailability
struct
{
mu
sync
.
RWMutex
mu
sync
.
RWMutex
...
@@ -100,22 +131,37 @@ func (u *URLAvailability) IsAvailable(url string) bool {
...
@@ -100,22 +131,37 @@ func (u *URLAvailability) IsAvailable(url string) bool {
// GetAvailableURLs 返回可用的 URL 列表
// GetAvailableURLs 返回可用的 URL 列表
// 最近成功的 URL 优先,其他按默认顺序
// 最近成功的 URL 优先,其他按默认顺序
func
(
u
*
URLAvailability
)
GetAvailableURLs
()
[]
string
{
func
(
u
*
URLAvailability
)
GetAvailableURLs
()
[]
string
{
return
u
.
GetAvailableURLsWithBase
(
BaseURLs
)
}
// GetAvailableURLsWithBase 返回可用的 URL 列表(使用自定义顺序)
// 最近成功的 URL 优先,其他按传入顺序
func
(
u
*
URLAvailability
)
GetAvailableURLsWithBase
(
baseURLs
[]
string
)
[]
string
{
u
.
mu
.
RLock
()
u
.
mu
.
RLock
()
defer
u
.
mu
.
RUnlock
()
defer
u
.
mu
.
RUnlock
()
now
:=
time
.
Now
()
now
:=
time
.
Now
()
result
:=
make
([]
string
,
0
,
len
(
B
aseURLs
))
result
:=
make
([]
string
,
0
,
len
(
b
aseURLs
))
// 如果有最近成功的 URL 且可用,放在最前面
// 如果有最近成功的 URL 且可用,放在最前面
if
u
.
lastSuccess
!=
""
{
if
u
.
lastSuccess
!=
""
{
expiry
,
exists
:=
u
.
unavailable
[
u
.
lastSuccess
]
found
:=
false
if
!
exists
||
now
.
After
(
expiry
)
{
for
_
,
url
:=
range
baseURLs
{
result
=
append
(
result
,
u
.
lastSuccess
)
if
url
==
u
.
lastSuccess
{
found
=
true
break
}
}
if
found
{
expiry
,
exists
:=
u
.
unavailable
[
u
.
lastSuccess
]
if
!
exists
||
now
.
After
(
expiry
)
{
result
=
append
(
result
,
u
.
lastSuccess
)
}
}
}
}
}
// 添加其他可用的 URL(按
默认
顺序)
// 添加其他可用的 URL(按
传入
顺序)
for
_
,
url
:=
range
B
aseURLs
{
for
_
,
url
:=
range
b
aseURLs
{
// 跳过已添加的 lastSuccess
// 跳过已添加的 lastSuccess
if
url
==
u
.
lastSuccess
{
if
url
==
u
.
lastSuccess
{
continue
continue
...
...
backend/internal/pkg/antigravity/request_transformer.go
View file @
ff8b1b4a
...
@@ -44,11 +44,13 @@ type TransformOptions struct {
...
@@ -44,11 +44,13 @@ type TransformOptions struct {
// IdentityPatch 可选:自定义注入到 systemInstruction 开头的身份防护提示词;
// IdentityPatch 可选:自定义注入到 systemInstruction 开头的身份防护提示词;
// 为空时使用默认模板(包含 [IDENTITY_PATCH] 及 SYSTEM_PROMPT_BEGIN 标记)。
// 为空时使用默认模板(包含 [IDENTITY_PATCH] 及 SYSTEM_PROMPT_BEGIN 标记)。
IdentityPatch
string
IdentityPatch
string
EnableMCPXML
bool
}
}
func
DefaultTransformOptions
()
TransformOptions
{
func
DefaultTransformOptions
()
TransformOptions
{
return
TransformOptions
{
return
TransformOptions
{
EnableIdentityPatch
:
true
,
EnableIdentityPatch
:
true
,
EnableMCPXML
:
true
,
}
}
}
}
...
@@ -257,8 +259,8 @@ func buildSystemInstruction(system json.RawMessage, modelName string, opts Trans
...
@@ -257,8 +259,8 @@ func buildSystemInstruction(system json.RawMessage, modelName string, opts Trans
// 添加用户的 system prompt
// 添加用户的 system prompt
parts
=
append
(
parts
,
userSystemParts
...
)
parts
=
append
(
parts
,
userSystemParts
...
)
// 检测是否有 MCP 工具,如有则注入 XML 调用协议
// 检测是否有 MCP 工具,如有
且启用了 MCP XML 注入
则注入 XML 调用协议
if
hasMCPTools
(
tools
)
{
if
opts
.
EnableMCPXML
&&
hasMCPTools
(
tools
)
{
parts
=
append
(
parts
,
GeminiPart
{
Text
:
mcpXMLProtocol
})
parts
=
append
(
parts
,
GeminiPart
{
Text
:
mcpXMLProtocol
})
}
}
...
@@ -492,9 +494,23 @@ func parseToolResultContent(content json.RawMessage, isError bool) string {
...
@@ -492,9 +494,23 @@ func parseToolResultContent(content json.RawMessage, isError bool) string {
}
}
// buildGenerationConfig 构建 generationConfig
// buildGenerationConfig 构建 generationConfig
const
(
defaultMaxOutputTokens
=
64000
maxOutputTokensUpperBound
=
65000
maxOutputTokensClaude
=
64000
)
func
maxOutputTokensLimit
(
model
string
)
int
{
if
strings
.
HasPrefix
(
model
,
"claude-"
)
{
return
maxOutputTokensClaude
}
return
maxOutputTokensUpperBound
}
func
buildGenerationConfig
(
req
*
ClaudeRequest
)
*
GeminiGenerationConfig
{
func
buildGenerationConfig
(
req
*
ClaudeRequest
)
*
GeminiGenerationConfig
{
maxLimit
:=
maxOutputTokensLimit
(
req
.
Model
)
config
:=
&
GeminiGenerationConfig
{
config
:=
&
GeminiGenerationConfig
{
MaxOutputTokens
:
64000
,
// 默认最大输出
MaxOutputTokens
:
defaultMaxOutputTokens
,
// 默认最大输出
StopSequences
:
DefaultStopSequences
,
StopSequences
:
DefaultStopSequences
,
}
}
...
@@ -518,6 +534,10 @@ func buildGenerationConfig(req *ClaudeRequest) *GeminiGenerationConfig {
...
@@ -518,6 +534,10 @@ func buildGenerationConfig(req *ClaudeRequest) *GeminiGenerationConfig {
}
}
}
}
if
config
.
MaxOutputTokens
>
maxLimit
{
config
.
MaxOutputTokens
=
maxLimit
}
// 其他参数
// 其他参数
if
req
.
Temperature
!=
nil
{
if
req
.
Temperature
!=
nil
{
config
.
Temperature
=
req
.
Temperature
config
.
Temperature
=
req
.
Temperature
...
...
Prev
1
2
3
4
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment