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
1de18b89
"backend/internal/handler/vscode:/vscode.git/clone" did not exist on "66fde7a2e609b13adcdeeaac3d4ac5b1296edc29"
Commit
1de18b89
authored
Mar 19, 2026
by
Wang Lvyuan
Browse files
merge: sync upstream/main before PR
parents
882518c1
9f6ab6b8
Changes
107
Hide whitespace changes
Inline
Side-by-side
backend/cmd/server/wire_gen.go
View file @
1de18b89
...
@@ -110,7 +110,6 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
...
@@ -110,7 +110,6 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
concurrencyCache
:=
repository
.
ProvideConcurrencyCache
(
redisClient
,
configConfig
)
concurrencyCache
:=
repository
.
ProvideConcurrencyCache
(
redisClient
,
configConfig
)
concurrencyService
:=
service
.
ProvideConcurrencyService
(
concurrencyCache
,
accountRepository
,
configConfig
)
concurrencyService
:=
service
.
ProvideConcurrencyService
(
concurrencyCache
,
accountRepository
,
configConfig
)
adminUserHandler
:=
admin
.
NewUserHandler
(
adminService
,
concurrencyService
)
adminUserHandler
:=
admin
.
NewUserHandler
(
adminService
,
concurrencyService
)
groupHandler
:=
admin
.
NewGroupHandler
(
adminService
)
claudeOAuthClient
:=
repository
.
NewClaudeOAuthClient
()
claudeOAuthClient
:=
repository
.
NewClaudeOAuthClient
()
oAuthService
:=
service
.
NewOAuthService
(
proxyRepository
,
claudeOAuthClient
)
oAuthService
:=
service
.
NewOAuthService
(
proxyRepository
,
claudeOAuthClient
)
openAIOAuthClient
:=
repository
.
NewOpenAIOAuthClient
()
openAIOAuthClient
:=
repository
.
NewOpenAIOAuthClient
()
...
@@ -143,6 +142,8 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
...
@@ -143,6 +142,8 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
crsSyncService
:=
service
.
NewCRSSyncService
(
accountRepository
,
proxyRepository
,
oAuthService
,
openAIOAuthService
,
geminiOAuthService
,
configConfig
)
crsSyncService
:=
service
.
NewCRSSyncService
(
accountRepository
,
proxyRepository
,
oAuthService
,
openAIOAuthService
,
geminiOAuthService
,
configConfig
)
sessionLimitCache
:=
repository
.
ProvideSessionLimitCache
(
redisClient
,
configConfig
)
sessionLimitCache
:=
repository
.
ProvideSessionLimitCache
(
redisClient
,
configConfig
)
rpmCache
:=
repository
.
NewRPMCache
(
redisClient
)
rpmCache
:=
repository
.
NewRPMCache
(
redisClient
)
groupCapacityService
:=
service
.
NewGroupCapacityService
(
accountRepository
,
groupRepository
,
concurrencyService
,
sessionLimitCache
,
rpmCache
)
groupHandler
:=
admin
.
NewGroupHandler
(
adminService
,
dashboardService
,
groupCapacityService
)
accountHandler
:=
admin
.
NewAccountHandler
(
adminService
,
oAuthService
,
openAIOAuthService
,
geminiOAuthService
,
antigravityOAuthService
,
rateLimitService
,
accountUsageService
,
accountTestService
,
concurrencyService
,
crsSyncService
,
sessionLimitCache
,
rpmCache
,
compositeTokenCacheInvalidator
)
accountHandler
:=
admin
.
NewAccountHandler
(
adminService
,
oAuthService
,
openAIOAuthService
,
geminiOAuthService
,
antigravityOAuthService
,
rateLimitService
,
accountUsageService
,
accountTestService
,
concurrencyService
,
crsSyncService
,
sessionLimitCache
,
rpmCache
,
compositeTokenCacheInvalidator
)
adminAnnouncementHandler
:=
admin
.
NewAnnouncementHandler
(
announcementService
)
adminAnnouncementHandler
:=
admin
.
NewAnnouncementHandler
(
announcementService
)
dataManagementService
:=
service
.
NewDataManagementService
()
dataManagementService
:=
service
.
NewDataManagementService
()
...
...
backend/ent/migrate/schema.go
View file @
1de18b89
...
@@ -716,6 +716,7 @@ var (
...
@@ -716,6 +716,7 @@ var (
{
Name
:
"id"
,
Type
:
field
.
TypeInt64
,
Increment
:
true
},
{
Name
:
"id"
,
Type
:
field
.
TypeInt64
,
Increment
:
true
},
{
Name
:
"request_id"
,
Type
:
field
.
TypeString
,
Size
:
64
},
{
Name
:
"request_id"
,
Type
:
field
.
TypeString
,
Size
:
64
},
{
Name
:
"model"
,
Type
:
field
.
TypeString
,
Size
:
100
},
{
Name
:
"model"
,
Type
:
field
.
TypeString
,
Size
:
100
},
{
Name
:
"upstream_model"
,
Type
:
field
.
TypeString
,
Nullable
:
true
,
Size
:
100
},
{
Name
:
"input_tokens"
,
Type
:
field
.
TypeInt
,
Default
:
0
},
{
Name
:
"input_tokens"
,
Type
:
field
.
TypeInt
,
Default
:
0
},
{
Name
:
"output_tokens"
,
Type
:
field
.
TypeInt
,
Default
:
0
},
{
Name
:
"output_tokens"
,
Type
:
field
.
TypeInt
,
Default
:
0
},
{
Name
:
"cache_creation_tokens"
,
Type
:
field
.
TypeInt
,
Default
:
0
},
{
Name
:
"cache_creation_tokens"
,
Type
:
field
.
TypeInt
,
Default
:
0
},
...
@@ -755,31 +756,31 @@ var (
...
@@ -755,31 +756,31 @@ var (
ForeignKeys
:
[]
*
schema
.
ForeignKey
{
ForeignKeys
:
[]
*
schema
.
ForeignKey
{
{
{
Symbol
:
"usage_logs_api_keys_usage_logs"
,
Symbol
:
"usage_logs_api_keys_usage_logs"
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
8
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
9
]},
RefColumns
:
[]
*
schema
.
Column
{
APIKeysColumns
[
0
]},
RefColumns
:
[]
*
schema
.
Column
{
APIKeysColumns
[
0
]},
OnDelete
:
schema
.
NoAction
,
OnDelete
:
schema
.
NoAction
,
},
},
{
{
Symbol
:
"usage_logs_accounts_usage_logs"
,
Symbol
:
"usage_logs_accounts_usage_logs"
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
29
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
30
]},
RefColumns
:
[]
*
schema
.
Column
{
AccountsColumns
[
0
]},
RefColumns
:
[]
*
schema
.
Column
{
AccountsColumns
[
0
]},
OnDelete
:
schema
.
NoAction
,
OnDelete
:
schema
.
NoAction
,
},
},
{
{
Symbol
:
"usage_logs_groups_usage_logs"
,
Symbol
:
"usage_logs_groups_usage_logs"
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
3
0
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
3
1
]},
RefColumns
:
[]
*
schema
.
Column
{
GroupsColumns
[
0
]},
RefColumns
:
[]
*
schema
.
Column
{
GroupsColumns
[
0
]},
OnDelete
:
schema
.
SetNull
,
OnDelete
:
schema
.
SetNull
,
},
},
{
{
Symbol
:
"usage_logs_users_usage_logs"
,
Symbol
:
"usage_logs_users_usage_logs"
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
3
1
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
3
2
]},
RefColumns
:
[]
*
schema
.
Column
{
UsersColumns
[
0
]},
RefColumns
:
[]
*
schema
.
Column
{
UsersColumns
[
0
]},
OnDelete
:
schema
.
NoAction
,
OnDelete
:
schema
.
NoAction
,
},
},
{
{
Symbol
:
"usage_logs_user_subscriptions_usage_logs"
,
Symbol
:
"usage_logs_user_subscriptions_usage_logs"
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
3
2
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
3
3
]},
RefColumns
:
[]
*
schema
.
Column
{
UserSubscriptionsColumns
[
0
]},
RefColumns
:
[]
*
schema
.
Column
{
UserSubscriptionsColumns
[
0
]},
OnDelete
:
schema
.
SetNull
,
OnDelete
:
schema
.
SetNull
,
},
},
...
@@ -788,32 +789,32 @@ var (
...
@@ -788,32 +789,32 @@ var (
{
{
Name
:
"usagelog_user_id"
,
Name
:
"usagelog_user_id"
,
Unique
:
false
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
3
1
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
3
2
]},
},
},
{
{
Name
:
"usagelog_api_key_id"
,
Name
:
"usagelog_api_key_id"
,
Unique
:
false
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
8
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
9
]},
},
},
{
{
Name
:
"usagelog_account_id"
,
Name
:
"usagelog_account_id"
,
Unique
:
false
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
29
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
30
]},
},
},
{
{
Name
:
"usagelog_group_id"
,
Name
:
"usagelog_group_id"
,
Unique
:
false
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
3
0
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
3
1
]},
},
},
{
{
Name
:
"usagelog_subscription_id"
,
Name
:
"usagelog_subscription_id"
,
Unique
:
false
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
3
2
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
3
3
]},
},
},
{
{
Name
:
"usagelog_created_at"
,
Name
:
"usagelog_created_at"
,
Unique
:
false
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
7
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
8
]},
},
},
{
{
Name
:
"usagelog_model"
,
Name
:
"usagelog_model"
,
...
@@ -828,17 +829,17 @@ var (
...
@@ -828,17 +829,17 @@ var (
{
{
Name
:
"usagelog_user_id_created_at"
,
Name
:
"usagelog_user_id_created_at"
,
Unique
:
false
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
3
1
],
UsageLogsColumns
[
2
7
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
3
2
],
UsageLogsColumns
[
2
8
]},
},
},
{
{
Name
:
"usagelog_api_key_id_created_at"
,
Name
:
"usagelog_api_key_id_created_at"
,
Unique
:
false
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
8
],
UsageLogsColumns
[
2
7
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
9
],
UsageLogsColumns
[
2
8
]},
},
},
{
{
Name
:
"usagelog_group_id_created_at"
,
Name
:
"usagelog_group_id_created_at"
,
Unique
:
false
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
3
0
],
UsageLogsColumns
[
2
7
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
3
1
],
UsageLogsColumns
[
2
8
]},
},
},
},
},
}
}
...
...
backend/ent/mutation.go
View file @
1de18b89
...
@@ -18239,6 +18239,7 @@ type UsageLogMutation struct {
...
@@ -18239,6 +18239,7 @@ type UsageLogMutation struct {
id *int64
id *int64
request_id *string
request_id *string
model *string
model *string
upstream_model *string
input_tokens *int
input_tokens *int
addinput_tokens *int
addinput_tokens *int
output_tokens *int
output_tokens *int
...
@@ -18576,6 +18577,55 @@ func (m *UsageLogMutation) ResetModel() {
...
@@ -18576,6 +18577,55 @@ func (m *UsageLogMutation) ResetModel() {
m.model = nil
m.model = nil
}
}
// SetUpstreamModel sets the "upstream_model" field.
func (m *UsageLogMutation) SetUpstreamModel(s string) {
m.upstream_model = &s
}
// UpstreamModel returns the value of the "upstream_model" field in the mutation.
func (m *UsageLogMutation) UpstreamModel() (r string, exists bool) {
v := m.upstream_model
if v == nil {
return
}
return *v, true
}
// OldUpstreamModel returns the old "upstream_model" field's value of the UsageLog entity.
// If the UsageLog 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 *UsageLogMutation) OldUpstreamModel(ctx context.Context) (v *string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUpstreamModel is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUpstreamModel requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUpstreamModel: %w", err)
}
return oldValue.UpstreamModel, nil
}
// ClearUpstreamModel clears the value of the "upstream_model" field.
func (m *UsageLogMutation) ClearUpstreamModel() {
m.upstream_model = nil
m.clearedFields[usagelog.FieldUpstreamModel] = struct{}{}
}
// UpstreamModelCleared returns if the "upstream_model" field was cleared in this mutation.
func (m *UsageLogMutation) UpstreamModelCleared() bool {
_, ok := m.clearedFields[usagelog.FieldUpstreamModel]
return ok
}
// ResetUpstreamModel resets all changes to the "upstream_model" field.
func (m *UsageLogMutation) ResetUpstreamModel() {
m.upstream_model = nil
delete(m.clearedFields, usagelog.FieldUpstreamModel)
}
// SetGroupID sets the "group_id" field.
// SetGroupID sets the "group_id" field.
func (m *UsageLogMutation) SetGroupID(i int64) {
func (m *UsageLogMutation) SetGroupID(i int64) {
m.group = &i
m.group = &i
...
@@ -20197,7 +20247,7 @@ func (m *UsageLogMutation) Type() string {
...
@@ -20197,7 +20247,7 @@ func (m *UsageLogMutation) 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 *UsageLogMutation) Fields() []string {
func (m *UsageLogMutation) Fields() []string {
fields := make([]string, 0, 3
2
)
fields := make([]string, 0, 3
3
)
if m.user != nil {
if m.user != nil {
fields = append(fields, usagelog.FieldUserID)
fields = append(fields, usagelog.FieldUserID)
}
}
...
@@ -20213,6 +20263,9 @@ func (m *UsageLogMutation) Fields() []string {
...
@@ -20213,6 +20263,9 @@ func (m *UsageLogMutation) Fields() []string {
if m.model != nil {
if m.model != nil {
fields = append(fields, usagelog.FieldModel)
fields = append(fields, usagelog.FieldModel)
}
}
if m.upstream_model != nil {
fields = append(fields, usagelog.FieldUpstreamModel)
}
if m.group != nil {
if m.group != nil {
fields = append(fields, usagelog.FieldGroupID)
fields = append(fields, usagelog.FieldGroupID)
}
}
...
@@ -20312,6 +20365,8 @@ func (m *UsageLogMutation) Field(name string) (ent.Value, bool) {
...
@@ -20312,6 +20365,8 @@ func (m *UsageLogMutation) Field(name string) (ent.Value, bool) {
return m.RequestID()
return m.RequestID()
case usagelog.FieldModel:
case usagelog.FieldModel:
return m.Model()
return m.Model()
case usagelog.FieldUpstreamModel:
return m.UpstreamModel()
case usagelog.FieldGroupID:
case usagelog.FieldGroupID:
return m.GroupID()
return m.GroupID()
case usagelog.FieldSubscriptionID:
case usagelog.FieldSubscriptionID:
...
@@ -20385,6 +20440,8 @@ func (m *UsageLogMutation) OldField(ctx context.Context, name string) (ent.Value
...
@@ -20385,6 +20440,8 @@ func (m *UsageLogMutation) OldField(ctx context.Context, name string) (ent.Value
return m.OldRequestID(ctx)
return m.OldRequestID(ctx)
case usagelog.FieldModel:
case usagelog.FieldModel:
return m.OldModel(ctx)
return m.OldModel(ctx)
case usagelog.FieldUpstreamModel:
return m.OldUpstreamModel(ctx)
case usagelog.FieldGroupID:
case usagelog.FieldGroupID:
return m.OldGroupID(ctx)
return m.OldGroupID(ctx)
case usagelog.FieldSubscriptionID:
case usagelog.FieldSubscriptionID:
...
@@ -20483,6 +20540,13 @@ func (m *UsageLogMutation) SetField(name string, value ent.Value) error {
...
@@ -20483,6 +20540,13 @@ func (m *UsageLogMutation) SetField(name string, value ent.Value) error {
}
}
m.SetModel(v)
m.SetModel(v)
return nil
return nil
case usagelog.FieldUpstreamModel:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpstreamModel(v)
return nil
case usagelog.FieldGroupID:
case usagelog.FieldGroupID:
v, ok := value.(int64)
v, ok := value.(int64)
if !ok {
if !ok {
...
@@ -20921,6 +20985,9 @@ func (m *UsageLogMutation) AddField(name string, value ent.Value) error {
...
@@ -20921,6 +20985,9 @@ func (m *UsageLogMutation) AddField(name string, value ent.Value) error {
// mutation.
// mutation.
func (m *UsageLogMutation) ClearedFields() []string {
func (m *UsageLogMutation) ClearedFields() []string {
var fields []string
var fields []string
if m.FieldCleared(usagelog.FieldUpstreamModel) {
fields = append(fields, usagelog.FieldUpstreamModel)
}
if m.FieldCleared(usagelog.FieldGroupID) {
if m.FieldCleared(usagelog.FieldGroupID) {
fields = append(fields, usagelog.FieldGroupID)
fields = append(fields, usagelog.FieldGroupID)
}
}
...
@@ -20962,6 +21029,9 @@ func (m *UsageLogMutation) FieldCleared(name string) bool {
...
@@ -20962,6 +21029,9 @@ func (m *UsageLogMutation) FieldCleared(name string) bool {
// error if the field is not defined in the schema.
// error if the field is not defined in the schema.
func (m *UsageLogMutation) ClearField(name string) error {
func (m *UsageLogMutation) ClearField(name string) error {
switch name {
switch name {
case usagelog.FieldUpstreamModel:
m.ClearUpstreamModel()
return nil
case usagelog.FieldGroupID:
case usagelog.FieldGroupID:
m.ClearGroupID()
m.ClearGroupID()
return nil
return nil
...
@@ -21012,6 +21082,9 @@ func (m *UsageLogMutation) ResetField(name string) error {
...
@@ -21012,6 +21082,9 @@ func (m *UsageLogMutation) ResetField(name string) error {
case usagelog.FieldModel:
case usagelog.FieldModel:
m.ResetModel()
m.ResetModel()
return nil
return nil
case usagelog.FieldUpstreamModel:
m.ResetUpstreamModel()
return nil
case usagelog.FieldGroupID:
case usagelog.FieldGroupID:
m.ResetGroupID()
m.ResetGroupID()
return nil
return nil
...
...
backend/ent/runtime/runtime.go
View file @
1de18b89
...
@@ -821,92 +821,96 @@ func init() {
...
@@ -821,92 +821,96 @@ func init() {
return
nil
return
nil
}
}
}()
}()
// usagelogDescUpstreamModel is the schema descriptor for upstream_model field.
usagelogDescUpstreamModel
:=
usagelogFields
[
5
]
.
Descriptor
()
// usagelog.UpstreamModelValidator is a validator for the "upstream_model" field. It is called by the builders before save.
usagelog
.
UpstreamModelValidator
=
usagelogDescUpstreamModel
.
Validators
[
0
]
.
(
func
(
string
)
error
)
// usagelogDescInputTokens is the schema descriptor for input_tokens field.
// usagelogDescInputTokens is the schema descriptor for input_tokens field.
usagelogDescInputTokens
:=
usagelogFields
[
7
]
.
Descriptor
()
usagelogDescInputTokens
:=
usagelogFields
[
8
]
.
Descriptor
()
// usagelog.DefaultInputTokens holds the default value on creation for the input_tokens field.
// usagelog.DefaultInputTokens holds the default value on creation for the input_tokens field.
usagelog
.
DefaultInputTokens
=
usagelogDescInputTokens
.
Default
.
(
int
)
usagelog
.
DefaultInputTokens
=
usagelogDescInputTokens
.
Default
.
(
int
)
// usagelogDescOutputTokens is the schema descriptor for output_tokens field.
// usagelogDescOutputTokens is the schema descriptor for output_tokens field.
usagelogDescOutputTokens
:=
usagelogFields
[
8
]
.
Descriptor
()
usagelogDescOutputTokens
:=
usagelogFields
[
9
]
.
Descriptor
()
// usagelog.DefaultOutputTokens holds the default value on creation for the output_tokens field.
// usagelog.DefaultOutputTokens holds the default value on creation for the output_tokens field.
usagelog
.
DefaultOutputTokens
=
usagelogDescOutputTokens
.
Default
.
(
int
)
usagelog
.
DefaultOutputTokens
=
usagelogDescOutputTokens
.
Default
.
(
int
)
// usagelogDescCacheCreationTokens is the schema descriptor for cache_creation_tokens field.
// usagelogDescCacheCreationTokens is the schema descriptor for cache_creation_tokens field.
usagelogDescCacheCreationTokens
:=
usagelogFields
[
9
]
.
Descriptor
()
usagelogDescCacheCreationTokens
:=
usagelogFields
[
10
]
.
Descriptor
()
// usagelog.DefaultCacheCreationTokens holds the default value on creation for the cache_creation_tokens field.
// usagelog.DefaultCacheCreationTokens holds the default value on creation for the cache_creation_tokens field.
usagelog
.
DefaultCacheCreationTokens
=
usagelogDescCacheCreationTokens
.
Default
.
(
int
)
usagelog
.
DefaultCacheCreationTokens
=
usagelogDescCacheCreationTokens
.
Default
.
(
int
)
// usagelogDescCacheReadTokens is the schema descriptor for cache_read_tokens field.
// usagelogDescCacheReadTokens is the schema descriptor for cache_read_tokens field.
usagelogDescCacheReadTokens
:=
usagelogFields
[
1
0
]
.
Descriptor
()
usagelogDescCacheReadTokens
:=
usagelogFields
[
1
1
]
.
Descriptor
()
// usagelog.DefaultCacheReadTokens holds the default value on creation for the cache_read_tokens field.
// usagelog.DefaultCacheReadTokens holds the default value on creation for the cache_read_tokens field.
usagelog
.
DefaultCacheReadTokens
=
usagelogDescCacheReadTokens
.
Default
.
(
int
)
usagelog
.
DefaultCacheReadTokens
=
usagelogDescCacheReadTokens
.
Default
.
(
int
)
// usagelogDescCacheCreation5mTokens is the schema descriptor for cache_creation_5m_tokens field.
// usagelogDescCacheCreation5mTokens is the schema descriptor for cache_creation_5m_tokens field.
usagelogDescCacheCreation5mTokens
:=
usagelogFields
[
1
1
]
.
Descriptor
()
usagelogDescCacheCreation5mTokens
:=
usagelogFields
[
1
2
]
.
Descriptor
()
// usagelog.DefaultCacheCreation5mTokens holds the default value on creation for the cache_creation_5m_tokens field.
// usagelog.DefaultCacheCreation5mTokens holds the default value on creation for the cache_creation_5m_tokens field.
usagelog
.
DefaultCacheCreation5mTokens
=
usagelogDescCacheCreation5mTokens
.
Default
.
(
int
)
usagelog
.
DefaultCacheCreation5mTokens
=
usagelogDescCacheCreation5mTokens
.
Default
.
(
int
)
// usagelogDescCacheCreation1hTokens is the schema descriptor for cache_creation_1h_tokens field.
// usagelogDescCacheCreation1hTokens is the schema descriptor for cache_creation_1h_tokens field.
usagelogDescCacheCreation1hTokens
:=
usagelogFields
[
1
2
]
.
Descriptor
()
usagelogDescCacheCreation1hTokens
:=
usagelogFields
[
1
3
]
.
Descriptor
()
// usagelog.DefaultCacheCreation1hTokens holds the default value on creation for the cache_creation_1h_tokens field.
// usagelog.DefaultCacheCreation1hTokens holds the default value on creation for the cache_creation_1h_tokens field.
usagelog
.
DefaultCacheCreation1hTokens
=
usagelogDescCacheCreation1hTokens
.
Default
.
(
int
)
usagelog
.
DefaultCacheCreation1hTokens
=
usagelogDescCacheCreation1hTokens
.
Default
.
(
int
)
// usagelogDescInputCost is the schema descriptor for input_cost field.
// usagelogDescInputCost is the schema descriptor for input_cost field.
usagelogDescInputCost
:=
usagelogFields
[
1
3
]
.
Descriptor
()
usagelogDescInputCost
:=
usagelogFields
[
1
4
]
.
Descriptor
()
// usagelog.DefaultInputCost holds the default value on creation for the input_cost field.
// usagelog.DefaultInputCost holds the default value on creation for the input_cost field.
usagelog
.
DefaultInputCost
=
usagelogDescInputCost
.
Default
.
(
float64
)
usagelog
.
DefaultInputCost
=
usagelogDescInputCost
.
Default
.
(
float64
)
// usagelogDescOutputCost is the schema descriptor for output_cost field.
// usagelogDescOutputCost is the schema descriptor for output_cost field.
usagelogDescOutputCost
:=
usagelogFields
[
1
4
]
.
Descriptor
()
usagelogDescOutputCost
:=
usagelogFields
[
1
5
]
.
Descriptor
()
// usagelog.DefaultOutputCost holds the default value on creation for the output_cost field.
// usagelog.DefaultOutputCost holds the default value on creation for the output_cost field.
usagelog
.
DefaultOutputCost
=
usagelogDescOutputCost
.
Default
.
(
float64
)
usagelog
.
DefaultOutputCost
=
usagelogDescOutputCost
.
Default
.
(
float64
)
// usagelogDescCacheCreationCost is the schema descriptor for cache_creation_cost field.
// usagelogDescCacheCreationCost is the schema descriptor for cache_creation_cost field.
usagelogDescCacheCreationCost
:=
usagelogFields
[
1
5
]
.
Descriptor
()
usagelogDescCacheCreationCost
:=
usagelogFields
[
1
6
]
.
Descriptor
()
// usagelog.DefaultCacheCreationCost holds the default value on creation for the cache_creation_cost field.
// usagelog.DefaultCacheCreationCost holds the default value on creation for the cache_creation_cost field.
usagelog
.
DefaultCacheCreationCost
=
usagelogDescCacheCreationCost
.
Default
.
(
float64
)
usagelog
.
DefaultCacheCreationCost
=
usagelogDescCacheCreationCost
.
Default
.
(
float64
)
// usagelogDescCacheReadCost is the schema descriptor for cache_read_cost field.
// usagelogDescCacheReadCost is the schema descriptor for cache_read_cost field.
usagelogDescCacheReadCost
:=
usagelogFields
[
1
6
]
.
Descriptor
()
usagelogDescCacheReadCost
:=
usagelogFields
[
1
7
]
.
Descriptor
()
// usagelog.DefaultCacheReadCost holds the default value on creation for the cache_read_cost field.
// usagelog.DefaultCacheReadCost holds the default value on creation for the cache_read_cost field.
usagelog
.
DefaultCacheReadCost
=
usagelogDescCacheReadCost
.
Default
.
(
float64
)
usagelog
.
DefaultCacheReadCost
=
usagelogDescCacheReadCost
.
Default
.
(
float64
)
// usagelogDescTotalCost is the schema descriptor for total_cost field.
// usagelogDescTotalCost is the schema descriptor for total_cost field.
usagelogDescTotalCost
:=
usagelogFields
[
1
7
]
.
Descriptor
()
usagelogDescTotalCost
:=
usagelogFields
[
1
8
]
.
Descriptor
()
// usagelog.DefaultTotalCost holds the default value on creation for the total_cost field.
// usagelog.DefaultTotalCost holds the default value on creation for the total_cost field.
usagelog
.
DefaultTotalCost
=
usagelogDescTotalCost
.
Default
.
(
float64
)
usagelog
.
DefaultTotalCost
=
usagelogDescTotalCost
.
Default
.
(
float64
)
// usagelogDescActualCost is the schema descriptor for actual_cost field.
// usagelogDescActualCost is the schema descriptor for actual_cost field.
usagelogDescActualCost
:=
usagelogFields
[
1
8
]
.
Descriptor
()
usagelogDescActualCost
:=
usagelogFields
[
1
9
]
.
Descriptor
()
// usagelog.DefaultActualCost holds the default value on creation for the actual_cost field.
// usagelog.DefaultActualCost holds the default value on creation for the actual_cost field.
usagelog
.
DefaultActualCost
=
usagelogDescActualCost
.
Default
.
(
float64
)
usagelog
.
DefaultActualCost
=
usagelogDescActualCost
.
Default
.
(
float64
)
// usagelogDescRateMultiplier is the schema descriptor for rate_multiplier field.
// usagelogDescRateMultiplier is the schema descriptor for rate_multiplier field.
usagelogDescRateMultiplier
:=
usagelogFields
[
19
]
.
Descriptor
()
usagelogDescRateMultiplier
:=
usagelogFields
[
20
]
.
Descriptor
()
// usagelog.DefaultRateMultiplier holds the default value on creation for the rate_multiplier field.
// usagelog.DefaultRateMultiplier holds the default value on creation for the rate_multiplier field.
usagelog
.
DefaultRateMultiplier
=
usagelogDescRateMultiplier
.
Default
.
(
float64
)
usagelog
.
DefaultRateMultiplier
=
usagelogDescRateMultiplier
.
Default
.
(
float64
)
// usagelogDescBillingType is the schema descriptor for billing_type field.
// usagelogDescBillingType is the schema descriptor for billing_type field.
usagelogDescBillingType
:=
usagelogFields
[
2
1
]
.
Descriptor
()
usagelogDescBillingType
:=
usagelogFields
[
2
2
]
.
Descriptor
()
// usagelog.DefaultBillingType holds the default value on creation for the billing_type field.
// usagelog.DefaultBillingType holds the default value on creation for the billing_type field.
usagelog
.
DefaultBillingType
=
usagelogDescBillingType
.
Default
.
(
int8
)
usagelog
.
DefaultBillingType
=
usagelogDescBillingType
.
Default
.
(
int8
)
// usagelogDescStream is the schema descriptor for stream field.
// usagelogDescStream is the schema descriptor for stream field.
usagelogDescStream
:=
usagelogFields
[
2
2
]
.
Descriptor
()
usagelogDescStream
:=
usagelogFields
[
2
3
]
.
Descriptor
()
// usagelog.DefaultStream holds the default value on creation for the stream field.
// usagelog.DefaultStream holds the default value on creation for the stream field.
usagelog
.
DefaultStream
=
usagelogDescStream
.
Default
.
(
bool
)
usagelog
.
DefaultStream
=
usagelogDescStream
.
Default
.
(
bool
)
// usagelogDescUserAgent is the schema descriptor for user_agent field.
// usagelogDescUserAgent is the schema descriptor for user_agent field.
usagelogDescUserAgent
:=
usagelogFields
[
2
5
]
.
Descriptor
()
usagelogDescUserAgent
:=
usagelogFields
[
2
6
]
.
Descriptor
()
// usagelog.UserAgentValidator is a validator for the "user_agent" field. It is called by the builders before save.
// usagelog.UserAgentValidator is a validator for the "user_agent" field. It is called by the builders before save.
usagelog
.
UserAgentValidator
=
usagelogDescUserAgent
.
Validators
[
0
]
.
(
func
(
string
)
error
)
usagelog
.
UserAgentValidator
=
usagelogDescUserAgent
.
Validators
[
0
]
.
(
func
(
string
)
error
)
// usagelogDescIPAddress is the schema descriptor for ip_address field.
// usagelogDescIPAddress is the schema descriptor for ip_address field.
usagelogDescIPAddress
:=
usagelogFields
[
2
6
]
.
Descriptor
()
usagelogDescIPAddress
:=
usagelogFields
[
2
7
]
.
Descriptor
()
// usagelog.IPAddressValidator is a validator for the "ip_address" field. It is called by the builders before save.
// usagelog.IPAddressValidator is a validator for the "ip_address" field. It is called by the builders before save.
usagelog
.
IPAddressValidator
=
usagelogDescIPAddress
.
Validators
[
0
]
.
(
func
(
string
)
error
)
usagelog
.
IPAddressValidator
=
usagelogDescIPAddress
.
Validators
[
0
]
.
(
func
(
string
)
error
)
// usagelogDescImageCount is the schema descriptor for image_count field.
// usagelogDescImageCount is the schema descriptor for image_count field.
usagelogDescImageCount
:=
usagelogFields
[
2
7
]
.
Descriptor
()
usagelogDescImageCount
:=
usagelogFields
[
2
8
]
.
Descriptor
()
// usagelog.DefaultImageCount holds the default value on creation for the image_count field.
// usagelog.DefaultImageCount holds the default value on creation for the image_count field.
usagelog
.
DefaultImageCount
=
usagelogDescImageCount
.
Default
.
(
int
)
usagelog
.
DefaultImageCount
=
usagelogDescImageCount
.
Default
.
(
int
)
// usagelogDescImageSize is the schema descriptor for image_size field.
// usagelogDescImageSize is the schema descriptor for image_size field.
usagelogDescImageSize
:=
usagelogFields
[
2
8
]
.
Descriptor
()
usagelogDescImageSize
:=
usagelogFields
[
2
9
]
.
Descriptor
()
// usagelog.ImageSizeValidator is a validator for the "image_size" field. It is called by the builders before save.
// usagelog.ImageSizeValidator is a validator for the "image_size" field. It is called by the builders before save.
usagelog
.
ImageSizeValidator
=
usagelogDescImageSize
.
Validators
[
0
]
.
(
func
(
string
)
error
)
usagelog
.
ImageSizeValidator
=
usagelogDescImageSize
.
Validators
[
0
]
.
(
func
(
string
)
error
)
// usagelogDescMediaType is the schema descriptor for media_type field.
// usagelogDescMediaType is the schema descriptor for media_type field.
usagelogDescMediaType
:=
usagelogFields
[
29
]
.
Descriptor
()
usagelogDescMediaType
:=
usagelogFields
[
30
]
.
Descriptor
()
// usagelog.MediaTypeValidator is a validator for the "media_type" field. It is called by the builders before save.
// usagelog.MediaTypeValidator is a validator for the "media_type" field. It is called by the builders before save.
usagelog
.
MediaTypeValidator
=
usagelogDescMediaType
.
Validators
[
0
]
.
(
func
(
string
)
error
)
usagelog
.
MediaTypeValidator
=
usagelogDescMediaType
.
Validators
[
0
]
.
(
func
(
string
)
error
)
// usagelogDescCacheTTLOverridden is the schema descriptor for cache_ttl_overridden field.
// usagelogDescCacheTTLOverridden is the schema descriptor for cache_ttl_overridden field.
usagelogDescCacheTTLOverridden
:=
usagelogFields
[
3
0
]
.
Descriptor
()
usagelogDescCacheTTLOverridden
:=
usagelogFields
[
3
1
]
.
Descriptor
()
// usagelog.DefaultCacheTTLOverridden holds the default value on creation for the cache_ttl_overridden field.
// usagelog.DefaultCacheTTLOverridden holds the default value on creation for the cache_ttl_overridden field.
usagelog
.
DefaultCacheTTLOverridden
=
usagelogDescCacheTTLOverridden
.
Default
.
(
bool
)
usagelog
.
DefaultCacheTTLOverridden
=
usagelogDescCacheTTLOverridden
.
Default
.
(
bool
)
// usagelogDescCreatedAt is the schema descriptor for created_at field.
// usagelogDescCreatedAt is the schema descriptor for created_at field.
usagelogDescCreatedAt
:=
usagelogFields
[
3
1
]
.
Descriptor
()
usagelogDescCreatedAt
:=
usagelogFields
[
3
2
]
.
Descriptor
()
// usagelog.DefaultCreatedAt holds the default value on creation for the created_at field.
// usagelog.DefaultCreatedAt holds the default value on creation for the created_at field.
usagelog
.
DefaultCreatedAt
=
usagelogDescCreatedAt
.
Default
.
(
func
()
time
.
Time
)
usagelog
.
DefaultCreatedAt
=
usagelogDescCreatedAt
.
Default
.
(
func
()
time
.
Time
)
userMixin
:=
schema
.
User
{}
.
Mixin
()
userMixin
:=
schema
.
User
{}
.
Mixin
()
...
...
backend/ent/schema/usage_log.go
View file @
1de18b89
...
@@ -41,6 +41,12 @@ func (UsageLog) Fields() []ent.Field {
...
@@ -41,6 +41,12 @@ func (UsageLog) Fields() []ent.Field {
field
.
String
(
"model"
)
.
field
.
String
(
"model"
)
.
MaxLen
(
100
)
.
MaxLen
(
100
)
.
NotEmpty
(),
NotEmpty
(),
// UpstreamModel stores the actual upstream model name when model mapping
// is applied. NULL means no mapping — the requested model was used as-is.
field
.
String
(
"upstream_model"
)
.
MaxLen
(
100
)
.
Optional
()
.
Nillable
(),
field
.
Int64
(
"group_id"
)
.
field
.
Int64
(
"group_id"
)
.
Optional
()
.
Optional
()
.
Nillable
(),
Nillable
(),
...
...
backend/ent/usagelog.go
View file @
1de18b89
...
@@ -32,6 +32,8 @@ type UsageLog struct {
...
@@ -32,6 +32,8 @@ type UsageLog struct {
RequestID
string
`json:"request_id,omitempty"`
RequestID
string
`json:"request_id,omitempty"`
// Model holds the value of the "model" field.
// Model holds the value of the "model" field.
Model
string
`json:"model,omitempty"`
Model
string
`json:"model,omitempty"`
// UpstreamModel holds the value of the "upstream_model" field.
UpstreamModel
*
string
`json:"upstream_model,omitempty"`
// GroupID holds the value of the "group_id" field.
// GroupID holds the value of the "group_id" field.
GroupID
*
int64
`json:"group_id,omitempty"`
GroupID
*
int64
`json:"group_id,omitempty"`
// SubscriptionID holds the value of the "subscription_id" field.
// SubscriptionID holds the value of the "subscription_id" field.
...
@@ -175,7 +177,7 @@ func (*UsageLog) scanValues(columns []string) ([]any, error) {
...
@@ -175,7 +177,7 @@ func (*UsageLog) scanValues(columns []string) ([]any, error) {
values
[
i
]
=
new
(
sql
.
NullFloat64
)
values
[
i
]
=
new
(
sql
.
NullFloat64
)
case
usagelog
.
FieldID
,
usagelog
.
FieldUserID
,
usagelog
.
FieldAPIKeyID
,
usagelog
.
FieldAccountID
,
usagelog
.
FieldGroupID
,
usagelog
.
FieldSubscriptionID
,
usagelog
.
FieldInputTokens
,
usagelog
.
FieldOutputTokens
,
usagelog
.
FieldCacheCreationTokens
,
usagelog
.
FieldCacheReadTokens
,
usagelog
.
FieldCacheCreation5mTokens
,
usagelog
.
FieldCacheCreation1hTokens
,
usagelog
.
FieldBillingType
,
usagelog
.
FieldDurationMs
,
usagelog
.
FieldFirstTokenMs
,
usagelog
.
FieldImageCount
:
case
usagelog
.
FieldID
,
usagelog
.
FieldUserID
,
usagelog
.
FieldAPIKeyID
,
usagelog
.
FieldAccountID
,
usagelog
.
FieldGroupID
,
usagelog
.
FieldSubscriptionID
,
usagelog
.
FieldInputTokens
,
usagelog
.
FieldOutputTokens
,
usagelog
.
FieldCacheCreationTokens
,
usagelog
.
FieldCacheReadTokens
,
usagelog
.
FieldCacheCreation5mTokens
,
usagelog
.
FieldCacheCreation1hTokens
,
usagelog
.
FieldBillingType
,
usagelog
.
FieldDurationMs
,
usagelog
.
FieldFirstTokenMs
,
usagelog
.
FieldImageCount
:
values
[
i
]
=
new
(
sql
.
NullInt64
)
values
[
i
]
=
new
(
sql
.
NullInt64
)
case
usagelog
.
FieldRequestID
,
usagelog
.
FieldModel
,
usagelog
.
FieldUserAgent
,
usagelog
.
FieldIPAddress
,
usagelog
.
FieldImageSize
,
usagelog
.
FieldMediaType
:
case
usagelog
.
FieldRequestID
,
usagelog
.
FieldModel
,
usagelog
.
FieldUpstreamModel
,
usagelog
.
FieldUserAgent
,
usagelog
.
FieldIPAddress
,
usagelog
.
FieldImageSize
,
usagelog
.
FieldMediaType
:
values
[
i
]
=
new
(
sql
.
NullString
)
values
[
i
]
=
new
(
sql
.
NullString
)
case
usagelog
.
FieldCreatedAt
:
case
usagelog
.
FieldCreatedAt
:
values
[
i
]
=
new
(
sql
.
NullTime
)
values
[
i
]
=
new
(
sql
.
NullTime
)
...
@@ -230,6 +232,13 @@ func (_m *UsageLog) assignValues(columns []string, values []any) error {
...
@@ -230,6 +232,13 @@ func (_m *UsageLog) assignValues(columns []string, values []any) error {
}
else
if
value
.
Valid
{
}
else
if
value
.
Valid
{
_m
.
Model
=
value
.
String
_m
.
Model
=
value
.
String
}
}
case
usagelog
.
FieldUpstreamModel
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullString
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field upstream_model"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
UpstreamModel
=
new
(
string
)
*
_m
.
UpstreamModel
=
value
.
String
}
case
usagelog
.
FieldGroupID
:
case
usagelog
.
FieldGroupID
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullInt64
);
!
ok
{
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullInt64
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field group_id"
,
values
[
i
])
return
fmt
.
Errorf
(
"unexpected type %T for field group_id"
,
values
[
i
])
...
@@ -477,6 +486,11 @@ func (_m *UsageLog) String() string {
...
@@ -477,6 +486,11 @@ func (_m *UsageLog) String() string {
builder
.
WriteString
(
"model="
)
builder
.
WriteString
(
"model="
)
builder
.
WriteString
(
_m
.
Model
)
builder
.
WriteString
(
_m
.
Model
)
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
UpstreamModel
;
v
!=
nil
{
builder
.
WriteString
(
"upstream_model="
)
builder
.
WriteString
(
*
v
)
}
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
GroupID
;
v
!=
nil
{
if
v
:=
_m
.
GroupID
;
v
!=
nil
{
builder
.
WriteString
(
"group_id="
)
builder
.
WriteString
(
"group_id="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
*
v
))
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
*
v
))
...
...
backend/ent/usagelog/usagelog.go
View file @
1de18b89
...
@@ -24,6 +24,8 @@ const (
...
@@ -24,6 +24,8 @@ const (
FieldRequestID
=
"request_id"
FieldRequestID
=
"request_id"
// FieldModel holds the string denoting the model field in the database.
// FieldModel holds the string denoting the model field in the database.
FieldModel
=
"model"
FieldModel
=
"model"
// FieldUpstreamModel holds the string denoting the upstream_model field in the database.
FieldUpstreamModel
=
"upstream_model"
// FieldGroupID holds the string denoting the group_id field in the database.
// FieldGroupID holds the string denoting the group_id field in the database.
FieldGroupID
=
"group_id"
FieldGroupID
=
"group_id"
// FieldSubscriptionID holds the string denoting the subscription_id field in the database.
// FieldSubscriptionID holds the string denoting the subscription_id field in the database.
...
@@ -135,6 +137,7 @@ var Columns = []string{
...
@@ -135,6 +137,7 @@ var Columns = []string{
FieldAccountID
,
FieldAccountID
,
FieldRequestID
,
FieldRequestID
,
FieldModel
,
FieldModel
,
FieldUpstreamModel
,
FieldGroupID
,
FieldGroupID
,
FieldSubscriptionID
,
FieldSubscriptionID
,
FieldInputTokens
,
FieldInputTokens
,
...
@@ -179,6 +182,8 @@ var (
...
@@ -179,6 +182,8 @@ var (
RequestIDValidator
func
(
string
)
error
RequestIDValidator
func
(
string
)
error
// ModelValidator is a validator for the "model" field. It is called by the builders before save.
// ModelValidator is a validator for the "model" field. It is called by the builders before save.
ModelValidator
func
(
string
)
error
ModelValidator
func
(
string
)
error
// UpstreamModelValidator is a validator for the "upstream_model" field. It is called by the builders before save.
UpstreamModelValidator
func
(
string
)
error
// DefaultInputTokens holds the default value on creation for the "input_tokens" field.
// DefaultInputTokens holds the default value on creation for the "input_tokens" field.
DefaultInputTokens
int
DefaultInputTokens
int
// DefaultOutputTokens holds the default value on creation for the "output_tokens" field.
// DefaultOutputTokens holds the default value on creation for the "output_tokens" field.
...
@@ -258,6 +263,11 @@ func ByModel(opts ...sql.OrderTermOption) OrderOption {
...
@@ -258,6 +263,11 @@ func ByModel(opts ...sql.OrderTermOption) OrderOption {
return
sql
.
OrderByField
(
FieldModel
,
opts
...
)
.
ToFunc
()
return
sql
.
OrderByField
(
FieldModel
,
opts
...
)
.
ToFunc
()
}
}
// ByUpstreamModel orders the results by the upstream_model field.
func
ByUpstreamModel
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldUpstreamModel
,
opts
...
)
.
ToFunc
()
}
// ByGroupID orders the results by the group_id field.
// ByGroupID orders the results by the group_id field.
func
ByGroupID
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
func
ByGroupID
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldGroupID
,
opts
...
)
.
ToFunc
()
return
sql
.
OrderByField
(
FieldGroupID
,
opts
...
)
.
ToFunc
()
...
...
backend/ent/usagelog/where.go
View file @
1de18b89
...
@@ -80,6 +80,11 @@ func Model(v string) predicate.UsageLog {
...
@@ -80,6 +80,11 @@ func Model(v string) predicate.UsageLog {
return
predicate
.
UsageLog
(
sql
.
FieldEQ
(
FieldModel
,
v
))
return
predicate
.
UsageLog
(
sql
.
FieldEQ
(
FieldModel
,
v
))
}
}
// UpstreamModel applies equality check predicate on the "upstream_model" field. It's identical to UpstreamModelEQ.
func
UpstreamModel
(
v
string
)
predicate
.
UsageLog
{
return
predicate
.
UsageLog
(
sql
.
FieldEQ
(
FieldUpstreamModel
,
v
))
}
// GroupID applies equality check predicate on the "group_id" field. It's identical to GroupIDEQ.
// GroupID applies equality check predicate on the "group_id" field. It's identical to GroupIDEQ.
func
GroupID
(
v
int64
)
predicate
.
UsageLog
{
func
GroupID
(
v
int64
)
predicate
.
UsageLog
{
return
predicate
.
UsageLog
(
sql
.
FieldEQ
(
FieldGroupID
,
v
))
return
predicate
.
UsageLog
(
sql
.
FieldEQ
(
FieldGroupID
,
v
))
...
@@ -405,6 +410,81 @@ func ModelContainsFold(v string) predicate.UsageLog {
...
@@ -405,6 +410,81 @@ func ModelContainsFold(v string) predicate.UsageLog {
return
predicate
.
UsageLog
(
sql
.
FieldContainsFold
(
FieldModel
,
v
))
return
predicate
.
UsageLog
(
sql
.
FieldContainsFold
(
FieldModel
,
v
))
}
}
// UpstreamModelEQ applies the EQ predicate on the "upstream_model" field.
func
UpstreamModelEQ
(
v
string
)
predicate
.
UsageLog
{
return
predicate
.
UsageLog
(
sql
.
FieldEQ
(
FieldUpstreamModel
,
v
))
}
// UpstreamModelNEQ applies the NEQ predicate on the "upstream_model" field.
func
UpstreamModelNEQ
(
v
string
)
predicate
.
UsageLog
{
return
predicate
.
UsageLog
(
sql
.
FieldNEQ
(
FieldUpstreamModel
,
v
))
}
// UpstreamModelIn applies the In predicate on the "upstream_model" field.
func
UpstreamModelIn
(
vs
...
string
)
predicate
.
UsageLog
{
return
predicate
.
UsageLog
(
sql
.
FieldIn
(
FieldUpstreamModel
,
vs
...
))
}
// UpstreamModelNotIn applies the NotIn predicate on the "upstream_model" field.
func
UpstreamModelNotIn
(
vs
...
string
)
predicate
.
UsageLog
{
return
predicate
.
UsageLog
(
sql
.
FieldNotIn
(
FieldUpstreamModel
,
vs
...
))
}
// UpstreamModelGT applies the GT predicate on the "upstream_model" field.
func
UpstreamModelGT
(
v
string
)
predicate
.
UsageLog
{
return
predicate
.
UsageLog
(
sql
.
FieldGT
(
FieldUpstreamModel
,
v
))
}
// UpstreamModelGTE applies the GTE predicate on the "upstream_model" field.
func
UpstreamModelGTE
(
v
string
)
predicate
.
UsageLog
{
return
predicate
.
UsageLog
(
sql
.
FieldGTE
(
FieldUpstreamModel
,
v
))
}
// UpstreamModelLT applies the LT predicate on the "upstream_model" field.
func
UpstreamModelLT
(
v
string
)
predicate
.
UsageLog
{
return
predicate
.
UsageLog
(
sql
.
FieldLT
(
FieldUpstreamModel
,
v
))
}
// UpstreamModelLTE applies the LTE predicate on the "upstream_model" field.
func
UpstreamModelLTE
(
v
string
)
predicate
.
UsageLog
{
return
predicate
.
UsageLog
(
sql
.
FieldLTE
(
FieldUpstreamModel
,
v
))
}
// UpstreamModelContains applies the Contains predicate on the "upstream_model" field.
func
UpstreamModelContains
(
v
string
)
predicate
.
UsageLog
{
return
predicate
.
UsageLog
(
sql
.
FieldContains
(
FieldUpstreamModel
,
v
))
}
// UpstreamModelHasPrefix applies the HasPrefix predicate on the "upstream_model" field.
func
UpstreamModelHasPrefix
(
v
string
)
predicate
.
UsageLog
{
return
predicate
.
UsageLog
(
sql
.
FieldHasPrefix
(
FieldUpstreamModel
,
v
))
}
// UpstreamModelHasSuffix applies the HasSuffix predicate on the "upstream_model" field.
func
UpstreamModelHasSuffix
(
v
string
)
predicate
.
UsageLog
{
return
predicate
.
UsageLog
(
sql
.
FieldHasSuffix
(
FieldUpstreamModel
,
v
))
}
// UpstreamModelIsNil applies the IsNil predicate on the "upstream_model" field.
func
UpstreamModelIsNil
()
predicate
.
UsageLog
{
return
predicate
.
UsageLog
(
sql
.
FieldIsNull
(
FieldUpstreamModel
))
}
// UpstreamModelNotNil applies the NotNil predicate on the "upstream_model" field.
func
UpstreamModelNotNil
()
predicate
.
UsageLog
{
return
predicate
.
UsageLog
(
sql
.
FieldNotNull
(
FieldUpstreamModel
))
}
// UpstreamModelEqualFold applies the EqualFold predicate on the "upstream_model" field.
func
UpstreamModelEqualFold
(
v
string
)
predicate
.
UsageLog
{
return
predicate
.
UsageLog
(
sql
.
FieldEqualFold
(
FieldUpstreamModel
,
v
))
}
// UpstreamModelContainsFold applies the ContainsFold predicate on the "upstream_model" field.
func
UpstreamModelContainsFold
(
v
string
)
predicate
.
UsageLog
{
return
predicate
.
UsageLog
(
sql
.
FieldContainsFold
(
FieldUpstreamModel
,
v
))
}
// GroupIDEQ applies the EQ predicate on the "group_id" field.
// GroupIDEQ applies the EQ predicate on the "group_id" field.
func
GroupIDEQ
(
v
int64
)
predicate
.
UsageLog
{
func
GroupIDEQ
(
v
int64
)
predicate
.
UsageLog
{
return
predicate
.
UsageLog
(
sql
.
FieldEQ
(
FieldGroupID
,
v
))
return
predicate
.
UsageLog
(
sql
.
FieldEQ
(
FieldGroupID
,
v
))
...
...
backend/ent/usagelog_create.go
View file @
1de18b89
...
@@ -57,6 +57,20 @@ func (_c *UsageLogCreate) SetModel(v string) *UsageLogCreate {
...
@@ -57,6 +57,20 @@ func (_c *UsageLogCreate) SetModel(v string) *UsageLogCreate {
return
_c
return
_c
}
}
// SetUpstreamModel sets the "upstream_model" field.
func
(
_c
*
UsageLogCreate
)
SetUpstreamModel
(
v
string
)
*
UsageLogCreate
{
_c
.
mutation
.
SetUpstreamModel
(
v
)
return
_c
}
// SetNillableUpstreamModel sets the "upstream_model" field if the given value is not nil.
func
(
_c
*
UsageLogCreate
)
SetNillableUpstreamModel
(
v
*
string
)
*
UsageLogCreate
{
if
v
!=
nil
{
_c
.
SetUpstreamModel
(
*
v
)
}
return
_c
}
// SetGroupID sets the "group_id" field.
// SetGroupID sets the "group_id" field.
func
(
_c
*
UsageLogCreate
)
SetGroupID
(
v
int64
)
*
UsageLogCreate
{
func
(
_c
*
UsageLogCreate
)
SetGroupID
(
v
int64
)
*
UsageLogCreate
{
_c
.
mutation
.
SetGroupID
(
v
)
_c
.
mutation
.
SetGroupID
(
v
)
...
@@ -596,6 +610,11 @@ func (_c *UsageLogCreate) check() error {
...
@@ -596,6 +610,11 @@ func (_c *UsageLogCreate) check() error {
return
&
ValidationError
{
Name
:
"model"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "UsageLog.model": %w`
,
err
)}
return
&
ValidationError
{
Name
:
"model"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "UsageLog.model": %w`
,
err
)}
}
}
}
}
if
v
,
ok
:=
_c
.
mutation
.
UpstreamModel
();
ok
{
if
err
:=
usagelog
.
UpstreamModelValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"upstream_model"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "UsageLog.upstream_model": %w`
,
err
)}
}
}
if
_
,
ok
:=
_c
.
mutation
.
InputTokens
();
!
ok
{
if
_
,
ok
:=
_c
.
mutation
.
InputTokens
();
!
ok
{
return
&
ValidationError
{
Name
:
"input_tokens"
,
err
:
errors
.
New
(
`ent: missing required field "UsageLog.input_tokens"`
)}
return
&
ValidationError
{
Name
:
"input_tokens"
,
err
:
errors
.
New
(
`ent: missing required field "UsageLog.input_tokens"`
)}
}
}
...
@@ -714,6 +733,10 @@ func (_c *UsageLogCreate) createSpec() (*UsageLog, *sqlgraph.CreateSpec) {
...
@@ -714,6 +733,10 @@ func (_c *UsageLogCreate) createSpec() (*UsageLog, *sqlgraph.CreateSpec) {
_spec
.
SetField
(
usagelog
.
FieldModel
,
field
.
TypeString
,
value
)
_spec
.
SetField
(
usagelog
.
FieldModel
,
field
.
TypeString
,
value
)
_node
.
Model
=
value
_node
.
Model
=
value
}
}
if
value
,
ok
:=
_c
.
mutation
.
UpstreamModel
();
ok
{
_spec
.
SetField
(
usagelog
.
FieldUpstreamModel
,
field
.
TypeString
,
value
)
_node
.
UpstreamModel
=
&
value
}
if
value
,
ok
:=
_c
.
mutation
.
InputTokens
();
ok
{
if
value
,
ok
:=
_c
.
mutation
.
InputTokens
();
ok
{
_spec
.
SetField
(
usagelog
.
FieldInputTokens
,
field
.
TypeInt
,
value
)
_spec
.
SetField
(
usagelog
.
FieldInputTokens
,
field
.
TypeInt
,
value
)
_node
.
InputTokens
=
value
_node
.
InputTokens
=
value
...
@@ -1011,6 +1034,24 @@ func (u *UsageLogUpsert) UpdateModel() *UsageLogUpsert {
...
@@ -1011,6 +1034,24 @@ func (u *UsageLogUpsert) UpdateModel() *UsageLogUpsert {
return
u
return
u
}
}
// SetUpstreamModel sets the "upstream_model" field.
func
(
u
*
UsageLogUpsert
)
SetUpstreamModel
(
v
string
)
*
UsageLogUpsert
{
u
.
Set
(
usagelog
.
FieldUpstreamModel
,
v
)
return
u
}
// UpdateUpstreamModel sets the "upstream_model" field to the value that was provided on create.
func
(
u
*
UsageLogUpsert
)
UpdateUpstreamModel
()
*
UsageLogUpsert
{
u
.
SetExcluded
(
usagelog
.
FieldUpstreamModel
)
return
u
}
// ClearUpstreamModel clears the value of the "upstream_model" field.
func
(
u
*
UsageLogUpsert
)
ClearUpstreamModel
()
*
UsageLogUpsert
{
u
.
SetNull
(
usagelog
.
FieldUpstreamModel
)
return
u
}
// SetGroupID sets the "group_id" field.
// SetGroupID sets the "group_id" field.
func
(
u
*
UsageLogUpsert
)
SetGroupID
(
v
int64
)
*
UsageLogUpsert
{
func
(
u
*
UsageLogUpsert
)
SetGroupID
(
v
int64
)
*
UsageLogUpsert
{
u
.
Set
(
usagelog
.
FieldGroupID
,
v
)
u
.
Set
(
usagelog
.
FieldGroupID
,
v
)
...
@@ -1600,6 +1641,27 @@ func (u *UsageLogUpsertOne) UpdateModel() *UsageLogUpsertOne {
...
@@ -1600,6 +1641,27 @@ func (u *UsageLogUpsertOne) UpdateModel() *UsageLogUpsertOne {
})
})
}
}
// SetUpstreamModel sets the "upstream_model" field.
func
(
u
*
UsageLogUpsertOne
)
SetUpstreamModel
(
v
string
)
*
UsageLogUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageLogUpsert
)
{
s
.
SetUpstreamModel
(
v
)
})
}
// UpdateUpstreamModel sets the "upstream_model" field to the value that was provided on create.
func
(
u
*
UsageLogUpsertOne
)
UpdateUpstreamModel
()
*
UsageLogUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageLogUpsert
)
{
s
.
UpdateUpstreamModel
()
})
}
// ClearUpstreamModel clears the value of the "upstream_model" field.
func
(
u
*
UsageLogUpsertOne
)
ClearUpstreamModel
()
*
UsageLogUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageLogUpsert
)
{
s
.
ClearUpstreamModel
()
})
}
// SetGroupID sets the "group_id" field.
// SetGroupID sets the "group_id" field.
func
(
u
*
UsageLogUpsertOne
)
SetGroupID
(
v
int64
)
*
UsageLogUpsertOne
{
func
(
u
*
UsageLogUpsertOne
)
SetGroupID
(
v
int64
)
*
UsageLogUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageLogUpsert
)
{
return
u
.
Update
(
func
(
s
*
UsageLogUpsert
)
{
...
@@ -2434,6 +2496,27 @@ func (u *UsageLogUpsertBulk) UpdateModel() *UsageLogUpsertBulk {
...
@@ -2434,6 +2496,27 @@ func (u *UsageLogUpsertBulk) UpdateModel() *UsageLogUpsertBulk {
})
})
}
}
// SetUpstreamModel sets the "upstream_model" field.
func
(
u
*
UsageLogUpsertBulk
)
SetUpstreamModel
(
v
string
)
*
UsageLogUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageLogUpsert
)
{
s
.
SetUpstreamModel
(
v
)
})
}
// UpdateUpstreamModel sets the "upstream_model" field to the value that was provided on create.
func
(
u
*
UsageLogUpsertBulk
)
UpdateUpstreamModel
()
*
UsageLogUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageLogUpsert
)
{
s
.
UpdateUpstreamModel
()
})
}
// ClearUpstreamModel clears the value of the "upstream_model" field.
func
(
u
*
UsageLogUpsertBulk
)
ClearUpstreamModel
()
*
UsageLogUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageLogUpsert
)
{
s
.
ClearUpstreamModel
()
})
}
// SetGroupID sets the "group_id" field.
// SetGroupID sets the "group_id" field.
func
(
u
*
UsageLogUpsertBulk
)
SetGroupID
(
v
int64
)
*
UsageLogUpsertBulk
{
func
(
u
*
UsageLogUpsertBulk
)
SetGroupID
(
v
int64
)
*
UsageLogUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageLogUpsert
)
{
return
u
.
Update
(
func
(
s
*
UsageLogUpsert
)
{
...
...
backend/ent/usagelog_update.go
View file @
1de18b89
...
@@ -102,6 +102,26 @@ func (_u *UsageLogUpdate) SetNillableModel(v *string) *UsageLogUpdate {
...
@@ -102,6 +102,26 @@ func (_u *UsageLogUpdate) SetNillableModel(v *string) *UsageLogUpdate {
return
_u
return
_u
}
}
// SetUpstreamModel sets the "upstream_model" field.
func
(
_u
*
UsageLogUpdate
)
SetUpstreamModel
(
v
string
)
*
UsageLogUpdate
{
_u
.
mutation
.
SetUpstreamModel
(
v
)
return
_u
}
// SetNillableUpstreamModel sets the "upstream_model" field if the given value is not nil.
func
(
_u
*
UsageLogUpdate
)
SetNillableUpstreamModel
(
v
*
string
)
*
UsageLogUpdate
{
if
v
!=
nil
{
_u
.
SetUpstreamModel
(
*
v
)
}
return
_u
}
// ClearUpstreamModel clears the value of the "upstream_model" field.
func
(
_u
*
UsageLogUpdate
)
ClearUpstreamModel
()
*
UsageLogUpdate
{
_u
.
mutation
.
ClearUpstreamModel
()
return
_u
}
// SetGroupID sets the "group_id" field.
// SetGroupID sets the "group_id" field.
func
(
_u
*
UsageLogUpdate
)
SetGroupID
(
v
int64
)
*
UsageLogUpdate
{
func
(
_u
*
UsageLogUpdate
)
SetGroupID
(
v
int64
)
*
UsageLogUpdate
{
_u
.
mutation
.
SetGroupID
(
v
)
_u
.
mutation
.
SetGroupID
(
v
)
...
@@ -745,6 +765,11 @@ func (_u *UsageLogUpdate) check() error {
...
@@ -745,6 +765,11 @@ func (_u *UsageLogUpdate) check() error {
return
&
ValidationError
{
Name
:
"model"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "UsageLog.model": %w`
,
err
)}
return
&
ValidationError
{
Name
:
"model"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "UsageLog.model": %w`
,
err
)}
}
}
}
}
if
v
,
ok
:=
_u
.
mutation
.
UpstreamModel
();
ok
{
if
err
:=
usagelog
.
UpstreamModelValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"upstream_model"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "UsageLog.upstream_model": %w`
,
err
)}
}
}
if
v
,
ok
:=
_u
.
mutation
.
UserAgent
();
ok
{
if
v
,
ok
:=
_u
.
mutation
.
UserAgent
();
ok
{
if
err
:=
usagelog
.
UserAgentValidator
(
v
);
err
!=
nil
{
if
err
:=
usagelog
.
UserAgentValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"user_agent"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "UsageLog.user_agent": %w`
,
err
)}
return
&
ValidationError
{
Name
:
"user_agent"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "UsageLog.user_agent": %w`
,
err
)}
...
@@ -795,6 +820,12 @@ func (_u *UsageLogUpdate) sqlSave(ctx context.Context) (_node int, err error) {
...
@@ -795,6 +820,12 @@ func (_u *UsageLogUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if
value
,
ok
:=
_u
.
mutation
.
Model
();
ok
{
if
value
,
ok
:=
_u
.
mutation
.
Model
();
ok
{
_spec
.
SetField
(
usagelog
.
FieldModel
,
field
.
TypeString
,
value
)
_spec
.
SetField
(
usagelog
.
FieldModel
,
field
.
TypeString
,
value
)
}
}
if
value
,
ok
:=
_u
.
mutation
.
UpstreamModel
();
ok
{
_spec
.
SetField
(
usagelog
.
FieldUpstreamModel
,
field
.
TypeString
,
value
)
}
if
_u
.
mutation
.
UpstreamModelCleared
()
{
_spec
.
ClearField
(
usagelog
.
FieldUpstreamModel
,
field
.
TypeString
)
}
if
value
,
ok
:=
_u
.
mutation
.
InputTokens
();
ok
{
if
value
,
ok
:=
_u
.
mutation
.
InputTokens
();
ok
{
_spec
.
SetField
(
usagelog
.
FieldInputTokens
,
field
.
TypeInt
,
value
)
_spec
.
SetField
(
usagelog
.
FieldInputTokens
,
field
.
TypeInt
,
value
)
}
}
...
@@ -1177,6 +1208,26 @@ func (_u *UsageLogUpdateOne) SetNillableModel(v *string) *UsageLogUpdateOne {
...
@@ -1177,6 +1208,26 @@ func (_u *UsageLogUpdateOne) SetNillableModel(v *string) *UsageLogUpdateOne {
return
_u
return
_u
}
}
// SetUpstreamModel sets the "upstream_model" field.
func
(
_u
*
UsageLogUpdateOne
)
SetUpstreamModel
(
v
string
)
*
UsageLogUpdateOne
{
_u
.
mutation
.
SetUpstreamModel
(
v
)
return
_u
}
// SetNillableUpstreamModel sets the "upstream_model" field if the given value is not nil.
func
(
_u
*
UsageLogUpdateOne
)
SetNillableUpstreamModel
(
v
*
string
)
*
UsageLogUpdateOne
{
if
v
!=
nil
{
_u
.
SetUpstreamModel
(
*
v
)
}
return
_u
}
// ClearUpstreamModel clears the value of the "upstream_model" field.
func
(
_u
*
UsageLogUpdateOne
)
ClearUpstreamModel
()
*
UsageLogUpdateOne
{
_u
.
mutation
.
ClearUpstreamModel
()
return
_u
}
// SetGroupID sets the "group_id" field.
// SetGroupID sets the "group_id" field.
func
(
_u
*
UsageLogUpdateOne
)
SetGroupID
(
v
int64
)
*
UsageLogUpdateOne
{
func
(
_u
*
UsageLogUpdateOne
)
SetGroupID
(
v
int64
)
*
UsageLogUpdateOne
{
_u
.
mutation
.
SetGroupID
(
v
)
_u
.
mutation
.
SetGroupID
(
v
)
...
@@ -1833,6 +1884,11 @@ func (_u *UsageLogUpdateOne) check() error {
...
@@ -1833,6 +1884,11 @@ func (_u *UsageLogUpdateOne) check() error {
return
&
ValidationError
{
Name
:
"model"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "UsageLog.model": %w`
,
err
)}
return
&
ValidationError
{
Name
:
"model"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "UsageLog.model": %w`
,
err
)}
}
}
}
}
if
v
,
ok
:=
_u
.
mutation
.
UpstreamModel
();
ok
{
if
err
:=
usagelog
.
UpstreamModelValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"upstream_model"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "UsageLog.upstream_model": %w`
,
err
)}
}
}
if
v
,
ok
:=
_u
.
mutation
.
UserAgent
();
ok
{
if
v
,
ok
:=
_u
.
mutation
.
UserAgent
();
ok
{
if
err
:=
usagelog
.
UserAgentValidator
(
v
);
err
!=
nil
{
if
err
:=
usagelog
.
UserAgentValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"user_agent"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "UsageLog.user_agent": %w`
,
err
)}
return
&
ValidationError
{
Name
:
"user_agent"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "UsageLog.user_agent": %w`
,
err
)}
...
@@ -1900,6 +1956,12 @@ func (_u *UsageLogUpdateOne) sqlSave(ctx context.Context) (_node *UsageLog, err
...
@@ -1900,6 +1956,12 @@ func (_u *UsageLogUpdateOne) sqlSave(ctx context.Context) (_node *UsageLog, err
if
value
,
ok
:=
_u
.
mutation
.
Model
();
ok
{
if
value
,
ok
:=
_u
.
mutation
.
Model
();
ok
{
_spec
.
SetField
(
usagelog
.
FieldModel
,
field
.
TypeString
,
value
)
_spec
.
SetField
(
usagelog
.
FieldModel
,
field
.
TypeString
,
value
)
}
}
if
value
,
ok
:=
_u
.
mutation
.
UpstreamModel
();
ok
{
_spec
.
SetField
(
usagelog
.
FieldUpstreamModel
,
field
.
TypeString
,
value
)
}
if
_u
.
mutation
.
UpstreamModelCleared
()
{
_spec
.
ClearField
(
usagelog
.
FieldUpstreamModel
,
field
.
TypeString
)
}
if
value
,
ok
:=
_u
.
mutation
.
InputTokens
();
ok
{
if
value
,
ok
:=
_u
.
mutation
.
InputTokens
();
ok
{
_spec
.
SetField
(
usagelog
.
FieldInputTokens
,
field
.
TypeInt
,
value
)
_spec
.
SetField
(
usagelog
.
FieldInputTokens
,
field
.
TypeInt
,
value
)
}
}
...
...
backend/go.sum
View file @
1de18b89
...
@@ -22,8 +22,6 @@ github.com/andybalholm/brotli v1.2.0 h1:ukwgCxwYrmACq68yiUqwIWnGY0cTPox/M94sVwTo
...
@@ -22,8 +22,6 @@ github.com/andybalholm/brotli v1.2.0 h1:ukwgCxwYrmACq68yiUqwIWnGY0cTPox/M94sVwTo
github.com/andybalholm/brotli v1.2.0/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY=
github.com/andybalholm/brotli v1.2.0/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY=
github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY=
github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY=
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
github.com/aws/aws-sdk-go-v2 v1.41.2 h1:LuT2rzqNQsauaGkPK/7813XxcZ3o3yePY0Iy891T2ls=
github.com/aws/aws-sdk-go-v2 v1.41.2/go.mod h1:IvvlAZQXvTXznUPfRVfryiG1fbzE2NGK6m9u39YQ+S4=
github.com/aws/aws-sdk-go-v2 v1.41.3 h1:4kQ/fa22KjDt13QCy1+bYADvdgcxpfH18f0zP542kZA=
github.com/aws/aws-sdk-go-v2 v1.41.3 h1:4kQ/fa22KjDt13QCy1+bYADvdgcxpfH18f0zP542kZA=
github.com/aws/aws-sdk-go-v2 v1.41.3/go.mod h1:mwsPRE8ceUUpiTgF7QmQIJ7lgsKUPQOUl3o72QBrE1o=
github.com/aws/aws-sdk-go-v2 v1.41.3/go.mod h1:mwsPRE8ceUUpiTgF7QmQIJ7lgsKUPQOUl3o72QBrE1o=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.5 h1:zWFmPmgw4sveAYi1mRqG+E/g0461cJ5M4bJ8/nc6d3Q=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.5 h1:zWFmPmgw4sveAYi1mRqG+E/g0461cJ5M4bJ8/nc6d3Q=
...
@@ -60,8 +58,6 @@ github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.15 h1:edCcNp9eGIUDUCrzoCu1jWA
...
@@ -60,8 +58,6 @@ github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.15 h1:edCcNp9eGIUDUCrzoCu1jWA
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.15/go.mod h1:lyRQKED9xWfgkYC/wmmYfv7iVIM68Z5OQ88ZdcV1QbU=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.15/go.mod h1:lyRQKED9xWfgkYC/wmmYfv7iVIM68Z5OQ88ZdcV1QbU=
github.com/aws/aws-sdk-go-v2/service/sts v1.41.7 h1:NITQpgo9A5NrDZ57uOWj+abvXSb83BbyggcUBVksN7c=
github.com/aws/aws-sdk-go-v2/service/sts v1.41.7 h1:NITQpgo9A5NrDZ57uOWj+abvXSb83BbyggcUBVksN7c=
github.com/aws/aws-sdk-go-v2/service/sts v1.41.7/go.mod h1:sks5UWBhEuWYDPdwlnRFn1w7xWdH29Jcpe+/PJQefEs=
github.com/aws/aws-sdk-go-v2/service/sts v1.41.7/go.mod h1:sks5UWBhEuWYDPdwlnRFn1w7xWdH29Jcpe+/PJQefEs=
github.com/aws/smithy-go v1.24.1 h1:VbyeNfmYkWoxMVpGUAbQumkODcYmfMRfZ8yQiH30SK0=
github.com/aws/smithy-go v1.24.1/go.mod h1:LEj2LM3rBRQJxPZTB4KuzZkaZYnZPnvgIhb4pu07mx0=
github.com/aws/smithy-go v1.24.2 h1:FzA3bu/nt/vDvmnkg+R8Xl46gmzEDam6mZ1hzmwXFng=
github.com/aws/smithy-go v1.24.2 h1:FzA3bu/nt/vDvmnkg+R8Xl46gmzEDam6mZ1hzmwXFng=
github.com/aws/smithy-go v1.24.2/go.mod h1:YE2RhdIuDbA5E5bTdciG9KrW3+TiEONeUWCqxX9i1Fc=
github.com/aws/smithy-go v1.24.2/go.mod h1:YE2RhdIuDbA5E5bTdciG9KrW3+TiEONeUWCqxX9i1Fc=
github.com/bdandy/go-errors v1.2.2 h1:WdFv/oukjTJCLa79UfkGmwX7ZxONAihKu4V0mLIs11Q=
github.com/bdandy/go-errors v1.2.2 h1:WdFv/oukjTJCLa79UfkGmwX7ZxONAihKu4V0mLIs11Q=
...
@@ -98,10 +94,6 @@ github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
...
@@ -98,10 +94,6 @@ github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams=
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams=
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
github.com/clipperhouse/stringish v0.1.1 h1:+NSqMOr3GR6k1FdRhhnXrLfztGzuG+VuFDfatpWHKCs=
github.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA=
github.com/clipperhouse/uax29/v2 v2.5.0 h1:x7T0T4eTHDONxFJsL94uKNKPHrclyFI0lm7+w94cO8U=
github.com/clipperhouse/uax29/v2 v2.5.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
github.com/coder/websocket v1.8.14 h1:9L0p0iKiNOibykf283eHkKUHHrpG7f65OE3BhhO7v9g=
github.com/coder/websocket v1.8.14 h1:9L0p0iKiNOibykf283eHkKUHHrpG7f65OE3BhhO7v9g=
github.com/coder/websocket v1.8.14/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg=
github.com/coder/websocket v1.8.14/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg=
github.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG8PI=
github.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG8PI=
...
@@ -238,8 +230,6 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
...
@@ -238,8 +230,6 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw=
github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/mdelapenya/tlscert v0.2.0 h1:7H81W6Z/4weDvZBNOfQte5GpIMo0lGYEeWbkGp5LJHI=
github.com/mdelapenya/tlscert v0.2.0 h1:7H81W6Z/4weDvZBNOfQte5GpIMo0lGYEeWbkGp5LJHI=
...
@@ -273,8 +263,6 @@ github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
...
@@ -273,8 +263,6 @@ github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=
...
@@ -326,8 +314,6 @@ github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
...
@@ -326,8 +314,6 @@ github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ=
github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ=
...
...
backend/internal/domain/constants.go
View file @
1de18b89
...
@@ -82,8 +82,8 @@ var DefaultAntigravityModelMapping = map[string]string{
...
@@ -82,8 +82,8 @@ var DefaultAntigravityModelMapping = map[string]string{
"claude-opus-4-5-20251101"
:
"claude-opus-4-6-thinking"
,
// 迁移旧模型
"claude-opus-4-5-20251101"
:
"claude-opus-4-6-thinking"
,
// 迁移旧模型
"claude-sonnet-4-5-20250929"
:
"claude-sonnet-4-5"
,
"claude-sonnet-4-5-20250929"
:
"claude-sonnet-4-5"
,
// Claude Haiku → Sonnet(无 Haiku 支持)
// Claude Haiku → Sonnet(无 Haiku 支持)
"claude-haiku-4-5"
:
"claude-sonnet-4-
5
"
,
"claude-haiku-4-5"
:
"claude-sonnet-4-
6
"
,
"claude-haiku-4-5-20251001"
:
"claude-sonnet-4-
5
"
,
"claude-haiku-4-5-20251001"
:
"claude-sonnet-4-
6
"
,
// Gemini 2.5 白名单
// Gemini 2.5 白名单
"gemini-2.5-flash"
:
"gemini-2.5-flash"
,
"gemini-2.5-flash"
:
"gemini-2.5-flash"
,
"gemini-2.5-flash-image"
:
"gemini-2.5-flash-image"
,
"gemini-2.5-flash-image"
:
"gemini-2.5-flash-image"
,
...
...
backend/internal/handler/admin/admin_basic_handlers_test.go
View file @
1de18b89
...
@@ -17,7 +17,7 @@ func setupAdminRouter() (*gin.Engine, *stubAdminService) {
...
@@ -17,7 +17,7 @@ func setupAdminRouter() (*gin.Engine, *stubAdminService) {
adminSvc
:=
newStubAdminService
()
adminSvc
:=
newStubAdminService
()
userHandler
:=
NewUserHandler
(
adminSvc
,
nil
)
userHandler
:=
NewUserHandler
(
adminSvc
,
nil
)
groupHandler
:=
NewGroupHandler
(
adminSvc
)
groupHandler
:=
NewGroupHandler
(
adminSvc
,
nil
,
nil
)
proxyHandler
:=
NewProxyHandler
(
adminSvc
)
proxyHandler
:=
NewProxyHandler
(
adminSvc
)
redeemHandler
:=
NewRedeemHandler
(
adminSvc
,
nil
)
redeemHandler
:=
NewRedeemHandler
(
adminSvc
,
nil
)
...
...
backend/internal/handler/admin/dashboard_handler.go
View file @
1de18b89
...
@@ -273,6 +273,7 @@ func (h *DashboardHandler) GetModelStats(c *gin.Context) {
...
@@ -273,6 +273,7 @@ func (h *DashboardHandler) GetModelStats(c *gin.Context) {
// Parse optional filter params
// Parse optional filter params
var
userID
,
apiKeyID
,
accountID
,
groupID
int64
var
userID
,
apiKeyID
,
accountID
,
groupID
int64
modelSource
:=
usagestats
.
ModelSourceRequested
var
requestType
*
int16
var
requestType
*
int16
var
stream
*
bool
var
stream
*
bool
var
billingType
*
int8
var
billingType
*
int8
...
@@ -297,6 +298,13 @@ func (h *DashboardHandler) GetModelStats(c *gin.Context) {
...
@@ -297,6 +298,13 @@ func (h *DashboardHandler) GetModelStats(c *gin.Context) {
groupID
=
id
groupID
=
id
}
}
}
}
if
rawModelSource
:=
strings
.
TrimSpace
(
c
.
Query
(
"model_source"
));
rawModelSource
!=
""
{
if
!
usagestats
.
IsValidModelSource
(
rawModelSource
)
{
response
.
BadRequest
(
c
,
"Invalid model_source, use requested/upstream/mapping"
)
return
}
modelSource
=
rawModelSource
}
if
requestTypeStr
:=
strings
.
TrimSpace
(
c
.
Query
(
"request_type"
));
requestTypeStr
!=
""
{
if
requestTypeStr
:=
strings
.
TrimSpace
(
c
.
Query
(
"request_type"
));
requestTypeStr
!=
""
{
parsed
,
err
:=
service
.
ParseUsageRequestType
(
requestTypeStr
)
parsed
,
err
:=
service
.
ParseUsageRequestType
(
requestTypeStr
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -323,7 +331,7 @@ func (h *DashboardHandler) GetModelStats(c *gin.Context) {
...
@@ -323,7 +331,7 @@ func (h *DashboardHandler) GetModelStats(c *gin.Context) {
}
}
}
}
stats
,
hit
,
err
:=
h
.
getModelStatsCached
(
c
.
Request
.
Context
(),
startTime
,
endTime
,
userID
,
apiKeyID
,
accountID
,
groupID
,
requestType
,
stream
,
billingType
)
stats
,
hit
,
err
:=
h
.
getModelStatsCached
(
c
.
Request
.
Context
(),
startTime
,
endTime
,
userID
,
apiKeyID
,
accountID
,
groupID
,
modelSource
,
requestType
,
stream
,
billingType
)
if
err
!=
nil
{
if
err
!=
nil
{
response
.
Error
(
c
,
500
,
"Failed to get model statistics"
)
response
.
Error
(
c
,
500
,
"Failed to get model statistics"
)
return
return
...
@@ -619,6 +627,12 @@ func (h *DashboardHandler) GetUserBreakdown(c *gin.Context) {
...
@@ -619,6 +627,12 @@ func (h *DashboardHandler) GetUserBreakdown(c *gin.Context) {
}
}
}
}
dim
.
Model
=
c
.
Query
(
"model"
)
dim
.
Model
=
c
.
Query
(
"model"
)
rawModelSource
:=
strings
.
TrimSpace
(
c
.
DefaultQuery
(
"model_source"
,
usagestats
.
ModelSourceRequested
))
if
!
usagestats
.
IsValidModelSource
(
rawModelSource
)
{
response
.
BadRequest
(
c
,
"Invalid model_source, use requested/upstream/mapping"
)
return
}
dim
.
ModelType
=
rawModelSource
dim
.
Endpoint
=
c
.
Query
(
"endpoint"
)
dim
.
Endpoint
=
c
.
Query
(
"endpoint"
)
dim
.
EndpointType
=
c
.
DefaultQuery
(
"endpoint_type"
,
"inbound"
)
dim
.
EndpointType
=
c
.
DefaultQuery
(
"endpoint_type"
,
"inbound"
)
...
...
backend/internal/handler/admin/dashboard_handler_request_type_test.go
View file @
1de18b89
...
@@ -149,6 +149,28 @@ func TestDashboardModelStatsInvalidStream(t *testing.T) {
...
@@ -149,6 +149,28 @@ func TestDashboardModelStatsInvalidStream(t *testing.T) {
require
.
Equal
(
t
,
http
.
StatusBadRequest
,
rec
.
Code
)
require
.
Equal
(
t
,
http
.
StatusBadRequest
,
rec
.
Code
)
}
}
func
TestDashboardModelStatsInvalidModelSource
(
t
*
testing
.
T
)
{
repo
:=
&
dashboardUsageRepoCapture
{}
router
:=
newDashboardRequestTypeTestRouter
(
repo
)
req
:=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/admin/dashboard/models?model_source=invalid"
,
nil
)
rec
:=
httptest
.
NewRecorder
()
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusBadRequest
,
rec
.
Code
)
}
func
TestDashboardModelStatsValidModelSource
(
t
*
testing
.
T
)
{
repo
:=
&
dashboardUsageRepoCapture
{}
router
:=
newDashboardRequestTypeTestRouter
(
repo
)
req
:=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/admin/dashboard/models?model_source=upstream"
,
nil
)
rec
:=
httptest
.
NewRecorder
()
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
}
func
TestDashboardUsersRankingLimitAndCache
(
t
*
testing
.
T
)
{
func
TestDashboardUsersRankingLimitAndCache
(
t
*
testing
.
T
)
{
dashboardUsersRankingCache
=
newSnapshotCache
(
5
*
time
.
Minute
)
dashboardUsersRankingCache
=
newSnapshotCache
(
5
*
time
.
Minute
)
repo
:=
&
dashboardUsageRepoCapture
{
repo
:=
&
dashboardUsageRepoCapture
{
...
...
backend/internal/handler/admin/dashboard_handler_user_breakdown_test.go
View file @
1de18b89
...
@@ -73,9 +73,35 @@ func TestGetUserBreakdown_ModelFilter(t *testing.T) {
...
@@ -73,9 +73,35 @@ func TestGetUserBreakdown_ModelFilter(t *testing.T) {
require
.
Equal
(
t
,
http
.
StatusOK
,
w
.
Code
)
require
.
Equal
(
t
,
http
.
StatusOK
,
w
.
Code
)
require
.
Equal
(
t
,
"claude-opus-4-6"
,
repo
.
capturedDim
.
Model
)
require
.
Equal
(
t
,
"claude-opus-4-6"
,
repo
.
capturedDim
.
Model
)
require
.
Equal
(
t
,
usagestats
.
ModelSourceRequested
,
repo
.
capturedDim
.
ModelType
)
require
.
Equal
(
t
,
int64
(
0
),
repo
.
capturedDim
.
GroupID
)
require
.
Equal
(
t
,
int64
(
0
),
repo
.
capturedDim
.
GroupID
)
}
}
func
TestGetUserBreakdown_ModelSourceFilter
(
t
*
testing
.
T
)
{
repo
:=
&
userBreakdownRepoCapture
{}
router
:=
newUserBreakdownRouter
(
repo
)
req
:=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/admin/dashboard/user-breakdown?start_date=2026-03-01&end_date=2026-03-16&model=claude-opus-4-6&model_source=upstream"
,
nil
)
w
:=
httptest
.
NewRecorder
()
router
.
ServeHTTP
(
w
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
w
.
Code
)
require
.
Equal
(
t
,
usagestats
.
ModelSourceUpstream
,
repo
.
capturedDim
.
ModelType
)
}
func
TestGetUserBreakdown_InvalidModelSource
(
t
*
testing
.
T
)
{
repo
:=
&
userBreakdownRepoCapture
{}
router
:=
newUserBreakdownRouter
(
repo
)
req
:=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/admin/dashboard/user-breakdown?start_date=2026-03-01&end_date=2026-03-16&model_source=foobar"
,
nil
)
w
:=
httptest
.
NewRecorder
()
router
.
ServeHTTP
(
w
,
req
)
require
.
Equal
(
t
,
http
.
StatusBadRequest
,
w
.
Code
)
}
func
TestGetUserBreakdown_EndpointFilter
(
t
*
testing
.
T
)
{
func
TestGetUserBreakdown_EndpointFilter
(
t
*
testing
.
T
)
{
repo
:=
&
userBreakdownRepoCapture
{}
repo
:=
&
userBreakdownRepoCapture
{}
router
:=
newUserBreakdownRouter
(
repo
)
router
:=
newUserBreakdownRouter
(
repo
)
...
...
backend/internal/handler/admin/dashboard_query_cache.go
View file @
1de18b89
...
@@ -38,6 +38,7 @@ type dashboardModelGroupCacheKey struct {
...
@@ -38,6 +38,7 @@ type dashboardModelGroupCacheKey struct {
APIKeyID
int64
`json:"api_key_id"`
APIKeyID
int64
`json:"api_key_id"`
AccountID
int64
`json:"account_id"`
AccountID
int64
`json:"account_id"`
GroupID
int64
`json:"group_id"`
GroupID
int64
`json:"group_id"`
ModelSource
string
`json:"model_source,omitempty"`
RequestType
*
int16
`json:"request_type"`
RequestType
*
int16
`json:"request_type"`
Stream
*
bool
`json:"stream"`
Stream
*
bool
`json:"stream"`
BillingType
*
int8
`json:"billing_type"`
BillingType
*
int8
`json:"billing_type"`
...
@@ -111,6 +112,7 @@ func (h *DashboardHandler) getModelStatsCached(
...
@@ -111,6 +112,7 @@ func (h *DashboardHandler) getModelStatsCached(
ctx
context
.
Context
,
ctx
context
.
Context
,
startTime
,
endTime
time
.
Time
,
startTime
,
endTime
time
.
Time
,
userID
,
apiKeyID
,
accountID
,
groupID
int64
,
userID
,
apiKeyID
,
accountID
,
groupID
int64
,
modelSource
string
,
requestType
*
int16
,
requestType
*
int16
,
stream
*
bool
,
stream
*
bool
,
billingType
*
int8
,
billingType
*
int8
,
...
@@ -122,12 +124,13 @@ func (h *DashboardHandler) getModelStatsCached(
...
@@ -122,12 +124,13 @@ func (h *DashboardHandler) getModelStatsCached(
APIKeyID
:
apiKeyID
,
APIKeyID
:
apiKeyID
,
AccountID
:
accountID
,
AccountID
:
accountID
,
GroupID
:
groupID
,
GroupID
:
groupID
,
ModelSource
:
usagestats
.
NormalizeModelSource
(
modelSource
),
RequestType
:
requestType
,
RequestType
:
requestType
,
Stream
:
stream
,
Stream
:
stream
,
BillingType
:
billingType
,
BillingType
:
billingType
,
})
})
entry
,
hit
,
err
:=
dashboardModelStatsCache
.
GetOrLoad
(
key
,
func
()
(
any
,
error
)
{
entry
,
hit
,
err
:=
dashboardModelStatsCache
.
GetOrLoad
(
key
,
func
()
(
any
,
error
)
{
return
h
.
dashboardService
.
GetModelStatsWithFilters
(
ctx
,
startTime
,
endTime
,
userID
,
apiKeyID
,
accountID
,
groupID
,
requestType
,
stream
,
billingType
)
return
h
.
dashboardService
.
GetModelStatsWithFilters
BySource
(
ctx
,
startTime
,
endTime
,
userID
,
apiKeyID
,
accountID
,
groupID
,
requestType
,
stream
,
billingType
,
modelSource
)
})
})
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
hit
,
err
return
nil
,
hit
,
err
...
...
backend/internal/handler/admin/dashboard_snapshot_v2_handler.go
View file @
1de18b89
...
@@ -200,6 +200,7 @@ func (h *DashboardHandler) buildSnapshotV2Response(
...
@@ -200,6 +200,7 @@ func (h *DashboardHandler) buildSnapshotV2Response(
filters
.
APIKeyID
,
filters
.
APIKeyID
,
filters
.
AccountID
,
filters
.
AccountID
,
filters
.
GroupID
,
filters
.
GroupID
,
usagestats
.
ModelSourceRequested
,
filters
.
RequestType
,
filters
.
RequestType
,
filters
.
Stream
,
filters
.
Stream
,
filters
.
BillingType
,
filters
.
BillingType
,
...
...
backend/internal/handler/admin/group_handler.go
View file @
1de18b89
...
@@ -9,6 +9,7 @@ import (
...
@@ -9,6 +9,7 @@ import (
"github.com/Wei-Shaw/sub2api/internal/handler/dto"
"github.com/Wei-Shaw/sub2api/internal/handler/dto"
"github.com/Wei-Shaw/sub2api/internal/pkg/response"
"github.com/Wei-Shaw/sub2api/internal/pkg/response"
"github.com/Wei-Shaw/sub2api/internal/pkg/timezone"
"github.com/Wei-Shaw/sub2api/internal/service"
"github.com/Wei-Shaw/sub2api/internal/service"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
...
@@ -16,7 +17,9 @@ import (
...
@@ -16,7 +17,9 @@ import (
// GroupHandler handles admin group management
// GroupHandler handles admin group management
type
GroupHandler
struct
{
type
GroupHandler
struct
{
adminService
service
.
AdminService
adminService
service
.
AdminService
dashboardService
*
service
.
DashboardService
groupCapacityService
*
service
.
GroupCapacityService
}
}
type
optionalLimitField
struct
{
type
optionalLimitField
struct
{
...
@@ -69,9 +72,11 @@ func (f optionalLimitField) ToServiceInput() *float64 {
...
@@ -69,9 +72,11 @@ func (f optionalLimitField) ToServiceInput() *float64 {
}
}
// NewGroupHandler creates a new admin group handler
// NewGroupHandler creates a new admin group handler
func
NewGroupHandler
(
adminService
service
.
AdminService
)
*
GroupHandler
{
func
NewGroupHandler
(
adminService
service
.
AdminService
,
dashboardService
*
service
.
DashboardService
,
groupCapacityService
*
service
.
GroupCapacityService
)
*
GroupHandler
{
return
&
GroupHandler
{
return
&
GroupHandler
{
adminService
:
adminService
,
adminService
:
adminService
,
dashboardService
:
dashboardService
,
groupCapacityService
:
groupCapacityService
,
}
}
}
}
...
@@ -363,6 +368,33 @@ func (h *GroupHandler) GetStats(c *gin.Context) {
...
@@ -363,6 +368,33 @@ func (h *GroupHandler) GetStats(c *gin.Context) {
_
=
groupID
// TODO: implement actual stats
_
=
groupID
// TODO: implement actual stats
}
}
// GetUsageSummary returns today's and cumulative cost for all groups.
// GET /api/v1/admin/groups/usage-summary?timezone=Asia/Shanghai
func
(
h
*
GroupHandler
)
GetUsageSummary
(
c
*
gin
.
Context
)
{
userTZ
:=
c
.
Query
(
"timezone"
)
now
:=
timezone
.
NowInUserLocation
(
userTZ
)
todayStart
:=
timezone
.
StartOfDayInUserLocation
(
now
,
userTZ
)
results
,
err
:=
h
.
dashboardService
.
GetGroupUsageSummary
(
c
.
Request
.
Context
(),
todayStart
)
if
err
!=
nil
{
response
.
Error
(
c
,
500
,
"Failed to get group usage summary"
)
return
}
response
.
Success
(
c
,
results
)
}
// GetCapacitySummary returns aggregated capacity (concurrency/sessions/RPM) for all active groups.
// GET /api/v1/admin/groups/capacity-summary
func
(
h
*
GroupHandler
)
GetCapacitySummary
(
c
*
gin
.
Context
)
{
results
,
err
:=
h
.
groupCapacityService
.
GetAllGroupCapacity
(
c
.
Request
.
Context
())
if
err
!=
nil
{
response
.
Error
(
c
,
500
,
"Failed to get group capacity summary"
)
return
}
response
.
Success
(
c
,
results
)
}
// GetGroupAPIKeys handles getting API keys in a group
// GetGroupAPIKeys handles getting API keys in a group
// GET /api/v1/admin/groups/:id/api-keys
// GET /api/v1/admin/groups/:id/api-keys
func
(
h
*
GroupHandler
)
GetGroupAPIKeys
(
c
*
gin
.
Context
)
{
func
(
h
*
GroupHandler
)
GetGroupAPIKeys
(
c
*
gin
.
Context
)
{
...
...
backend/internal/handler/admin/setting_handler.go
View file @
1de18b89
...
@@ -977,6 +977,58 @@ func (h *SettingHandler) DeleteAdminAPIKey(c *gin.Context) {
...
@@ -977,6 +977,58 @@ func (h *SettingHandler) DeleteAdminAPIKey(c *gin.Context) {
response
.
Success
(
c
,
gin
.
H
{
"message"
:
"Admin API key deleted"
})
response
.
Success
(
c
,
gin
.
H
{
"message"
:
"Admin API key deleted"
})
}
}
// GetOverloadCooldownSettings 获取529过载冷却配置
// GET /api/v1/admin/settings/overload-cooldown
func
(
h
*
SettingHandler
)
GetOverloadCooldownSettings
(
c
*
gin
.
Context
)
{
settings
,
err
:=
h
.
settingService
.
GetOverloadCooldownSettings
(
c
.
Request
.
Context
())
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
response
.
Success
(
c
,
dto
.
OverloadCooldownSettings
{
Enabled
:
settings
.
Enabled
,
CooldownMinutes
:
settings
.
CooldownMinutes
,
})
}
// UpdateOverloadCooldownSettingsRequest 更新529过载冷却配置请求
type
UpdateOverloadCooldownSettingsRequest
struct
{
Enabled
bool
`json:"enabled"`
CooldownMinutes
int
`json:"cooldown_minutes"`
}
// UpdateOverloadCooldownSettings 更新529过载冷却配置
// PUT /api/v1/admin/settings/overload-cooldown
func
(
h
*
SettingHandler
)
UpdateOverloadCooldownSettings
(
c
*
gin
.
Context
)
{
var
req
UpdateOverloadCooldownSettingsRequest
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
response
.
BadRequest
(
c
,
"Invalid request: "
+
err
.
Error
())
return
}
settings
:=
&
service
.
OverloadCooldownSettings
{
Enabled
:
req
.
Enabled
,
CooldownMinutes
:
req
.
CooldownMinutes
,
}
if
err
:=
h
.
settingService
.
SetOverloadCooldownSettings
(
c
.
Request
.
Context
(),
settings
);
err
!=
nil
{
response
.
BadRequest
(
c
,
err
.
Error
())
return
}
updatedSettings
,
err
:=
h
.
settingService
.
GetOverloadCooldownSettings
(
c
.
Request
.
Context
())
if
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
return
}
response
.
Success
(
c
,
dto
.
OverloadCooldownSettings
{
Enabled
:
updatedSettings
.
Enabled
,
CooldownMinutes
:
updatedSettings
.
CooldownMinutes
,
})
}
// GetStreamTimeoutSettings 获取流超时处理配置
// GetStreamTimeoutSettings 获取流超时处理配置
// GET /api/v1/admin/settings/stream-timeout
// GET /api/v1/admin/settings/stream-timeout
func
(
h
*
SettingHandler
)
GetStreamTimeoutSettings
(
c
*
gin
.
Context
)
{
func
(
h
*
SettingHandler
)
GetStreamTimeoutSettings
(
c
*
gin
.
Context
)
{
...
...
Prev
1
2
3
4
5
6
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