feat(backend): add kiro account support
This commit is contained in:
@@ -48,6 +48,13 @@ type Account struct {
|
||||
TempUnschedulableUntil *time.Time
|
||||
TempUnschedulableReason string
|
||||
|
||||
KiroQuotaState string
|
||||
KiroQuotaReason string
|
||||
KiroQuotaResetAt *time.Time
|
||||
KiroRuntimeState string
|
||||
KiroRuntimeReason string
|
||||
KiroRuntimeResetAt *time.Time
|
||||
|
||||
SessionWindowStart *time.Time
|
||||
SessionWindowEnd *time.Time
|
||||
SessionWindowStatus string
|
||||
@@ -164,6 +171,10 @@ func (a *Account) IsGemini() bool {
|
||||
return a.Platform == PlatformGemini
|
||||
}
|
||||
|
||||
func (a *Account) IsKiro() bool {
|
||||
return a.Platform == PlatformKiro
|
||||
}
|
||||
|
||||
func (a *Account) GeminiOAuthType() string {
|
||||
if a.Platform != PlatformGemini || a.Type != AccountTypeOAuth {
|
||||
return ""
|
||||
@@ -478,17 +489,17 @@ func (a *Account) GetModelMapping() map[string]string {
|
||||
|
||||
func (a *Account) resolveModelMapping(rawMapping map[string]any) map[string]string {
|
||||
if a.Credentials == nil {
|
||||
// Antigravity 平台使用默认映射
|
||||
if a.Platform == domain.PlatformAntigravity {
|
||||
return domain.DefaultAntigravityModelMapping
|
||||
// 部分平台在未显式配置 model_mapping 时仍应使用默认映射,
|
||||
// 以限制可调度/可转发的模型集合。
|
||||
if defaults := defaultModelMappingForPlatform(a.Platform); defaults != nil {
|
||||
return defaults
|
||||
}
|
||||
// Bedrock 默认映射由 forwardBedrock 统一处理(需配合 region prefix 调整)
|
||||
return nil
|
||||
}
|
||||
if len(rawMapping) == 0 {
|
||||
// Antigravity 平台使用默认映射
|
||||
if a.Platform == domain.PlatformAntigravity {
|
||||
return domain.DefaultAntigravityModelMapping
|
||||
if defaults := defaultModelMappingForPlatform(a.Platform); defaults != nil {
|
||||
return defaults
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -510,13 +521,23 @@ func (a *Account) resolveModelMapping(rawMapping map[string]any) map[string]stri
|
||||
return result
|
||||
}
|
||||
|
||||
// Antigravity 平台使用默认映射
|
||||
if a.Platform == domain.PlatformAntigravity {
|
||||
return domain.DefaultAntigravityModelMapping
|
||||
if defaults := defaultModelMappingForPlatform(a.Platform); defaults != nil {
|
||||
return defaults
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func defaultModelMappingForPlatform(platform string) map[string]string {
|
||||
switch platform {
|
||||
case domain.PlatformAntigravity:
|
||||
return domain.DefaultAntigravityModelMapping
|
||||
case domain.PlatformKiro:
|
||||
return domain.DefaultKiroModelMapping
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func mapPtr(m map[string]any) uintptr {
|
||||
if m == nil {
|
||||
return 0
|
||||
@@ -608,8 +629,8 @@ func resolveRequestedModelInMapping(mapping map[string]string, requestedModel st
|
||||
return matchWildcardMappingResult(mapping, requestedModel)
|
||||
}
|
||||
|
||||
// IsModelSupported 检查模型是否在 model_mapping 中(支持通配符)
|
||||
// 如果未配置 mapping,返回 true(允许所有模型)
|
||||
// IsModelSupported 检查模型是否在 model_mapping 中(支持通配符)。
|
||||
// 对带默认映射的平台(如 Antigravity/Kiro),未显式配置时也会先回退到默认映射。
|
||||
func (a *Account) IsModelSupported(requestedModel string) bool {
|
||||
mapping := a.GetModelMapping()
|
||||
if len(mapping) == 0 {
|
||||
@@ -622,8 +643,8 @@ func (a *Account) IsModelSupported(requestedModel string) bool {
|
||||
return normalized != requestedModel && mappingSupportsRequestedModel(mapping, normalized)
|
||||
}
|
||||
|
||||
// GetMappedModel 获取映射后的模型名(支持通配符,最长优先匹配)
|
||||
// 如果未配置 mapping,返回原始模型名
|
||||
// GetMappedModel 获取映射后的模型名(支持通配符,最长优先匹配)。
|
||||
// 对带默认映射的平台(如 Antigravity/Kiro),未显式配置时返回默认映射结果。
|
||||
func (a *Account) GetMappedModel(requestedModel string) string {
|
||||
mappedModel, _ := a.ResolveMappedModel(requestedModel)
|
||||
return mappedModel
|
||||
@@ -725,6 +746,9 @@ func (a *Account) GetBaseURL() string {
|
||||
}
|
||||
baseURL := a.GetCredential("base_url")
|
||||
if baseURL == "" {
|
||||
if a.Platform == PlatformKiro {
|
||||
return ""
|
||||
}
|
||||
return "https://api.anthropic.com"
|
||||
}
|
||||
if a.Platform == PlatformAntigravity {
|
||||
|
||||
Reference in New Issue
Block a user