Merge remote-tracking branch 'pr/2131' into release/v0.1.133
# Conflicts: # backend/cmd/server/wire_gen.go # backend/internal/config/config.go # backend/internal/service/gateway_service.go # backend/internal/service/pricing_service.go # backend/internal/service/wire.go # deploy/config.example.yaml # frontend/src/views/admin/AccountsView.vue
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/Wei-Shaw/sub2api/internal/pkg/claude"
|
||||
infraerrors "github.com/Wei-Shaw/sub2api/internal/pkg/errors"
|
||||
"github.com/Wei-Shaw/sub2api/internal/pkg/geminicli"
|
||||
kiropkg "github.com/Wei-Shaw/sub2api/internal/pkg/kiro"
|
||||
"github.com/Wei-Shaw/sub2api/internal/pkg/openai"
|
||||
"github.com/Wei-Shaw/sub2api/internal/pkg/response"
|
||||
"github.com/Wei-Shaw/sub2api/internal/pkg/timezone"
|
||||
@@ -179,6 +180,9 @@ type AccountWithConcurrency struct {
|
||||
const accountListGroupUngroupedQueryValue = "ungrouped"
|
||||
|
||||
func (h *AccountHandler) buildAccountResponseWithRuntime(ctx context.Context, account *service.Account) AccountWithConcurrency {
|
||||
if h.accountUsageService != nil {
|
||||
h.accountUsageService.EnrichAccountWithKiroRuntimeState(ctx, account)
|
||||
}
|
||||
item := AccountWithConcurrency{
|
||||
Account: dto.AccountFromService(account),
|
||||
CurrentConcurrency: 0,
|
||||
@@ -351,6 +355,9 @@ func (h *AccountHandler) List(c *gin.Context) {
|
||||
result := make([]AccountWithConcurrency, len(accounts))
|
||||
for i := range accounts {
|
||||
acc := &accounts[i]
|
||||
if h.accountUsageService != nil {
|
||||
h.accountUsageService.EnrichAccountWithKiroRuntimeState(c.Request.Context(), acc)
|
||||
}
|
||||
item := AccountWithConcurrency{
|
||||
Account: dto.AccountFromService(acc),
|
||||
CurrentConcurrency: concurrencyCounts[acc.ID],
|
||||
@@ -1953,6 +1960,18 @@ func (h *AccountHandler) GetAvailableModels(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Handle Kiro accounts
|
||||
if account.Platform == service.PlatformKiro {
|
||||
mapping := account.GetModelMapping()
|
||||
if len(mapping) == 0 {
|
||||
response.Success(c, kiropkg.DefaultModels)
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(c, buildMappedKiroModels(mapping))
|
||||
return
|
||||
}
|
||||
|
||||
// Handle Claude/Anthropic accounts
|
||||
// For OAuth and Setup-Token accounts: return default models
|
||||
if account.IsOAuth() {
|
||||
@@ -1994,6 +2013,28 @@ func (h *AccountHandler) GetAvailableModels(c *gin.Context) {
|
||||
response.Success(c, models)
|
||||
}
|
||||
|
||||
func buildMappedKiroModels(mapping map[string]string) []kiropkg.Model {
|
||||
models := make([]kiropkg.Model, 0, len(mapping))
|
||||
for requestedModel := range mapping {
|
||||
var found bool
|
||||
for _, dm := range kiropkg.DefaultModels {
|
||||
if dm.ID == requestedModel {
|
||||
models = append(models, dm)
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
models = append(models, kiropkg.Model{
|
||||
ID: requestedModel,
|
||||
Type: "model",
|
||||
DisplayName: requestedModel,
|
||||
})
|
||||
}
|
||||
}
|
||||
return models
|
||||
}
|
||||
|
||||
// SetPrivacy handles setting privacy for a single OpenAI/Antigravity OAuth account
|
||||
// POST /api/v1/admin/accounts/:id/set-privacy
|
||||
func (h *AccountHandler) SetPrivacy(c *gin.Context) {
|
||||
@@ -2206,6 +2247,12 @@ func (h *AccountHandler) GetAntigravityDefaultModelMapping(c *gin.Context) {
|
||||
response.Success(c, domain.DefaultAntigravityModelMapping)
|
||||
}
|
||||
|
||||
// GetKiroDefaultModelMapping 获取 Kiro 平台的默认模型映射
|
||||
// GET /api/v1/admin/accounts/kiro/default-model-mapping
|
||||
func (h *AccountHandler) GetKiroDefaultModelMapping(c *gin.Context) {
|
||||
response.Success(c, domain.DefaultKiroModelMapping)
|
||||
}
|
||||
|
||||
// sanitizeExtraBaseRPM 对 extra map 中的 base_rpm 值进行范围校验和归一化。
|
||||
// 负值归零,超过 10000 截断为 10000。extra 为 nil 或不含 base_rpm 时无操作。
|
||||
func sanitizeExtraBaseRPM(extra map[string]any) {
|
||||
|
||||
Reference in New Issue
Block a user